Unverified Commit 89637e4e authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Replace iOS physical/simulator bools with enum (#87138)

parent 32c2e2ba
...@@ -50,7 +50,7 @@ class BuildIOSCommand extends _BuildIOSSubCommand { ...@@ -50,7 +50,7 @@ class BuildIOSCommand extends _BuildIOSSubCommand {
final XcodeBuildAction xcodeBuildAction = XcodeBuildAction.build; final XcodeBuildAction xcodeBuildAction = XcodeBuildAction.build;
@override @override
bool get forSimulator => boolArg('simulator'); EnvironmentType get environmentType => boolArg('simulator') ? EnvironmentType.simulator : EnvironmentType.physical;
@override @override
bool get configOnly => boolArg('config-only'); bool get configOnly => boolArg('config-only');
...@@ -91,7 +91,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -91,7 +91,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
final XcodeBuildAction xcodeBuildAction = XcodeBuildAction.archive; final XcodeBuildAction xcodeBuildAction = XcodeBuildAction.archive;
@override @override
final bool forSimulator = false; final EnvironmentType environmentType = EnvironmentType.physical;
@override @override
final bool configOnly = false; final bool configOnly = false;
...@@ -208,7 +208,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -208,7 +208,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
}; };
XcodeBuildAction get xcodeBuildAction; XcodeBuildAction get xcodeBuildAction;
bool get forSimulator; EnvironmentType get environmentType;
bool get configOnly; bool get configOnly;
bool get shouldCodesign; bool get shouldCodesign;
...@@ -229,19 +229,19 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -229,19 +229,19 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
defaultBuildMode = forSimulator ? BuildMode.debug : BuildMode.release; defaultBuildMode = environmentType == EnvironmentType.simulator ? BuildMode.debug : BuildMode.release;
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
if (!supported) { if (!supported) {
throwToolExit('Building for iOS is only supported on macOS.'); throwToolExit('Building for iOS is only supported on macOS.');
} }
if (forSimulator && !buildInfo.supportsSimulator) { if (environmentType == EnvironmentType.simulator && !buildInfo.supportsSimulator) {
throwToolExit('${toTitleCase(buildInfo.friendlyModeName)} mode is not supported for simulators.'); throwToolExit('${toTitleCase(buildInfo.friendlyModeName)} mode is not supported for simulators.');
} }
if (configOnly && buildInfo.codeSizeDirectory != null) { if (configOnly && buildInfo.codeSizeDirectory != null) {
throwToolExit('Cannot analyze code size without performing a full build.'); throwToolExit('Cannot analyze code size without performing a full build.');
} }
if (!forSimulator && !shouldCodesign) { if (environmentType == EnvironmentType.physical && !shouldCodesign) {
globals.printStatus( globals.printStatus(
'Warning: Building for device with codesigning disabled. You will ' 'Warning: Building for device with codesigning disabled. You will '
'have to manually codesign before deploying to device.', 'have to manually codesign before deploying to device.',
...@@ -254,7 +254,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -254,7 +254,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
throwToolExit('Application not configured for iOS'); throwToolExit('Application not configured for iOS');
} }
final String logTarget = forSimulator ? 'simulator' : 'device'; final String logTarget = environmentType == EnvironmentType.simulator ? 'simulator' : 'device';
final String typeName = globals.artifacts.getEngineType(TargetPlatform.ios, buildInfo.mode); final String typeName = globals.artifacts.getEngineType(TargetPlatform.ios, buildInfo.mode);
if (xcodeBuildAction == XcodeBuildAction.build) { if (xcodeBuildAction == XcodeBuildAction.build) {
globals.printStatus('Building $app for $logTarget ($typeName)...'); globals.printStatus('Building $app for $logTarget ($typeName)...');
...@@ -265,7 +265,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -265,7 +265,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
app: app, app: app,
buildInfo: buildInfo, buildInfo: buildInfo,
targetOverride: targetFile, targetOverride: targetFile,
buildForDevice: !forSimulator, environmentType: environmentType,
codesign: shouldCodesign, codesign: shouldCodesign,
configOnly: configOnly, configOnly: configOnly,
buildAction: xcodeBuildAction, buildAction: xcodeBuildAction,
......
...@@ -327,7 +327,7 @@ class IOSDevice extends Device { ...@@ -327,7 +327,7 @@ class IOSDevice extends Device {
app: package as BuildableIOSApp, app: package as BuildableIOSApp,
buildInfo: debuggingOptions.buildInfo, buildInfo: debuggingOptions.buildInfo,
targetOverride: mainPath, targetOverride: mainPath,
buildForDevice: true, environmentType: EnvironmentType.physical,
activeArch: cpuArchitecture, activeArch: cpuArchitecture,
deviceID: id, deviceID: id,
); );
......
...@@ -96,7 +96,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -96,7 +96,7 @@ Future<XcodeBuildResult> buildXcodeProject({
BuildableIOSApp app, BuildableIOSApp app,
BuildInfo buildInfo, BuildInfo buildInfo,
String targetOverride, String targetOverride,
bool buildForDevice, EnvironmentType environmentType = EnvironmentType.physical,
DarwinArch activeArch, DarwinArch activeArch,
bool codesign = true, bool codesign = true,
String deviceID, String deviceID,
...@@ -181,10 +181,10 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -181,10 +181,10 @@ Future<XcodeBuildResult> buildXcodeProject({
final Map<String, String> buildSettings = await app.project.buildSettingsForBuildInfo( final Map<String, String> buildSettings = await app.project.buildSettingsForBuildInfo(
buildInfo, buildInfo,
environmentType: buildForDevice ? EnvironmentType.physical : EnvironmentType.simulator, environmentType: environmentType
) ?? <String, String>{}; ) ?? <String, String>{};
if (codesign && buildForDevice) { if (codesign && environmentType == EnvironmentType.physical) {
autoSigningConfigs = await getCodeSigningIdentityDevelopmentTeam( autoSigningConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: buildSettings, buildSettings: buildSettings,
processManager: globals.processManager, processManager: globals.processManager,
...@@ -251,18 +251,18 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -251,18 +251,18 @@ Future<XcodeBuildResult> buildXcodeProject({
// The -sdk argument has to be omitted if a watchOS companion app exists. // The -sdk argument has to be omitted if a watchOS companion app exists.
// Otherwise the build will fail as WatchKit dependencies cannot be build using the iOS SDK. // Otherwise the build will fail as WatchKit dependencies cannot be build using the iOS SDK.
globals.printStatus('Watch companion app found. Adjusting build settings.'); globals.printStatus('Watch companion app found. Adjusting build settings.');
if (!buildForDevice && (deviceID == null || deviceID == '')) { if (environmentType == EnvironmentType.simulator && (deviceID == null || deviceID == '')) {
globals.printError('No simulator device ID has been set.'); globals.printError('No simulator device ID has been set.');
globals.printError('A device ID is required to build an app with a watchOS companion app.'); globals.printError('A device ID is required to build an app with a watchOS companion app.');
globals.printError('Please run "flutter devices" to get a list of available device IDs'); globals.printError('Please run "flutter devices" to get a list of available device IDs');
globals.printError('and specify one using the -d, --device-id flag.'); globals.printError('and specify one using the -d, --device-id flag.');
return XcodeBuildResult(success: false); return XcodeBuildResult(success: false);
} }
if (!buildForDevice) { if (environmentType == EnvironmentType.simulator) {
buildCommands.addAll(<String>['-destination', 'id=$deviceID']); buildCommands.addAll(<String>['-destination', 'id=$deviceID']);
} }
} else { } else {
if (buildForDevice) { if (environmentType == EnvironmentType.physical) {
buildCommands.addAll(<String>['-sdk', 'iphoneos']); buildCommands.addAll(<String>['-sdk', 'iphoneos']);
} else { } else {
buildCommands.addAll(<String>['-sdk', 'iphonesimulator']); buildCommands.addAll(<String>['-sdk', 'iphonesimulator']);
...@@ -378,7 +378,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -378,7 +378,7 @@ Future<XcodeBuildResult> buildXcodeProject({
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: buildCommands, buildCommands: buildCommands,
appDirectory: app.project.hostAppRoot.path, appDirectory: app.project.hostAppRoot.path,
buildForPhysicalDevice: buildForDevice, environmentType: environmentType,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
...@@ -390,7 +390,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -390,7 +390,7 @@ Future<XcodeBuildResult> buildXcodeProject({
// actual directory will end with 'iphonesimulator' for simulator builds. // actual directory will end with 'iphonesimulator' for simulator builds.
// The value of TARGET_BUILD_DIR is adjusted to accommodate for this effect. // The value of TARGET_BUILD_DIR is adjusted to accommodate for this effect.
String targetBuildDir = buildSettings['TARGET_BUILD_DIR']; String targetBuildDir = buildSettings['TARGET_BUILD_DIR'];
if (hasWatchCompanion && !buildForDevice) { if (hasWatchCompanion && environmentType == EnvironmentType.simulator) {
globals.printTrace('Replacing iphoneos with iphonesimulator in TARGET_BUILD_DIR.'); globals.printTrace('Replacing iphoneos with iphonesimulator in TARGET_BUILD_DIR.');
targetBuildDir = targetBuildDir.replaceFirst('iphoneos', 'iphonesimulator'); targetBuildDir = targetBuildDir.replaceFirst('iphoneos', 'iphonesimulator');
} }
...@@ -437,7 +437,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -437,7 +437,7 @@ Future<XcodeBuildResult> buildXcodeProject({
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: buildCommands, buildCommands: buildCommands,
appDirectory: app.project.hostAppRoot.path, appDirectory: app.project.hostAppRoot.path,
buildForPhysicalDevice: buildForDevice, environmentType: environmentType,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
...@@ -508,7 +508,7 @@ return result.exitCode != 0 && ...@@ -508,7 +508,7 @@ return result.exitCode != 0 &&
Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsage, Logger logger) async { Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsage, Logger logger) async {
if (result.xcodeBuildExecution != null && if (result.xcodeBuildExecution != null &&
result.xcodeBuildExecution.buildForPhysicalDevice && result.xcodeBuildExecution.environmentType == EnvironmentType.physical &&
result.stdout?.toUpperCase()?.contains('BITCODE') == true) { result.stdout?.toUpperCase()?.contains('BITCODE') == true) {
BuildEvent('xcode-bitcode-failure', BuildEvent('xcode-bitcode-failure',
type: 'ios', type: 'ios',
...@@ -533,7 +533,7 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa ...@@ -533,7 +533,7 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa
} }
if (result.xcodeBuildExecution != null && if (result.xcodeBuildExecution != null &&
result.xcodeBuildExecution.buildForPhysicalDevice && result.xcodeBuildExecution.environmentType == EnvironmentType.physical &&
result.stdout?.contains('BCEROR') == true && result.stdout?.contains('BCEROR') == true &&
// May need updating if Xcode changes its outputs. // May need updating if Xcode changes its outputs.
result.stdout?.contains("Xcode couldn't find a provisioning profile matching") == true) { result.stdout?.contains("Xcode couldn't find a provisioning profile matching") == true) {
...@@ -544,14 +544,14 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa ...@@ -544,14 +544,14 @@ Future<void> diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa
// * DEVELOPMENT_TEAM (automatic signing) // * DEVELOPMENT_TEAM (automatic signing)
// * PROVISIONING_PROFILE (manual signing) // * PROVISIONING_PROFILE (manual signing)
if (result.xcodeBuildExecution != null && if (result.xcodeBuildExecution != null &&
result.xcodeBuildExecution.buildForPhysicalDevice && result.xcodeBuildExecution.environmentType == EnvironmentType.physical &&
!<String>['DEVELOPMENT_TEAM', 'PROVISIONING_PROFILE'].any( !<String>['DEVELOPMENT_TEAM', 'PROVISIONING_PROFILE'].any(
result.xcodeBuildExecution.buildSettings.containsKey)) { result.xcodeBuildExecution.buildSettings.containsKey)) {
logger.printError(noDevelopmentTeamInstruction, emphasis: true); logger.printError(noDevelopmentTeamInstruction, emphasis: true);
return; return;
} }
if (result.xcodeBuildExecution != null && if (result.xcodeBuildExecution != null &&
result.xcodeBuildExecution.buildForPhysicalDevice && result.xcodeBuildExecution.environmentType == EnvironmentType.physical &&
result.xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') == true) { result.xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') == true) {
logger.printError(''); logger.printError('');
logger.printError('It appears that your application still contains the default signing identifier.'); logger.printError('It appears that your application still contains the default signing identifier.');
...@@ -609,14 +609,14 @@ class XcodeBuildExecution { ...@@ -609,14 +609,14 @@ class XcodeBuildExecution {
XcodeBuildExecution({ XcodeBuildExecution({
@required this.buildCommands, @required this.buildCommands,
@required this.appDirectory, @required this.appDirectory,
@required this.buildForPhysicalDevice, @required this.environmentType,
@required this.buildSettings, @required this.buildSettings,
}); });
/// The original list of Xcode build commands used to produce this build result. /// The original list of Xcode build commands used to produce this build result.
final List<String> buildCommands; final List<String> buildCommands;
final String appDirectory; final String appDirectory;
final bool buildForPhysicalDevice; final EnvironmentType environmentType;
/// The build settings corresponding to the [buildCommands] invocation. /// The build settings corresponding to the [buildCommands] invocation.
final Map<String, String> buildSettings; final Map<String, String> buildSettings;
} }
......
...@@ -529,7 +529,7 @@ class IOSSimulator extends Device { ...@@ -529,7 +529,7 @@ class IOSSimulator extends Device {
app: app, app: app,
buildInfo: buildInfo, buildInfo: buildInfo,
targetOverride: mainPath, targetOverride: mainPath,
buildForDevice: false, environmentType: EnvironmentType.simulator,
deviceID: id, deviceID: id,
); );
if (!buildResult.success) { if (!buildResult.success) {
......
...@@ -149,7 +149,7 @@ void main() { ...@@ -149,7 +149,7 @@ void main() {
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: buildCommands, buildCommands: buildCommands,
appDirectory: '/blah/blah', appDirectory: '/blah/blah',
buildForPhysicalDevice: true, environmentType: EnvironmentType.physical,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
...@@ -229,7 +229,7 @@ Error launching application on iPhone.''', ...@@ -229,7 +229,7 @@ Error launching application on iPhone.''',
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: <String>['xcrun', 'xcodebuild', 'blah'], buildCommands: <String>['xcrun', 'xcodebuild', 'blah'],
appDirectory: '/blah/blah', appDirectory: '/blah/blah',
buildForPhysicalDevice: true, environmentType: EnvironmentType.physical,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
...@@ -310,7 +310,7 @@ Could not build the precompiled application for the device.''', ...@@ -310,7 +310,7 @@ Could not build the precompiled application for the device.''',
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: <String>['xcrun', 'xcodebuild', 'blah'], buildCommands: <String>['xcrun', 'xcodebuild', 'blah'],
appDirectory: '/blah/blah', appDirectory: '/blah/blah',
buildForPhysicalDevice: true, environmentType: EnvironmentType.physical,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
...@@ -347,7 +347,7 @@ Exited (sigterm)''', ...@@ -347,7 +347,7 @@ Exited (sigterm)''',
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: <String>['xcrun', 'xcodebuild', 'blah'], buildCommands: <String>['xcrun', 'xcodebuild', 'blah'],
appDirectory: '/blah/blah', appDirectory: '/blah/blah',
buildForPhysicalDevice: true, environmentType: EnvironmentType.physical,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
...@@ -384,7 +384,7 @@ Exited (sigterm)''', ...@@ -384,7 +384,7 @@ Exited (sigterm)''',
xcodeBuildExecution: XcodeBuildExecution( xcodeBuildExecution: XcodeBuildExecution(
buildCommands: <String>['xcrun', 'xcodebuild', 'blah'], buildCommands: <String>['xcrun', 'xcodebuild', 'blah'],
appDirectory: '/blah/blah', appDirectory: '/blah/blah',
buildForPhysicalDevice: true, environmentType: EnvironmentType.physical,
buildSettings: buildSettings, buildSettings: buildSettings,
), ),
); );
......
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