[flutter_tools] Fix analyze size on arm64 (#141317)

Fixes https://github.com/flutter/flutter/issues/140659
This commit is contained in:
Christopher Fujino
2024-01-16 16:15:28 -08:00
committed by GitHub
parent 0c66636a1f
commit 4cd0a3252d
3 changed files with 82 additions and 24 deletions

View File

@@ -585,7 +585,49 @@ STDERR STUFF
Platform: () => macosPlatform,
});
testUsingContext('Performs code size analysis and sends analytics', () async {
testUsingContext('code size analysis throws StateError if no code size snapshot generated by gen_snapshot', () async {
final BuildCommand command = BuildCommand(
artifacts: artifacts,
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: fileSystem,
logger: logger,
processUtils: processUtils,
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles();
fileSystem.file('build/macos/Build/Products/Release/Runner.app/App')
..createSync(recursive: true)
..writeAsBytesSync(List<int>.generate(10000, (int index) => 0));
expect(
() => createTestCommandRunner(command).run(
const <String>['build', 'macos', '--no-pub', '--analyze-size']
),
throwsA(
isA<StateError>().having(
(StateError err) => err.message,
'message',
'No code size snapshot file (snapshot.<ARCH>.json) found in build/flutter_size_01',
),
),
);
expect(testLogger.statusText, isEmpty);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
// we never generate code size snapshot here
setUpFakeXcodeBuildHandler('Release'),
]),
Platform: () => macosPlatform,
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: macosPlatform),
Usage: () => usage,
Analytics: () => fakeAnalytics,
});
testUsingContext('Performs code size analysis and sends analytics from arm64 host', () async {
final BuildCommand command = BuildCommand(
artifacts: artifacts,
androidSdk: FakeAndroidSdk(),
@@ -614,8 +656,10 @@ STDERR STUFF
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
// These are generated by gen_snapshot because flutter assemble passes
// extra flags specifying this output path
setUpFakeXcodeBuildHandler('Release', onRun: () {
fileSystem.file('build/flutter_size_01/snapshot.x86_64.json')
fileSystem.file('build/flutter_size_01/snapshot.arm64.json')
..createSync(recursive: true)
..writeAsStringSync('''
[
@@ -626,7 +670,7 @@ STDERR STUFF
"s": 2400
}
]''');
fileSystem.file('build/flutter_size_01/trace.x86_64.json')
fileSystem.file('build/flutter_size_01/trace.arm64.json')
..createSync(recursive: true)
..writeAsStringSync('{}');
}),