Unverified Commit 6ca4db4b authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Add usage event when macOS app is archived (#108651)

parent 40940de6
......@@ -77,6 +77,7 @@ BuildApp() {
"-dDartObfuscation=${DART_OBFUSCATION}"
"-dSplitDebugInfo=${SPLIT_DEBUG_INFO}"
"-dTrackWidgetCreation=${TRACK_WIDGET_CREATION}"
"-dAction=${ACTION}"
"--DartDefines=${DART_DEFINES}"
"--ExtraGenSnapshotOptions=${EXTRA_GEN_SNAPSHOT_OPTIONS}"
"--ExtraFrontEndOptions=${EXTRA_FRONT_END_OPTIONS}"
......
......@@ -9,6 +9,7 @@ import '../../base/io.dart';
import '../../base/process.dart';
import '../../build_info.dart';
import '../../globals.dart' as globals show xcode;
import '../../reporting/reporting.dart';
import '../build_system.dart';
import '../depfile.dart';
import '../exceptions.dart';
......@@ -544,4 +545,27 @@ class ReleaseMacOSBundleFlutterAssets extends MacOSBundleFlutterAssets {
CompileMacOSFramework(),
ReleaseUnpackMacOS(),
];
@override
Future<void> build(Environment environment) async {
bool buildSuccess = true;
try {
await super.build(environment);
} catch (_) { // ignore: avoid_catches_without_on_clauses
buildSuccess = false;
rethrow;
} finally {
// Send a usage event when the app is being archived from Xcode.
if (environment.defines[kXcodeAction]?.toLowerCase() == 'install') {
environment.logger.printTrace('Sending archive event if usage enabled.');
UsageEvent(
'assemble',
'macos-archive',
label: buildSuccess ? 'success' : 'fail',
flutterUsage: environment.usage,
).send();
}
}
}
}
......@@ -11,6 +11,7 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/macos.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import '../../../src/common.dart';
import '../../../src/context.dart';
......@@ -27,12 +28,14 @@ void main() {
late FakeCommand lipoInfoNonFatCommand;
late FakeCommand lipoInfoFatCommand;
late FakeCommand lipoVerifyX86_64Command;
late TestUsage usage;
setUp(() {
processManager = FakeProcessManager.empty();
artifacts = Artifacts.test();
fileSystem = MemoryFileSystem.test();
logger = BufferLogger.test();
usage = TestUsage();
environment = Environment.test(
fileSystem.currentDirectory,
defines: <String, String>{
......@@ -45,7 +48,8 @@ void main() {
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
engineVersion: '2'
engineVersion: '2',
usage: usage,
);
binary = environment.outputDir
......@@ -314,6 +318,37 @@ void main() {
ProcessManager: () => processManager,
});
testUsingContext('ReleaseMacOSBundleFlutterAssets sends archive success event', () async {
environment.defines[kBuildMode] = 'release';
environment.defines[kXcodeAction] = 'install';
fileSystem.file('bin/cache/artifacts/engine/darwin-x64/vm_isolate_snapshot.bin')
.createSync(recursive: true);
fileSystem.file('bin/cache/artifacts/engine/darwin-x64/isolate_snapshot.bin')
.createSync(recursive: true);
fileSystem.file(fileSystem.path.join(environment.buildDir.path, 'App.framework', 'App'))
.createSync(recursive: true);
await const ReleaseMacOSBundleFlutterAssets().build(environment);
expect(usage.events, contains(const TestUsageEvent('assemble', 'macos-archive', label: 'success')));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('ReleaseMacOSBundleFlutterAssets sends archive fail event', () async {
environment.defines[kBuildMode] = 'release';
environment.defines[kXcodeAction] = 'install';
// Throws because the project files are not set up.
await expectLater(() => const ReleaseMacOSBundleFlutterAssets().build(environment),
throwsA(const TypeMatcher<FileSystemException>()));
expect(usage.events, contains(const TestUsageEvent('assemble', 'macos-archive', label: 'fail')));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('DebugMacOSFramework creates expected binary with arm64 only arch', () async {
environment.defines[kDarwinArchs] = 'arm64';
processManager.addCommand(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment