[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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 82 additions and 24 deletions

View file

@ -455,22 +455,22 @@ abstract class MacOSBundleFlutterAssets extends Target {
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>App</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>App</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>App</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>App</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>

View file

@ -181,11 +181,25 @@ Future<void> _writeCodeSizeAnalysis(BuildInfo buildInfo, SizeAnalyzer? sizeAnaly
if (buildInfo.codeSizeDirectory == null || sizeAnalyzer == null) {
return;
}
final String arch = DarwinArch.x86_64.name;
final File aotSnapshot = globals.fs.directory(buildInfo.codeSizeDirectory)
.childFile('snapshot.$arch.json');
final File precompilerTrace = globals.fs.directory(buildInfo.codeSizeDirectory)
.childFile('trace.$arch.json');
final File? aotSnapshot = DarwinArch.values.map<File?>((DarwinArch arch) {
return globals.fs.directory(buildInfo.codeSizeDirectory).childFile('snapshot.${arch.name}.json');
// Pick the first if there are multiple for simplicity
}).firstWhere(
(File? file) => file!.existsSync(),
orElse: () => null,
);
if (aotSnapshot == null) {
throw StateError('No code size snapshot file (snapshot.<ARCH>.json) found in ${buildInfo.codeSizeDirectory}');
}
final File? precompilerTrace = DarwinArch.values.map<File?>((DarwinArch arch) {
return globals.fs.directory(buildInfo.codeSizeDirectory).childFile('trace.${arch.name}.json');
}).firstWhere(
(File? file) => file!.existsSync(),
orElse: () => null,
);
if (precompilerTrace == null) {
throw StateError('No precompiler trace file (trace.<ARCH>.json) found in ${buildInfo.codeSizeDirectory}');
}
// This analysis is only supported for release builds.
// Attempt to guess the correct .app by picking the first one.

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('{}');
}),