Skip to content

Commit a7a4d0b

Browse files
Write macOS universal gen_snapshot binaries to a separate output directory (#164667)
Also use the name "gen_snapshot" when building for Android targets instead of appending a target architecture to the filename. This allows flutter_tools to find the universal gen_snapshot binary when using a locally built engine. Previously the tools would search directories like "clang_x64" and find build outputs that may not match the host architecture. Moving the universal gen_snapshot binary to a separate directory avoids conflicts with Dart's gen_snapshot binary, which is placed at the root of the target output directory.
1 parent f0992e0 commit a7a4d0b

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

engine/src/flutter/ci/builders/mac_host_engine.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,9 @@
11411141
"--dst",
11421142
"out/debug/snapshot",
11431143
"--arm64-path",
1144-
"out/ci/mac_debug_gen_snapshot_arm64/gen_snapshot_arm64",
1144+
"out/ci/mac_debug_gen_snapshot_arm64/universal/gen_snapshot_arm64",
11451145
"--x64-path",
1146-
"out/ci/host_debug_gen_snapshot/gen_snapshot_x64",
1146+
"out/ci/host_debug_gen_snapshot/universal/gen_snapshot_x64",
11471147
"--zip"
11481148
],
11491149
"script": "flutter/sky/tools/create_macos_gen_snapshots.py"
@@ -1154,9 +1154,9 @@
11541154
"--dst",
11551155
"out/profile/snapshot",
11561156
"--arm64-path",
1157-
"out/ci/mac_profile_gen_snapshot_arm64/gen_snapshot_arm64",
1157+
"out/ci/mac_profile_gen_snapshot_arm64/universal/gen_snapshot_arm64",
11581158
"--x64-path",
1159-
"out/ci/host_profile_gen_snapshot/gen_snapshot_x64",
1159+
"out/ci/host_profile_gen_snapshot/universal/gen_snapshot_x64",
11601160
"--zip"
11611161
],
11621162
"script": "flutter/sky/tools/create_macos_gen_snapshots.py"
@@ -1167,9 +1167,9 @@
11671167
"--dst",
11681168
"out/release/snapshot",
11691169
"--arm64-path",
1170-
"out/ci/mac_release_gen_snapshot_arm64/gen_snapshot_arm64",
1170+
"out/ci/mac_release_gen_snapshot_arm64/universal/gen_snapshot_arm64",
11711171
"--x64-path",
1172-
"out/ci/host_release_gen_snapshot/gen_snapshot_x64",
1172+
"out/ci/host_release_gen_snapshot/universal/gen_snapshot_x64",
11731173
"--zip"
11741174
],
11751175
"script": "flutter/sky/tools/create_macos_gen_snapshots.py"

engine/src/flutter/lib/snapshot/BUILD.gn

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,19 @@ if (host_os == "mac" &&
228228
host_arch = "x64"
229229
}
230230

231+
if (target_os == "android") {
232+
# Each Android engine build targets a specific architecture and does not
233+
# need to add the target architecture to the universal binary filename.
234+
universal_binary_name = "gen_snapshot"
235+
} else {
236+
universal_binary_name = "gen_snapshot${gen_snapshot_suffix}"
237+
}
238+
universal_output_path = "${root_out_dir}/universal/${universal_binary_name}"
239+
231240
# Create a universal binary from the two architecture-specific gen_snapshots.
232241
action("create_macos_gen_snapshots") {
233242
script = "//flutter/sky/tools/create_macos_binary.py"
234-
outputs = [ "${root_out_dir}/gen_snapshot${gen_snapshot_suffix}" ]
243+
outputs = [ universal_output_path ]
235244
args = [
236245
"--in-arm64",
237246
rebase_path(
@@ -240,7 +249,7 @@ if (host_os == "mac" &&
240249
rebase_path(
241250
"${root_out_dir}/artifacts_x64/gen_snapshot${gen_snapshot_suffix}"),
242251
"--out",
243-
rebase_path("${root_out_dir}/gen_snapshot${gen_snapshot_suffix}"),
252+
rebase_path(universal_output_path),
244253
]
245254
deps = [
246255
":create_macos_gen_snapshot_arm64${gen_snapshot_suffix}",

engine/src/flutter/shell/platform/android/BUILD.gn

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ if (target_cpu != "x86") {
693693
gen_snapshot_dest = "gen_snapshot"
694694

695695
if (host_os == "mac") {
696-
gen_snapshot_src =
697-
rebase_path("$root_out_dir/gen_snapshot${gen_snapshot_suffix}")
696+
gen_snapshot_src = rebase_path("$root_out_dir/universal/gen_snapshot")
698697
} else if (host_os == "win") {
699698
gen_snapshot_src = rebase_path("$root_out_dir/gen_snapshot.exe")
700699
gen_snapshot_dest = "gen_snapshot.exe"

engine/src/flutter/sky/tools/create_ios_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def main():
8484

8585
# Copy gen_snapshot binary to destination directory.
8686
if arm64_out_dir:
87-
gen_snapshot = os.path.join(arm64_out_dir, 'gen_snapshot_arm64')
87+
gen_snapshot = os.path.join(arm64_out_dir, 'universal', 'gen_snapshot_arm64')
8888
sky_utils.copy_binary(gen_snapshot, os.path.join(dst, 'gen_snapshot_arm64'))
8989
if x64_out_dir:
90-
gen_snapshot = os.path.join(x64_out_dir, 'gen_snapshot_x64')
90+
gen_snapshot = os.path.join(x64_out_dir, 'universal', 'gen_snapshot_x64')
9191
sky_utils.copy_binary(gen_snapshot, os.path.join(dst, 'gen_snapshot_x64'))
9292

9393
zip_archive(dst, args)

packages/flutter_tools/lib/src/artifacts.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ class CachedLocalEngineArtifacts implements Artifacts {
13661366
String _genSnapshotPath(Artifact artifact) {
13671367
const List<String> clangDirs = <String>[
13681368
'.',
1369+
'universal',
13691370
'clang_x64',
13701371
'clang_x86',
13711372
'clang_i386',

packages/flutter_tools/test/general.shard/artifacts_test.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ void main() {
288288
late Cache cache;
289289
late FileSystem fileSystem;
290290
late Platform platform;
291+
late FakeProcessManager processManager;
291292

292293
setUp(() {
293294
fileSystem = MemoryFileSystem.test();
@@ -301,6 +302,7 @@ void main() {
301302
osUtils: FakeOperatingSystemUtils(),
302303
artifacts: <ArtifactSet>[],
303304
);
305+
processManager = FakeProcessManager.any();
304306
artifacts = CachedLocalWebSdkArtifacts(
305307
parent: CachedLocalEngineArtifacts(
306308
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'host_debug_unopt'),
@@ -312,7 +314,7 @@ void main() {
312314
cache: cache,
313315
fileSystem: fileSystem,
314316
platform: platform,
315-
processManager: FakeProcessManager.any(),
317+
processManager: processManager,
316318
operatingSystemUtils: FakeOperatingSystemUtils(),
317319
),
318320
webSdkPath: fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'wasm_release'),
@@ -511,6 +513,12 @@ void main() {
511513
artifacts.getHostArtifact(HostArtifact.libtessellator).path,
512514
fileSystem.path.join('/out', 'host_debug_unopt', 'libtessellator.so'),
513515
);
516+
517+
processManager.excludedExecutables.add('/out/android_debug_unopt/./gen_snapshot');
518+
expect(
519+
artifacts.getArtifactPath(Artifact.genSnapshot),
520+
fileSystem.path.join('/out', 'android_debug_unopt', 'universal', 'gen_snapshot'),
521+
);
514522
});
515523

516524
testWithoutContext(

0 commit comments

Comments
 (0)