Print pretty error when xcodebuild fails due to missing simulator (#130286)

Starting in Xcode 15, the simulator is no longer included in Xcode and must be downloaded and installed separately.

If you try to run flutter and the simulator is missing, you'll get an error like
```
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
               		{ id:B1234A5C-67B8-901D-B2CB-FE34F56BDE78 }

               	Ineligible destinations for the "Runner" scheme:
               		{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device, error:iOS 17.0 is not installed. To use with Xcode, first download and install the platform }
```

Print a pretty error to make it easier for developers to know what to do.

Part 2 of https://github.com/flutter/flutter/issues/129558.
This commit is contained in:
Victoria Ashworth
2023-07-13 11:51:13 -05:00
committed by GitHub
parent 60c1f37609
commit 604010e9e2
6 changed files with 468 additions and 1 deletions

View File

@@ -638,6 +638,37 @@ void main() {
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
testUsingContext('Extra error message for missing simulator platform in xcresult bundle.', () async {
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles();
await expectLater(
createTestCommandRunner(command).run(const <String>['build', 'ios', '--no-pub']),
throwsToolExit(),
);
expect(testLogger.errorText, contains(missingPlatformInstructions('iOS 17.0')));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(exitCode: 1, onRun: () {
fileSystem.systemTempDirectory.childDirectory(_xcBundleFilePath).createSync();
}),
setUpXCResultCommand(stdout: kSampleResultJsonWithActionIssues),
setUpRsyncCommand(),
]),
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
testUsingContext('Delete xcresult bundle before each xcodebuild command.', () async {
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),

View File

@@ -245,6 +245,44 @@ Error launching application on iPhone.''',
);
});
testWithoutContext('fallback to stdout: Ineligible destinations', () async {
final Map<String, String> buildSettingsWithDevTeam = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'test.app',
'DEVELOPMENT_TEAM': 'a team',
};
final XcodeBuildResult buildResult = XcodeBuildResult(
success: false,
stderr: '''
Launching lib/main.dart on iPhone in debug mode...
Signing iOS app for device deployment using developer identity: "iPhone Developer: test@flutter.io (1122334455)"
Running Xcode build... 1.3s
Failed to build iOS app
Error output from Xcode build:
↳
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
{ id:1234D567-890C-1DA2-34E5-F6789A0123C4 }
Ineligible destinations for the "Runner" scheme:
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device, error:iOS 17.0 is not installed. To use with Xcode, first download and install the platform }
Could not build the precompiled application for the device.
Error launching application on iPhone.''',
xcodeBuildExecution: XcodeBuildExecution(
buildCommands: <String>['xcrun', 'xcodebuild', 'blah'],
appDirectory: '/blah/blah',
environmentType: EnvironmentType.physical,
buildSettings: buildSettingsWithDevTeam,
),
);
await diagnoseXcodeBuildFailure(buildResult, testUsage, logger);
expect(
logger.errorText,
contains(missingPlatformInstructions('iOS 17.0')),
);
});
testWithoutContext('No development team shows message', () async {
final XcodeBuildResult buildResult = XcodeBuildResult(
success: false,

View File

@@ -204,6 +204,19 @@ void main() {
expect(result.parsingErrorMessage, isNull);
});
testWithoutContext(
'correctly parse sample result json with action issues.', () async {
final XCResultGenerator generator = setupGenerator(resultJson: kSampleResultJsonWithActionIssues);
final XCResultIssueDiscarder discarder = XCResultIssueDiscarder(typeMatcher: XCResultIssueType.warning);
final XCResult result = await generator.generate(issueDiscarders: <XCResultIssueDiscarder>[discarder]);
expect(result.issues.length, 1);
expect(result.issues.first.type, XCResultIssueType.error);
expect(result.issues.first.subType, 'Uncategorized');
expect(result.issues.first.message, contains('Unable to find a destination matching the provided destination specifier'));
expect(result.parseSuccess, isTrue);
expect(result.parsingErrorMessage, isNull);
});
testWithoutContext(
'error: `xcresulttool get` process fail should return an `XCResult` with stderr as `parsingErrorMessage`.',
() async {

View File

@@ -378,3 +378,252 @@ const String kSampleResultJsonWithProvisionIssue = r'''
}
}
''';
/// An example xcresult bundle json that contains action issues.
const String kSampleResultJsonWithActionIssues = r'''
{
"_type" : {
"_name" : "ActionsInvocationRecord"
},
"actions" : {
"_type" : {
"_name" : "Array"
},
"_values" : [
{
"_type" : {
"_name" : "ActionRecord"
},
"actionResult" : {
"_type" : {
"_name" : "ActionResult"
},
"coverage" : {
"_type" : {
"_name" : "CodeCoverageInfo"
}
},
"issues" : {
"_type" : {
"_name" : "ResultIssueSummaries"
},
"testFailureSummaries" : {
"_type" : {
"_name" : "Array"
},
"_values" : [
{
"_type" : {
"_name" : "TestFailureIssueSummary",
"_supertype" : {
"_name" : "IssueSummary"
}
},
"issueType" : {
"_type" : {
"_name" : "String"
},
"_value" : "Uncategorized"
},
"message" : {
"_type" : {
"_name" : "String"
},
"_value" : "Unable to find a destination matching the provided destination specifier:\n\t\t{ id:1234D567-890C-1DA2-34E5-F6789A0123C4 }\n\n\tIneligible destinations for the \"Runner\" scheme:\n\t\t{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device, error:iOS 17.0 is not installed. To use with Xcode, first download and install the platform }"
}
}
]
}
},
"logRef" : {
"_type" : {
"_name" : "Reference"
},
"id" : {
"_type" : {
"_name" : "String"
},
"_value" : "0~5X-qvql8_ppq0bj9taBMeZd4L2lXQagy1twsFRWwc06r42obpBZfP87uKnGO98mp5CUz1Ppr1knHiTMH9tOuwQ=="
},
"targetType" : {
"_type" : {
"_name" : "TypeDefinition"
},
"name" : {
"_type" : {
"_name" : "String"
},
"_value" : "ActivityLogSection"
}
}
},
"metrics" : {
"_type" : {
"_name" : "ResultMetrics"
}
},
"resultName" : {
"_type" : {
"_name" : "String"
},
"_value" : "All Tests"
},
"status" : {
"_type" : {
"_name" : "String"
},
"_value" : "failedToStart"
},
"testsRef" : {
"_type" : {
"_name" : "Reference"
},
"id" : {
"_type" : {
"_name" : "String"
},
"_value" : "0~Dmuz8-g6YRb8HPVbTUXJD21oy3r5jxIGi-njd2Lc43yR5JlJf7D78HtNn2BsrF5iw1uYMnsuJ9xFDV7ZAmwhGg=="
},
"targetType" : {
"_type" : {
"_name" : "TypeDefinition"
},
"name" : {
"_type" : {
"_name" : "String"
},
"_value" : "ActionTestPlanRunSummaries"
}
}
}
},
"buildResult" : {
"_type" : {
"_name" : "ActionResult"
},
"coverage" : {
"_type" : {
"_name" : "CodeCoverageInfo"
}
},
"issues" : {
"_type" : {
"_name" : "ResultIssueSummaries"
}
},
"metrics" : {
"_type" : {
"_name" : "ResultMetrics"
}
},
"resultName" : {
"_type" : {
"_name" : "String"
},
"_value" : "Build Succeeded"
},
"status" : {
"_type" : {
"_name" : "String"
},
"_value" : "succeeded"
}
},
"endedTime" : {
"_type" : {
"_name" : "Date"
},
"_value" : "2023-07-10T12:52:22.592-0500"
},
"runDestination" : {
"_type" : {
"_name" : "ActionRunDestinationRecord"
},
"localComputerRecord" : {
"_type" : {
"_name" : "ActionDeviceRecord"
},
"platformRecord" : {
"_type" : {
"_name" : "ActionPlatformRecord"
}
}
},
"targetDeviceRecord" : {
"_type" : {
"_name" : "ActionDeviceRecord"
},
"platformRecord" : {
"_type" : {
"_name" : "ActionPlatformRecord"
}
}
},
"targetSDKRecord" : {
"_type" : {
"_name" : "ActionSDKRecord"
}
}
},
"schemeCommandName" : {
"_type" : {
"_name" : "String"
},
"_value" : "Test"
},
"schemeTaskName" : {
"_type" : {
"_name" : "String"
},
"_value" : "BuildAndAction"
},
"startedTime" : {
"_type" : {
"_name" : "Date"
},
"_value" : "2023-07-10T12:52:22.592-0500"
},
"title" : {
"_type" : {
"_name" : "String"
},
"_value" : "RunnerTests.xctest"
}
}
]
},
"issues" : {
"_type" : {
"_name" : "ResultIssueSummaries"
}
},
"metadataRef" : {
"_type" : {
"_name" : "Reference"
},
"id" : {
"_type" : {
"_name" : "String"
},
"_value" : "0~pY0GqmiVE6Q3qlWdLJDp_PnrsUKsJ7KKM1zKGnvEZOWGdBeGNArjjU62kgF2UBFdQLdRmf5SGpImQfJB6e7vDQ=="
},
"targetType" : {
"_type" : {
"_name" : "TypeDefinition"
},
"name" : {
"_type" : {
"_name" : "String"
},
"_value" : "ActionsInvocationMetadata"
}
}
},
"metrics" : {
"_type" : {
"_name" : "ResultMetrics"
}
}
}
''';