Skip to content

Commit

Permalink
Clean Xcode project before analyzing and testing (#6842)
Browse files Browse the repository at this point in the history
On macOS 14, caching seems to be more aggressive with swiftmodules and can cause conflicts between tests. To mitigate this, use `xcodebuild clean` (cleans Derived Data for the project) as part of `xcodebuild analyze` and `xcodebuild test`.

Fixes flutter/flutter#149270. Fixes flutter/flutter#149266.
  • Loading branch information
vashworth authored Jun 4, 2024
1 parent bb8c7b2 commit 5e88f94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion script/tool/lib/src/native_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ this command.
_printRunningExampleTestsMessage(example, platform);
final int exitCode = await _xcode.runXcodeBuild(
example.directory,
actions: <String>['test'],
// Clean before testing to remove cached swiftmodules from previous
// runs, which can cause conflicts.
actions: <String>['clean', 'test'],
workspace: '${platform.toLowerCase()}/Runner.xcworkspace',
scheme: 'Runner',
configuration: 'Debug',
Expand Down
4 changes: 3 additions & 1 deletion script/tool/lib/src/xcode_analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
print('Running $platform tests and analyzer for $examplePath...');
final int exitCode = await _xcode.runXcodeBuild(
example.directory,
actions: <String>['analyze'],
// Clean before analyzing to remove cached swiftmodules from previous
// runs, which can cause conflicts.
actions: <String>['clean', 'analyze'],
workspace: '${platform.toLowerCase()}/Runner.xcworkspace',
scheme: 'Runner',
configuration: 'Debug',
Expand Down
7 changes: 4 additions & 3 deletions script/tool/test/native_test_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void main() {
'xcrun',
<String>[
'xcodebuild',
'clean',
'test',
'-workspace',
'$platform/Runner.xcworkspace',
Expand Down Expand Up @@ -220,7 +221,7 @@ void main() {
getMockXcodebuildListProcess(<String>['RunnerTests', 'RunnerUITests']),
// Exit code 66 from testing indicates no tests.
FakeProcessInfo(
MockProcess(exitCode: 66), <String>['xcodebuild', 'test']),
MockProcess(exitCode: 66), <String>['xcodebuild', 'clean', 'test']),
];
final List<String> output = await runCapturingPrint(
runner, <String>['native-test', '--macos', '--no-unit']);
Expand Down Expand Up @@ -1469,11 +1470,11 @@ public class FlutterActivityTest {
getMockXcodebuildListProcess(
<String>['RunnerTests', 'RunnerUITests']), // iOS list
FakeProcessInfo(
MockProcess(), <String>['xcodebuild', 'test']), // iOS run
MockProcess(), <String>['xcodebuild', 'clean', 'test']), // iOS run
getMockXcodebuildListProcess(
<String>['RunnerTests', 'RunnerUITests']), // macOS list
FakeProcessInfo(
MockProcess(), <String>['xcodebuild', 'test']), // macOS run
MockProcess(), <String>['xcodebuild', 'clean', 'test']), // macOS run
];

final List<String> output = await runCapturingPrint(runner, <String>[
Expand Down
8 changes: 8 additions & 0 deletions script/tool/test/xcode_analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'ios/Runner.xcworkspace',
Expand Down Expand Up @@ -146,6 +147,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'ios/Runner.xcworkspace',
Expand Down Expand Up @@ -244,6 +246,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'macos/Runner.xcworkspace',
Expand Down Expand Up @@ -278,6 +281,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'macos/Runner.xcworkspace',
Expand Down Expand Up @@ -350,6 +354,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'ios/Runner.xcworkspace',
Expand All @@ -366,6 +371,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'macos/Runner.xcworkspace',
Expand Down Expand Up @@ -406,6 +412,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'macos/Runner.xcworkspace',
Expand Down Expand Up @@ -445,6 +452,7 @@ void main() {
'xcrun',
const <String>[
'xcodebuild',
'clean',
'analyze',
'-workspace',
'ios/Runner.xcworkspace',
Expand Down

0 comments on commit 5e88f94

Please sign in to comment.