From 071f62d937e2526ca482dbd2a42eb4c83944be2a Mon Sep 17 00:00:00 2001 From: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Date: Fri, 2 May 2025 15:39:50 -0500 Subject: [PATCH] Add engine build mode to Flutter and FlutterMacOS framework Info.plist (#168024) This PR adds the build mode (debug, profile, release) to the Flutter.framework, FlutterMacOS.framework, and FlutterEmbedder.framework Info.plist. It also adds the engine version to the FlutterMacOS.framework Info.plist. The engine version is already in the Flutter.framework one. Fixes https://github.com/flutter/flutter/issues/168028. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- engine/src/flutter/build/copy_info_plist.py | 9 +++- .../shell/platform/darwin/ios/BUILD.gn | 2 + .../platform/darwin/ios/framework/Info.plist | 2 + .../shell/platform/darwin/macos/BUILD.gn | 11 +++- .../darwin/macos/framework/Info.plist | 4 ++ .../flutter/shell/platform/embedder/BUILD.gn | 2 + .../embedder/assets/EmbedderInfo.plist | 2 + .../ios_content_validation_test.dart | 52 +++++++++++++++++++ .../macos_content_validation_test.dart | 46 ++++++++++++++-- 9 files changed, 124 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/build/copy_info_plist.py b/engine/src/flutter/build/copy_info_plist.py index feedab7b9a7..de90f0dc23c 100644 --- a/engine/src/flutter/build/copy_info_plist.py +++ b/engine/src/flutter/build/copy_info_plist.py @@ -10,6 +10,7 @@ engine. usage: copy_info_plist.py --source --destination --minversion= + --buildmode= """ import argparse @@ -44,6 +45,7 @@ def main(): '--destination', help='Path to destination Info.plist', type=str, required=True ) parser.add_argument('--minversion', help='Minimum device OS version like "9.0"', type=str) + parser.add_argument('--buildmode', help='Build Mode like Debug, Profile, Release', type=str) args = parser.parse_args() @@ -51,7 +53,12 @@ def main(): engine_path = os.path.join(_src_root_dir, 'flutter') revision = git_revision.get_repository_version(engine_path) clang_version = get_clang_version() - text = text.format(revision=revision, clang_version=clang_version, min_version=args.minversion) + text = text.format( + revision=revision, + clang_version=clang_version, + min_version=args.minversion, + build_mode=args.buildmode + ) with open(args.destination, 'w') as outfile: outfile.write(text) diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index a633125c8c7..e0b1a1c3976 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -367,6 +367,8 @@ action("copy_framework_info_plist") { rebase_path(outputs[0]), "--minversion", ios_deployment_target, + "--buildmode", + flutter_runtime_mode, ] } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Info.plist b/engine/src/flutter/shell/platform/darwin/ios/framework/Info.plist index ceca7a90b81..0edcdde7cab 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Info.plist +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Info.plist @@ -24,6 +24,8 @@ {min_version} FlutterEngine {revision} + BuildMode + {build_mode} ClangVersion {clang_version} diff --git a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn index 3722db1d62f..5e329f95c1a 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn @@ -237,10 +237,19 @@ copy("copy_dylib") { deps = [ ":flutter_framework_dylib" ] } -copy("copy_framework_info_plist") { +action("copy_framework_info_plist") { + script = "//flutter/build/copy_info_plist.py" visibility = [ ":*" ] sources = [ "framework/Info.plist" ] outputs = [ "$_flutter_framework_dir/Versions/A/Resources/Info.plist" ] + args = [ + "--source", + rebase_path(sources[0]), + "--destination", + rebase_path(outputs[0]), + "--buildmode", + flutter_runtime_mode, + ] } copy("copy_framework_module_map") { diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Info.plist b/engine/src/flutter/shell/platform/darwin/macos/framework/Info.plist index 044a5e31b7e..48b715c6c53 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Info.plist +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Info.plist @@ -20,5 +20,9 @@ 1.0 NSPrincipalClass + FlutterEngine + {revision} + BuildMode + {build_mode} diff --git a/engine/src/flutter/shell/platform/embedder/BUILD.gn b/engine/src/flutter/shell/platform/embedder/BUILD.gn index 5a430ce408f..789b4d9a826 100644 --- a/engine/src/flutter/shell/platform/embedder/BUILD.gn +++ b/engine/src/flutter/shell/platform/embedder/BUILD.gn @@ -497,6 +497,8 @@ if (is_mac && !embedder_for_target) { rebase_path(sources[0]), "--destination", rebase_path(outputs[0]), + "--buildmode", + flutter_runtime_mode, ] } diff --git a/engine/src/flutter/shell/platform/embedder/assets/EmbedderInfo.plist b/engine/src/flutter/shell/platform/embedder/assets/EmbedderInfo.plist index 2c37b435d36..0a205a5e1fe 100644 --- a/engine/src/flutter/shell/platform/embedder/assets/EmbedderInfo.plist +++ b/engine/src/flutter/shell/platform/embedder/assets/EmbedderInfo.plist @@ -26,6 +26,8 @@ Copyright 2013 The Flutter Authors. All rights reserved. FlutterEngine {revision} + BuildMode + {build_mode} ClangVersion {clang_version} diff --git a/packages/flutter_tools/test/host_cross_arch.shard/ios_content_validation_test.dart b/packages/flutter_tools/test/host_cross_arch.shard/ios_content_validation_test.dart index ce3d2f4d155..e09cde46859 100644 --- a/packages/flutter_tools/test/host_cross_arch.shard/ios_content_validation_test.dart +++ b/packages/flutter_tools/test/host_cross_arch.shard/ios_content_validation_test.dart @@ -298,6 +298,58 @@ void main() { }); } + for (final BuildMode buildMode in [ + BuildMode.debug, + BuildMode.profile, + BuildMode.release, + ]) { + for (final String arch in ['ios-arm64', 'ios-arm64_x86_64-simulator']) { + test('verify ${buildMode.cliName} $arch Flutter.framework Info.plist', () { + final String artifactDir; + switch (buildMode) { + case BuildMode.debug: + case BuildMode.jitRelease: + artifactDir = 'ios'; + case BuildMode.profile: + artifactDir = 'ios-profile'; + case BuildMode.release: + artifactDir = 'ios-release'; + } + final Directory xcframeworkArtifact = fileSystem.directory( + fileSystem.path.join( + flutterRoot, + 'bin', + 'cache', + 'artifacts', + 'engine', + artifactDir, + 'Flutter.xcframework', + ), + ); + // Verify Info.plist has correct engine version and build mode + final File engineStamp = fileSystem.file( + fileSystem.path.join(flutterRoot, 'bin', 'cache', 'engine.stamp'), + ); + expect(engineStamp, exists); + final String engineVersion = engineStamp.readAsStringSync().trim(); + + final File infoPlist = fileSystem.file( + fileSystem.path.joinAll([ + xcframeworkArtifact.path, + 'ios-arm64', + 'Flutter.framework', + 'Info.plist', + ]), + ); + expect(infoPlist, exists); + + final String infoPlistContents = infoPlist.readAsStringSync(); + expect(infoPlistContents, contains(engineVersion)); + expect(infoPlistContents, contains(buildMode.cliName)); + }); + } + } + testWithoutContext('builds all plugin architectures for simulator', () { final ProcessResult buildSimulator = processManager.runSync([ flutterBin, diff --git a/packages/flutter_tools/test/host_cross_arch.shard/macos_content_validation_test.dart b/packages/flutter_tools/test/host_cross_arch.shard/macos_content_validation_test.dart index da967be5c19..e303cdca323 100644 --- a/packages/flutter_tools/test/host_cross_arch.shard/macos_content_validation_test.dart +++ b/packages/flutter_tools/test/host_cross_arch.shard/macos_content_validation_test.dart @@ -5,6 +5,7 @@ import 'package:file_testing/file_testing.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; +import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/features.dart'; import '../integration.shard/test_utils.dart'; @@ -31,11 +32,24 @@ void main() { } }); - for (final String buildMode in ['Debug', 'Release']) { - test('verify $buildMode FlutterMacOS.xcframework artifact', () { + for (final BuildMode buildMode in [ + BuildMode.debug, + BuildMode.profile, + BuildMode.release, + ]) { + test('verify ${buildMode.cliName} FlutterMacOS.xcframework artifact', () { final String flutterRoot = getFlutterRoot(); - final String artifactDir = (buildMode == 'Debug') ? 'darwin-x64' : 'darwin-x64-release'; + final String artifactDir; + switch (buildMode) { + case BuildMode.debug: + case BuildMode.jitRelease: + artifactDir = 'darwin-x64'; + case BuildMode.profile: + artifactDir = 'darwin-x64-profile'; + case BuildMode.release: + artifactDir = 'darwin-x64-release'; + } final Directory xcframeworkArtifact = fileSystem.directory( fileSystem.path.join( flutterRoot, @@ -72,7 +86,31 @@ void main() { final String artifactStat = frameworkArtifact.statSync().mode.toRadixString(8); expect(artifactStat, '40755'); - if (buildMode == 'Release') { + // Verify Info.plist has correct engine version and build mode + final File engineStamp = fileSystem.file( + fileSystem.path.join(flutterRoot, 'bin', 'cache', 'engine.stamp'), + ); + expect(engineStamp, exists); + final String engineVersion = engineStamp.readAsStringSync().trim(); + + final File infoPlist = fileSystem.file( + fileSystem.path.joinAll([ + xcframeworkArtifact.path, + 'macos-arm64_x86_64', + 'FlutterMacOS.framework', + 'Versions', + 'A', + 'Resources', + 'Info.plist', + ]), + ); + expect(infoPlist, exists); + + final String infoPlistContents = infoPlist.readAsStringSync(); + expect(infoPlistContents, contains(engineVersion)); + expect(infoPlistContents, contains(buildMode.cliName)); + + if (buildMode == BuildMode.release) { final Directory dsymArtifact = fileSystem.directory( fileSystem.path.joinAll([ xcframeworkArtifact.path,