Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 839a183

Browse files
authored
Add note to doctor validator if script is running Rosetta (#101309)
1 parent d6cc67d commit 839a183

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

packages/flutter_tools/lib/src/base/os.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,16 @@ class _MacOSUtils extends _PosixUtils {
372372
_processUtils.runSync(<String>['sw_vers', '-productName']),
373373
_processUtils.runSync(<String>['sw_vers', '-productVersion']),
374374
_processUtils.runSync(<String>['sw_vers', '-buildVersion']),
375+
_processUtils.runSync(<String>['uname', '-m']),
375376
];
376377
if (results.every((RunResult result) => result.exitCode == 0)) {
378+
String osName = getNameForHostPlatform(hostPlatform);
379+
// If the script is running in Rosetta, "uname -m" will return x86_64.
380+
if (hostPlatform == HostPlatform.darwin_arm && results[3].stdout.contains('x86_64')) {
381+
osName = '$osName (Rosetta)';
382+
}
377383
_name =
378-
'${results[0].stdout.trim()} ${results[1].stdout.trim()} ${results[2].stdout.trim()} ${getNameForHostPlatform(hostPlatform)}';
384+
'${results[0].stdout.trim()} ${results[1].stdout.trim()} ${results[2].stdout.trim()} $osName';
379385
}
380386
_name ??= super.name;
381387
}

packages/flutter_tools/test/general.shard/base/os_test.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ void main() {
311311
],
312312
stdout: 'build',
313313
),
314+
const FakeCommand(
315+
command: <String>[
316+
'uname',
317+
'-m',
318+
],
319+
stdout: 'arm64',
320+
),
314321
const FakeCommand(
315322
command: <String>[
316323
'which',
@@ -331,6 +338,56 @@ void main() {
331338
expect(utils.name, 'product version build darwin-arm');
332339
});
333340

341+
testWithoutContext('macOS ARM on Rosetta name', () async {
342+
fakeProcessManager.addCommands(<FakeCommand>[
343+
const FakeCommand(
344+
command: <String>[
345+
'sw_vers',
346+
'-productName',
347+
],
348+
stdout: 'product',
349+
),
350+
const FakeCommand(
351+
command: <String>[
352+
'sw_vers',
353+
'-productVersion',
354+
],
355+
stdout: 'version',
356+
),
357+
const FakeCommand(
358+
command: <String>[
359+
'sw_vers',
360+
'-buildVersion',
361+
],
362+
stdout: 'build',
363+
),
364+
const FakeCommand(
365+
command: <String>[
366+
'uname',
367+
'-m',
368+
],
369+
stdout: 'x86_64', // Running on Rosetta
370+
),
371+
const FakeCommand(
372+
command: <String>[
373+
'which',
374+
'sysctl',
375+
],
376+
),
377+
const FakeCommand(
378+
command: <String>[
379+
'sysctl',
380+
'hw.optional.arm64',
381+
],
382+
stdout: 'hw.optional.arm64: 1',
383+
),
384+
]);
385+
386+
final OperatingSystemUtils utils =
387+
createOSUtils(FakePlatform(operatingSystem: 'macos'));
388+
expect(utils.name, 'product version build darwin-arm (Rosetta)');
389+
});
390+
334391
testWithoutContext('macOS x86 name', () async {
335392
fakeProcessManager.addCommands(<FakeCommand>[
336393
const FakeCommand(
@@ -354,6 +411,13 @@ void main() {
354411
],
355412
stdout: 'build',
356413
),
414+
const FakeCommand(
415+
command: <String>[
416+
'uname',
417+
'-m',
418+
],
419+
stdout: 'x86_64',
420+
),
357421
const FakeCommand(
358422
command: <String>[
359423
'which',

0 commit comments

Comments
 (0)