Add usage event when iOS app is archived (#108643)
This commit is contained in:
@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/deferred_component.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
|
||||
@@ -23,21 +22,13 @@ void main() {
|
||||
|
||||
Environment createEnvironment() {
|
||||
final Map<String, String> defines = <String, String>{ kDeferredComponents: 'true' };
|
||||
final Environment result = Environment(
|
||||
outputDir: fileSystem.directory('/output'),
|
||||
buildDir: fileSystem.directory('/build'),
|
||||
projectDir: fileSystem.directory('/project'),
|
||||
final Environment result = Environment.test(
|
||||
fileSystem.directory('/project'),
|
||||
defines: defines,
|
||||
inputs: <String, String>{},
|
||||
cacheDir: fileSystem.directory('/cache'),
|
||||
flutterRootDir: fileSystem.directory('/flutter_root'),
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: FakeProcessManager.any(),
|
||||
platform: FakePlatform(),
|
||||
engineVersion: 'invalidEngineVersion',
|
||||
generateDartPluginRegistry: false,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ 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/ios.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
import '../../../src/common.dart';
|
||||
import '../../../src/context.dart';
|
||||
import '../../../src/fake_process_manager.dart';
|
||||
|
||||
final Platform macPlatform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{});
|
||||
|
||||
@@ -42,12 +44,14 @@ void main() {
|
||||
late FakeProcessManager processManager;
|
||||
late Artifacts artifacts;
|
||||
late BufferLogger logger;
|
||||
late TestUsage usage;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
processManager = FakeProcessManager.empty();
|
||||
logger = BufferLogger.test();
|
||||
artifacts = Artifacts.test();
|
||||
usage = TestUsage();
|
||||
environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
defines: <String, String>{
|
||||
@@ -59,6 +63,7 @@ void main() {
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
engineVersion: '2',
|
||||
usage: usage,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -216,9 +221,10 @@ void main() {
|
||||
expect(assetDirectory.childFile('io.flutter.shaders.json').readAsStringSync(), '{"data":{"A":"B"}}');
|
||||
});
|
||||
|
||||
testUsingContext('ReleaseIosApplicationBundle', () async {
|
||||
testUsingContext('ReleaseIosApplicationBundle build', () async {
|
||||
environment.defines[kBuildMode] = 'release';
|
||||
environment.defines[kCodesignIdentity] = 'ABC123';
|
||||
environment.defines[kXcodeAction] = 'build';
|
||||
|
||||
// Project info
|
||||
fileSystem.file('pubspec.yaml').writeAsStringSync('name: hello');
|
||||
@@ -247,7 +253,7 @@ void main() {
|
||||
);
|
||||
|
||||
await const ReleaseIosApplicationBundle().build(environment);
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
|
||||
expect(frameworkDirectoryBinary, exists);
|
||||
expect(frameworkDirectory.childFile('Info.plist'), exists);
|
||||
@@ -257,6 +263,53 @@ void main() {
|
||||
expect(assetDirectory.childFile('AssetManifest.json'), exists);
|
||||
expect(assetDirectory.childFile('vm_snapshot_data'), isNot(exists));
|
||||
expect(assetDirectory.childFile('isolate_snapshot_data'), isNot(exists));
|
||||
expect(usage.events, isEmpty);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
Platform: () => macPlatform,
|
||||
});
|
||||
|
||||
testUsingContext('ReleaseIosApplicationBundle sends archive success event', () async {
|
||||
environment.defines[kBuildMode] = 'release';
|
||||
environment.defines[kXcodeAction] = 'install';
|
||||
|
||||
fileSystem.file(fileSystem.path.join('ios', 'Flutter', 'AppFrameworkInfo.plist'))
|
||||
.createSync(recursive: true);
|
||||
|
||||
environment.buildDir
|
||||
.childDirectory('App.framework')
|
||||
.childFile('App')
|
||||
.createSync(recursive: true);
|
||||
|
||||
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
|
||||
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
|
||||
processManager.addCommand(
|
||||
FakeCommand(command: <String>[
|
||||
'codesign',
|
||||
'--force',
|
||||
'--sign',
|
||||
'-',
|
||||
frameworkDirectoryBinary.path,
|
||||
]),
|
||||
);
|
||||
|
||||
await const ReleaseIosApplicationBundle().build(environment);
|
||||
expect(usage.events, contains(const TestUsageEvent('assemble', 'ios-archive', label: 'success')));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
Platform: () => macPlatform,
|
||||
});
|
||||
|
||||
testUsingContext('ReleaseIosApplicationBundle 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 ReleaseIosApplicationBundle().build(environment),
|
||||
throwsA(const TypeMatcher<FileSystemException>()));
|
||||
expect(usage.events, contains(const TestUsageEvent('assemble', 'ios-archive', label: 'fail')));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
@@ -286,7 +339,7 @@ void main() {
|
||||
contains('release/profile builds are only supported for physical devices.'),
|
||||
)
|
||||
));
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
@@ -313,7 +366,7 @@ void main() {
|
||||
'description',
|
||||
contains('required define SdkRoot but it was not provided'),
|
||||
)));
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
@@ -414,7 +467,7 @@ void main() {
|
||||
await const DebugUnpackIOS().build(environment);
|
||||
|
||||
expect(logger.traceText, contains('Skipping lipo for non-fat file output/Flutter.framework/Flutter'));
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('fails when frameworks missing', () async {
|
||||
@@ -565,7 +618,7 @@ void main() {
|
||||
|
||||
expect(logger.traceText, contains('Skipping lipo for non-fat file output/Flutter.framework/Flutter'));
|
||||
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('thins fat framework', () async {
|
||||
@@ -613,7 +666,7 @@ void main() {
|
||||
]);
|
||||
|
||||
await const DebugUnpackIOS().build(environment);
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('fails when bitcode strip fails', () async {
|
||||
@@ -656,7 +709,7 @@ void main() {
|
||||
)),
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('strips framework', () async {
|
||||
@@ -685,7 +738,7 @@ void main() {
|
||||
]);
|
||||
await const DebugUnpackIOS().build(environment);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('fails when codesign fails', () async {
|
||||
@@ -730,7 +783,7 @@ void main() {
|
||||
)),
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('codesigns framework', () async {
|
||||
@@ -767,7 +820,7 @@ void main() {
|
||||
]);
|
||||
await const DebugUnpackIOS().build(environment);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, isFalse);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ void main() {
|
||||
final TestContext context = TestContext(
|
||||
<String>['build'],
|
||||
<String, String>{
|
||||
'ACTION': 'build',
|
||||
'BUILT_PRODUCTS_DIR': buildDir.path,
|
||||
'ENABLE_BITCODE': 'YES',
|
||||
'FLUTTER_ROOT': flutterRoot.path,
|
||||
@@ -51,6 +52,7 @@ void main() {
|
||||
'-dTrackWidgetCreation=',
|
||||
'-dDartObfuscation=',
|
||||
'-dEnableBitcode=',
|
||||
'-dAction=build',
|
||||
'--ExtraGenSnapshotOptions=',
|
||||
'--DartDefines=',
|
||||
'--ExtraFrontEndOptions=',
|
||||
@@ -104,6 +106,7 @@ void main() {
|
||||
'-dTrackWidgetCreation=',
|
||||
'-dDartObfuscation=',
|
||||
'-dEnableBitcode=',
|
||||
'-dAction=',
|
||||
'--ExtraGenSnapshotOptions=',
|
||||
'--DartDefines=',
|
||||
'--ExtraFrontEndOptions=',
|
||||
@@ -179,6 +182,7 @@ void main() {
|
||||
'-dTrackWidgetCreation=$trackWidgetCreation',
|
||||
'-dDartObfuscation=$dartObfuscation',
|
||||
'-dEnableBitcode=true',
|
||||
'-dAction=install',
|
||||
'--ExtraGenSnapshotOptions=$extraGenSnapshotOptions',
|
||||
'--DartDefines=$dartDefines',
|
||||
'--ExtraFrontEndOptions=$extraFrontEndOptions',
|
||||
|
||||
Reference in New Issue
Block a user