From 839a183ea6edbbcde8798f4d28eefb959e098d5f Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 5 Apr 2022 10:37:35 -0700 Subject: [PATCH] Add note to doctor validator if script is running Rosetta (#101309) --- packages/flutter_tools/lib/src/base/os.dart | 8 ++- .../test/general.shard/base/os_test.dart | 64 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index a2f2415b83..84ec6768b6 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -372,10 +372,16 @@ class _MacOSUtils extends _PosixUtils { _processUtils.runSync(['sw_vers', '-productName']), _processUtils.runSync(['sw_vers', '-productVersion']), _processUtils.runSync(['sw_vers', '-buildVersion']), + _processUtils.runSync(['uname', '-m']), ]; if (results.every((RunResult result) => result.exitCode == 0)) { + String osName = getNameForHostPlatform(hostPlatform); + // If the script is running in Rosetta, "uname -m" will return x86_64. + if (hostPlatform == HostPlatform.darwin_arm && results[3].stdout.contains('x86_64')) { + osName = '$osName (Rosetta)'; + } _name = - '${results[0].stdout.trim()} ${results[1].stdout.trim()} ${results[2].stdout.trim()} ${getNameForHostPlatform(hostPlatform)}'; + '${results[0].stdout.trim()} ${results[1].stdout.trim()} ${results[2].stdout.trim()} $osName'; } _name ??= super.name; } diff --git a/packages/flutter_tools/test/general.shard/base/os_test.dart b/packages/flutter_tools/test/general.shard/base/os_test.dart index da1a147be9..b5c4da84ff 100644 --- a/packages/flutter_tools/test/general.shard/base/os_test.dart +++ b/packages/flutter_tools/test/general.shard/base/os_test.dart @@ -311,6 +311,13 @@ void main() { ], stdout: 'build', ), + const FakeCommand( + command: [ + 'uname', + '-m', + ], + stdout: 'arm64', + ), const FakeCommand( command: [ 'which', @@ -331,6 +338,56 @@ void main() { expect(utils.name, 'product version build darwin-arm'); }); + testWithoutContext('macOS ARM on Rosetta name', () async { + fakeProcessManager.addCommands([ + const FakeCommand( + command: [ + 'sw_vers', + '-productName', + ], + stdout: 'product', + ), + const FakeCommand( + command: [ + 'sw_vers', + '-productVersion', + ], + stdout: 'version', + ), + const FakeCommand( + command: [ + 'sw_vers', + '-buildVersion', + ], + stdout: 'build', + ), + const FakeCommand( + command: [ + 'uname', + '-m', + ], + stdout: 'x86_64', // Running on Rosetta + ), + const FakeCommand( + command: [ + 'which', + 'sysctl', + ], + ), + const FakeCommand( + command: [ + 'sysctl', + 'hw.optional.arm64', + ], + stdout: 'hw.optional.arm64: 1', + ), + ]); + + final OperatingSystemUtils utils = + createOSUtils(FakePlatform(operatingSystem: 'macos')); + expect(utils.name, 'product version build darwin-arm (Rosetta)'); + }); + testWithoutContext('macOS x86 name', () async { fakeProcessManager.addCommands([ const FakeCommand( @@ -354,6 +411,13 @@ void main() { ], stdout: 'build', ), + const FakeCommand( + command: [ + 'uname', + '-m', + ], + stdout: 'x86_64', + ), const FakeCommand( command: [ 'which',