Unverified Commit 3a479e7e authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Rename SdkType -> EnvironmentType (#71095)

parent 2b4a2358
......@@ -12,7 +12,6 @@ import 'base/logger.dart';
import 'base/utils.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'globals.dart' as globals;
import 'macos/xcode.dart';
/// Information about a build to be performed or used.
class BuildInfo {
......@@ -320,6 +319,12 @@ BuildMode getBuildModeForName(String name) {
return BuildMode.fromName(name);
}
/// Environment type of the target device.
enum EnvironmentType {
physical,
simulator,
}
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) {
if (buildNumber == null) {
return null;
......@@ -481,22 +486,18 @@ enum AndroidArch {
}
/// The default set of iOS device architectures to build for.
List<DarwinArch> defaultIOSArchsForSdk(SdkType sdkType) {
switch (sdkType) {
case SdkType.iPhone:
return <DarwinArch>[
DarwinArch.armv7,
DarwinArch.arm64,
];
case SdkType.iPhoneSimulator:
List<DarwinArch> defaultIOSArchsForEnvironment(
EnvironmentType environmentType) {
if (environmentType == EnvironmentType.simulator) {
return <DarwinArch>[
// Apple Silicon ARM simulators not yet supported.
DarwinArch.x86_64,
];
default:
assert(false, 'Unknown SDK type $sdkType');
return null;
}
return <DarwinArch>[
DarwinArch.armv7,
DarwinArch.arm64,
];
}
String getNameForDarwinArch(DarwinArch arch) {
......
......@@ -21,7 +21,6 @@ import '../cache.dart';
import '../convert.dart';
import '../globals.dart' as globals;
import '../macos/cocoapod_utils.dart';
import '../macos/xcode.dart';
import '../plugins.dart';
import '../project.dart';
import '../runner/flutter_command.dart' show DevelopmentArtifact, FlutterCommandResult;
......@@ -375,11 +374,13 @@ end
final Status status = globals.logger.startProgress(
' ├─Building App.framework...',
);
final List<SdkType> sdkTypes = <SdkType>[SdkType.iPhone];
final List<EnvironmentType> environmentTypes = <EnvironmentType>[
EnvironmentType.physical,
];
final List<Directory> frameworks = <Directory>[];
Target target;
if (buildInfo.isDebug) {
sdkTypes.add(SdkType.iPhoneSimulator);
environmentTypes.add(EnvironmentType.simulator);
target = const DebugIosApplicationBundle();
} else if (buildInfo.isProfile) {
target = const ProfileIosApplicationBundle();
......@@ -388,8 +389,9 @@ end
}
try {
for (final SdkType sdkType in sdkTypes) {
final Directory outputBuildDirectory = sdkType == SdkType.iPhone
for (final EnvironmentType sdkType in environmentTypes) {
final Directory outputBuildDirectory =
sdkType == EnvironmentType.physical
? iPhoneBuildOutput
: simulatorBuildOutput;
frameworks.add(outputBuildDirectory.childDirectory(appFrameworkName));
......@@ -411,7 +413,7 @@ end
buildInfo.extraGenSnapshotOptions.join(','),
if (buildInfo?.extraFrontEndOptions?.isNotEmpty ?? false)
kExtraFrontEndOptions: buildInfo.extraFrontEndOptions.join(','),
kIosArchs: defaultIOSArchsForSdk(sdkType)
kIosArchs: defaultIOSArchsForEnvironment(sdkType)
.map(getNameForDarwinArch)
.join(' '),
kSdkRoot: await globals.xcode.sdkLocation(sdkType),
......
......@@ -29,29 +29,16 @@ const int kXcodeRequiredVersionMajor = 11;
const int kXcodeRequiredVersionMinor = 0;
const int kXcodeRequiredVersionPatch = 0;
enum SdkType {
iPhone,
iPhoneSimulator,
macOS,
}
/// SDK name passed to `xcrun --sdk`. Corresponds to undocumented Xcode
/// SUPPORTED_PLATFORMS values.
///
/// Usage: xcrun [options] <tool name> ... arguments ...
/// ...
/// --sdk <sdk name> find the tool for the given SDK name.
String getNameForSdk(SdkType sdk) {
switch (sdk) {
case SdkType.iPhone:
return 'iphoneos';
case SdkType.iPhoneSimulator:
return 'iphonesimulator';
case SdkType.macOS:
return 'macosx';
}
assert(false);
return null;
String getSDKNameForIOSEnvironmentType(EnvironmentType environmentType) {
return (environmentType == EnvironmentType.simulator)
? 'iphonesimulator'
: 'iphoneos';
}
/// A utility class for interacting with Xcode command line tools.
......@@ -178,10 +165,10 @@ class Xcode {
);
}
Future<String> sdkLocation(SdkType sdk) async {
assert(sdk != null);
Future<String> sdkLocation(EnvironmentType environmentType) async {
assert(environmentType != null);
final RunResult runResult = await _processUtils.run(
<String>[...xcrunCommand(), '--sdk', getNameForSdk(sdk), '--show-sdk-path'],
<String>[...xcrunCommand(), '--sdk', getSDKNameForIOSEnvironmentType(environmentType), '--show-sdk-path'],
);
if (runResult.exitCode != 0) {
throwToolExit('Could not find SDK location: ${runResult.stderr}');
......@@ -203,6 +190,17 @@ class Xcode {
}
}
EnvironmentType environmentTypeFromSdkroot(Directory sdkroot) {
assert(sdkroot != null);
// iPhoneSimulator.sdk or iPhoneOS.sdk
final String sdkName = sdkroot.basename.toLowerCase();
if (sdkName.contains('iphone')) {
return sdkName.contains('simulator') ? EnvironmentType.simulator : EnvironmentType.physical;
}
assert(false);
return null;
}
enum XCDeviceEvent {
attach,
detach,
......
......@@ -300,9 +300,8 @@ void main() {
});
testWithoutContext('SDK name', () {
expect(getNameForSdk(SdkType.iPhone), 'iphoneos');
expect(getNameForSdk(SdkType.iPhoneSimulator), 'iphonesimulator');
expect(getNameForSdk(SdkType.macOS), 'macosx');
expect(getSDKNameForIOSEnvironmentType(EnvironmentType.physical), 'iphoneos');
expect(getSDKNameForIOSEnvironmentType(EnvironmentType.simulator), 'iphonesimulator');
});
group('SDK location', () {
......@@ -314,17 +313,7 @@ void main() {
stdout: sdkroot,
));
expect(await xcode.sdkLocation(SdkType.iPhone), sdkroot);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
testWithoutContext('--show-sdk-path macosx', () async {
fakeProcessManager.addCommand(const FakeCommand(
command: <String>['xcrun', '--sdk', 'macosx', '--show-sdk-path'],
stdout: sdkroot,
));
expect(await xcode.sdkLocation(SdkType.macOS), sdkroot);
expect(await xcode.sdkLocation(EnvironmentType.physical), sdkroot);
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
......@@ -335,7 +324,7 @@ void main() {
stderr: 'xcrun: error:',
));
expect(() async => await xcode.sdkLocation(SdkType.iPhone),
expect(() async => await xcode.sdkLocation(EnvironmentType.physical),
throwsToolExit(message: 'Could not find SDK location'));
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment