diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index fecf5d310f77..674bf4eb9355 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -64,10 +64,12 @@ class GenSnapshot { String snapshotterPath = getSnapshotterPath(snapshotType); - // iOS has a separate gen_snapshot for armv7 and arm64 in the same, - // directory. So we need to select the right one. - if (snapshotType.platform == TargetPlatform.ios) { - snapshotterPath += '_${getNameForDarwinArch(darwinArch!)}'; + // iOS and macOS have separate gen_snapshot binaries for each target + // architecture (iOS: armv7, arm64; macOS: x86_64, arm64). Select the right + // one for the target architecture in question. + if (snapshotType.platform == TargetPlatform.ios || + snapshotType.platform == TargetPlatform.darwin) { + snapshotterPath += '_${getDartNameForDarwinArch(darwinArch!)}'; } return _processUtils.stream( diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index 119e3929876a..026078467095 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -570,6 +570,31 @@ List defaultIOSArchsForEnvironment( ]; } +// Returns the Dart SDK's name for the specified target architecture. +// +// When building for Darwin platforms, the tool invokes architecture-specific +// variants of `gen_snapshot`, one for each target architecture. The output +// instructions are then built into architecture-specific binaries, which are +// merged into a universal binary using the `lipo` tool. +String getDartNameForDarwinArch(DarwinArch arch) { + switch (arch) { + case DarwinArch.armv7: + return 'armv7'; + case DarwinArch.arm64: + return 'arm64'; + case DarwinArch.x86_64: + return 'x64'; + } +} + +// Returns Apple's name for the specified target architecture. +// +// When invoking Apple tools such as `xcodebuild` or `lipo`, the tool often +// passes one or more target architectures as paramters. The names returned by +// this function reflect Apple's name for the specified architecture. +// +// For consistency with developer expectations, Flutter outputs also use these +// architecture names in its build products for Darwin target platforms. String getNameForDarwinArch(DarwinArch arch) { switch (arch) { case DarwinArch.armv7: diff --git a/packages/flutter_tools/test/general.shard/build_info_test.dart b/packages/flutter_tools/test/general.shard/build_info_test.dart index ebfe7fbaf30b..96f3976a4291 100644 --- a/packages/flutter_tools/test/general.shard/build_info_test.dart +++ b/packages/flutter_tools/test/general.shard/build_info_test.dart @@ -80,6 +80,18 @@ void main() { }); }); + testWithoutContext('getDartNameForDarwinArch returns name used in Dart SDK', () { + expect(getDartNameForDarwinArch(DarwinArch.armv7), 'armv7'); + expect(getDartNameForDarwinArch(DarwinArch.arm64), 'arm64'); + expect(getDartNameForDarwinArch(DarwinArch.x86_64), 'x64'); + }); + + testWithoutContext('getNameForDarwinArch returns Apple names', () { + expect(getNameForDarwinArch(DarwinArch.armv7), 'armv7'); + expect(getNameForDarwinArch(DarwinArch.arm64), 'arm64'); + expect(getNameForDarwinArch(DarwinArch.x86_64), 'x86_64'); + }); + testWithoutContext('getNameForTargetPlatform on Darwin arches', () { expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.arm64), 'ios-arm64'); expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.armv7), 'ios-armv7'); diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart index 6dd648007262..ff8463760a4c 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart @@ -384,7 +384,7 @@ void main() { processManager.addCommands([ FakeCommand(command: [ - 'Artifact.genSnapshot.TargetPlatform.darwin.release', + 'Artifact.genSnapshot.TargetPlatform.darwin.release_arm64', '--deterministic', '--snapshot_kind=app-aot-assembly', '--assembly=${environment.buildDir.childFile('arm64/snapshot_assembly.S').path}', @@ -392,7 +392,7 @@ void main() { environment.buildDir.childFile('app.dill').path ]), FakeCommand(command: [ - 'Artifact.genSnapshot.TargetPlatform.darwin.release', + 'Artifact.genSnapshot.TargetPlatform.darwin.release_x64', '--deterministic', '--snapshot_kind=app-aot-assembly', '--assembly=${environment.buildDir.childFile('x86_64/snapshot_assembly.S').path}',