Suggest Rosetta when x64 binary cannot be run (#114558)
* Suggest Rosetta when x64 binary cannot be run * validator * Adjust error message
This commit is contained in:
@@ -581,8 +581,10 @@ Future<T> _run<T>(Future<T> Function() op, {
|
||||
} on io.ProcessException catch (e) {
|
||||
if (platform.isWindows) {
|
||||
_handleWindowsException(e, failureMessage, e.errorCode);
|
||||
} else if (platform.isLinux || platform.isMacOS) {
|
||||
} else if (platform.isLinux) {
|
||||
_handlePosixException(e, failureMessage, e.errorCode, posixPermissionSuggestion);
|
||||
} if (platform.isMacOS) {
|
||||
_handleMacOSException(e, failureMessage, e.errorCode, posixPermissionSuggestion);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
@@ -611,8 +613,10 @@ T _runSync<T>(T Function() op, {
|
||||
} on io.ProcessException catch (e) {
|
||||
if (platform.isWindows) {
|
||||
_handleWindowsException(e, failureMessage, e.errorCode);
|
||||
} else if (platform.isLinux || platform.isMacOS) {
|
||||
} else if (platform.isLinux) {
|
||||
_handlePosixException(e, failureMessage, e.errorCode, posixPermissionSuggestion);
|
||||
} if (platform.isMacOS) {
|
||||
_handleMacOSException(e, failureMessage, e.errorCode, posixPermissionSuggestion);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
@@ -762,6 +766,20 @@ void _handlePosixException(Exception e, String? message, int errorCode, String?
|
||||
_throwFileSystemException(errorMessage);
|
||||
}
|
||||
|
||||
void _handleMacOSException(Exception e, String? message, int errorCode, String? posixPermissionSuggestion) {
|
||||
// https://github.com/apple/darwin-xnu/blob/master/bsd/dev/dtrace/scripts/errno.d
|
||||
const int ebadarch = 86;
|
||||
if (errorCode == ebadarch) {
|
||||
final StringBuffer errorBuffer = StringBuffer();
|
||||
errorBuffer.writeln(message);
|
||||
errorBuffer.writeln('This binary was built with the incorrect architecture to run on this machine.');
|
||||
errorBuffer.writeln('Flutter requires the Rosetta translation environment. If you are on an ARM Mac, try running:');
|
||||
errorBuffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license');
|
||||
_throwFileSystemException(errorBuffer.toString());
|
||||
}
|
||||
_handlePosixException(e, message, errorCode, posixPermissionSuggestion);
|
||||
}
|
||||
|
||||
void _handleWindowsException(Exception e, String? message, int errorCode) {
|
||||
// From:
|
||||
// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes
|
||||
|
||||
@@ -42,7 +42,7 @@ class UserMessages {
|
||||
String flutterMirrorURL(String url) => 'Flutter download mirror $url';
|
||||
String get flutterBinariesDoNotRun =>
|
||||
'Downloaded executables cannot execute on host.\n'
|
||||
'See https://github.com/flutter/flutter/issues/6207 for more information';
|
||||
'See https://github.com/flutter/flutter/issues/6207 for more information.';
|
||||
String get flutterBinariesLinuxRepairCommands =>
|
||||
'On Debian/Ubuntu/Mint: sudo apt-get install lib32stdc++6\n'
|
||||
'On Fedora: dnf install libstdc++.i686\n'
|
||||
|
||||
@@ -549,6 +549,9 @@ class FlutterValidator extends DoctorValidator {
|
||||
buffer.writeln(_userMessages.flutterBinariesDoNotRun);
|
||||
if (_platform.isLinux) {
|
||||
buffer.writeln(_userMessages.flutterBinariesLinuxRepairCommands);
|
||||
} else if (_platform.isMacOS && _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm64) {
|
||||
buffer.writeln('Flutter requires the Rosetta translation environment on ARM Macs. Try running:');
|
||||
buffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license');
|
||||
}
|
||||
messages.add(ValidationMessage.error(buffer.toString()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user