Skip to content

Commit 355fd23

Browse files
[flutter_tools] add test for dart binary arch (flutter#101604)
1 parent 3437137 commit 355fd23

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/flutter_tools/test/integration.shard/bash_entrypoint_test.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'dart:convert';
77

88
import 'package:file/file.dart';
99
import 'package:flutter_tools/src/base/io.dart';
10+
import 'package:flutter_tools/src/base/logger.dart';
11+
import 'package:flutter_tools/src/base/os.dart';
1012

1113
import '../src/common.dart';
1214
import 'test_utils.dart';
@@ -48,6 +50,40 @@ Future<void> main() async {
4850
expect(stdout, contains('Successfully received SIGTERM!'));
4951
},
5052
skip: platform.isWindows); // [intended] Windows does not use the bash entrypoint
53+
54+
test('verify the dart binary arch matches the host arch', () async {
55+
final HostPlatform dartArch = _identifyBinaryArch(dartBinary.path);
56+
final OperatingSystemUtils os = OperatingSystemUtils(
57+
processManager: processManager,
58+
fileSystem: fileSystem,
59+
platform: platform,
60+
logger: BufferLogger.test(),
61+
);
62+
expect(dartArch, os.hostPlatform);
63+
}, skip: !platform.isMacOS); // [intended] Calls macOS-specific commands
64+
}
65+
66+
// Call `file` on the path and parse the output.
67+
// This is macOS-specific.
68+
HostPlatform _identifyBinaryArch(String path) {
69+
// Expect STDOUT like:
70+
// bin/cache/dart-sdk/bin/dart: Mach-O 64-bit executable x86_64
71+
final RegExp pattern = RegExp(r'Mach-O 64-bit executable (\w+)');
72+
final ProcessResult result = processManager.runSync(
73+
<String>['file', dartBinary.path],
74+
);
75+
final RegExpMatch? match = pattern.firstMatch(result.stdout as String);
76+
if (match == null) {
77+
fail('Unrecognized STDOUT from `file`: "${result.stdout}"');
78+
}
79+
switch (match.group(1)) {
80+
case 'x86_64':
81+
return HostPlatform.darwin_x64;
82+
case 'arm64':
83+
return HostPlatform.darwin_arm;
84+
default:
85+
fail('Unexpected architecture ${match.group(1)}');
86+
}
5187
}
5288

5389
// A test Dart app that will run until it receives SIGTERM
@@ -69,3 +105,14 @@ File get dartBash {
69105
.childFile('dart')
70106
.absolute;
71107
}
108+
109+
// The executable bash entrypoint for the Dart binary.
110+
File get dartBinary {
111+
return flutterRoot
112+
.childDirectory('bin')
113+
.childDirectory('cache')
114+
.childDirectory('dart-sdk')
115+
.childDirectory('bin')
116+
.childFile('dart')
117+
.absolute;
118+
}

0 commit comments

Comments
 (0)