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