Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/application_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ abstract class IOSApp extends ApplicationPackage {
}

static Future<IOSApp> fromIosProject(IosProject project, BuildInfo buildInfo) {
if (getCurrentHostPlatform() != HostPlatform.darwin_x64) {
if (!globals.platform.isMacOS) {
return null;
}
if (!project.exists) {
Expand Down
70 changes: 58 additions & 12 deletions packages/flutter_tools/lib/src/base/os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:file/file.dart';
import 'package:meta/meta.dart';
import 'package:process/process.dart';

import '../build_info.dart';
import '../globals.dart' as globals;
import 'common.dart';
import 'file_system.dart';
Expand All @@ -29,6 +30,13 @@ abstract class OperatingSystemUtils {
platform: platform,
processManager: processManager,
);
} else if (platform.isMacOS) {
return _MacOSUtils(
fileSystem: fileSystem,
logger: logger,
platform: platform,
processManager: processManager,
);
} else {
return _PosixUtils(
fileSystem: fileSystem,
Expand Down Expand Up @@ -112,6 +120,8 @@ abstract class OperatingSystemUtils {
return osNames.containsKey(osName) ? osNames[osName] : osName;
}

HostPlatform get hostPlatform;

List<File> _which(String execName, { bool all = false });

/// Returns the separator between items in the PATH environment variable.
Expand Down Expand Up @@ -246,30 +256,63 @@ class _PosixUtils extends OperatingSystemUtils {
return _fileSystem.file(path);
}

@override
String get pathVarSeparator => ':';

@override
HostPlatform hostPlatform = HostPlatform.linux_x64;
}

class _MacOSUtils extends _PosixUtils {
_MacOSUtils({
@required FileSystem fileSystem,
@required Logger logger,
@required Platform platform,
@required ProcessManager processManager,
}) : super(
fileSystem: fileSystem,
logger: logger,
platform: platform,
processManager: processManager,
);

String _name;

@override
String get name {
if (_name == null) {
if (_platform.isMacOS) {
final List<RunResult> results = <RunResult>[
_processUtils.runSync(<String>['sw_vers', '-productName']),
_processUtils.runSync(<String>['sw_vers', '-productVersion']),
_processUtils.runSync(<String>['sw_vers', '-buildVersion']),
_processUtils.runSync(<String>['uname', '-m']),
];
if (results.every((RunResult result) => result.exitCode == 0)) {
_name = '${results[0].stdout.trim()} ${results[1].stdout
.trim()} ${results[2].stdout.trim()} ${results[3].stdout.trim()}';
}
final List<RunResult> results = <RunResult>[
_processUtils.runSync(<String>['sw_vers', '-productName']),
_processUtils.runSync(<String>['sw_vers', '-productVersion']),
_processUtils.runSync(<String>['sw_vers', '-buildVersion']),
];
if (results.every((RunResult result) => result.exitCode == 0)) {
_name =
'${results[0].stdout.trim()} ${results[1].stdout.trim()} ${results[2].stdout.trim()} ${getNameForHostPlatform(hostPlatform)}';
}
_name ??= super.name;
}
return _name;
}

HostPlatform _hostPlatform;

// On ARM returns arm64, even when this process is running in Rosetta.
@override
String get pathVarSeparator => ':';
HostPlatform get hostPlatform {
if (_hostPlatform == null) {
final RunResult arm64Check =
_processUtils.runSync(<String>['sysctl', 'hw.optional.arm64']);
// hw.optional.arm64 is unavailable on < macOS 11 and exits with 1, assume x86 on failure.
// On arm64 stdout is "sysctl hw.optional.arm64: 1"
if (arm64Check.exitCode == 0 && arm64Check.stdout.trim().endsWith('1')) {
_hostPlatform = HostPlatform.darwin_arm;
} else {
_hostPlatform = HostPlatform.darwin_x64;
}
}
return _hostPlatform;
}
}

class _WindowsUtils extends OperatingSystemUtils {
Expand All @@ -285,6 +328,9 @@ class _WindowsUtils extends OperatingSystemUtils {
processManager: processManager,
);

@override
HostPlatform hostPlatform = HostPlatform.windows_x64;

@override
void makeExecutable(File file) {}

Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/build_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ bool isEmulatorBuildMode(BuildMode mode) {

enum HostPlatform {
darwin_x64,
darwin_arm,
linux_x64,
windows_x64,
}
Expand All @@ -406,6 +407,8 @@ String getNameForHostPlatform(HostPlatform platform) {
switch (platform) {
case HostPlatform.darwin_x64:
return 'darwin-x64';
case HostPlatform.darwin_arm:
return 'darwin-arm';
case HostPlatform.linux_x64:
return 'linux-x64';
case HostPlatform.windows_x64:
Expand All @@ -418,6 +421,7 @@ String getNameForHostPlatform(HostPlatform platform) {
enum TargetPlatform {
android,
ios,
// darwin_arm64 not yet supported, macOS desktop targets run in Rosetta as x86.
darwin_x64,
linux_x64,
windows_x64,
Expand Down
Loading