diff --git a/packages/flutter_tools/test/integration.shard/bash_entrypoint_test.dart b/packages/flutter_tools/test/integration.shard/bash_entrypoint_test.dart index 7377889c24..2b69951c00 100644 --- a/packages/flutter_tools/test/integration.shard/bash_entrypoint_test.dart +++ b/packages/flutter_tools/test/integration.shard/bash_entrypoint_test.dart @@ -7,6 +7,8 @@ import 'dart:convert'; import 'package:file/file.dart'; import 'package:flutter_tools/src/base/io.dart'; +import 'package:flutter_tools/src/base/logger.dart'; +import 'package:flutter_tools/src/base/os.dart'; import '../src/common.dart'; import 'test_utils.dart'; @@ -48,6 +50,40 @@ Future main() async { expect(stdout, contains('Successfully received SIGTERM!')); }, skip: platform.isWindows); // [intended] Windows does not use the bash entrypoint + + test('verify the dart binary arch matches the host arch', () async { + final HostPlatform dartArch = _identifyBinaryArch(dartBinary.path); + final OperatingSystemUtils os = OperatingSystemUtils( + processManager: processManager, + fileSystem: fileSystem, + platform: platform, + logger: BufferLogger.test(), + ); + expect(dartArch, os.hostPlatform); + }, skip: !platform.isMacOS); // [intended] Calls macOS-specific commands +} + +// Call `file` on the path and parse the output. +// This is macOS-specific. +HostPlatform _identifyBinaryArch(String path) { + // Expect STDOUT like: + // bin/cache/dart-sdk/bin/dart: Mach-O 64-bit executable x86_64 + final RegExp pattern = RegExp(r'Mach-O 64-bit executable (\w+)'); + final ProcessResult result = processManager.runSync( + ['file', dartBinary.path], + ); + final RegExpMatch? match = pattern.firstMatch(result.stdout as String); + if (match == null) { + fail('Unrecognized STDOUT from `file`: "${result.stdout}"'); + } + switch (match.group(1)) { + case 'x86_64': + return HostPlatform.darwin_x64; + case 'arm64': + return HostPlatform.darwin_arm; + default: + fail('Unexpected architecture ${match.group(1)}'); + } } // A test Dart app that will run until it receives SIGTERM @@ -69,3 +105,14 @@ File get dartBash { .childFile('dart') .absolute; } + +// The executable bash entrypoint for the Dart binary. +File get dartBinary { + return flutterRoot + .childDirectory('bin') + .childDirectory('cache') + .childDirectory('dart-sdk') + .childDirectory('bin') + .childFile('dart') + .absolute; +}