Skip to content

Commit 5e88f94

Browse files
authored
Clean Xcode project before analyzing and testing (#6842)
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.
1 parent bb8c7b2 commit 5e88f94

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

script/tool/lib/src/native_test_command.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ this command.
465465
_printRunningExampleTestsMessage(example, platform);
466466
final int exitCode = await _xcode.runXcodeBuild(
467467
example.directory,
468-
actions: <String>['test'],
468+
// Clean before testing to remove cached swiftmodules from previous
469+
// runs, which can cause conflicts.
470+
actions: <String>['clean', 'test'],
469471
workspace: '${platform.toLowerCase()}/Runner.xcworkspace',
470472
scheme: 'Runner',
471473
configuration: 'Debug',

script/tool/lib/src/xcode_analyze_command.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
111111
print('Running $platform tests and analyzer for $examplePath...');
112112
final int exitCode = await _xcode.runXcodeBuild(
113113
example.directory,
114-
actions: <String>['analyze'],
114+
// Clean before analyzing to remove cached swiftmodules from previous
115+
// runs, which can cause conflicts.
116+
actions: <String>['clean', 'analyze'],
115117
workspace: '${platform.toLowerCase()}/Runner.xcworkspace',
116118
scheme: 'Runner',
117119
configuration: 'Debug',

script/tool/test/native_test_command_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void main() {
139139
'xcrun',
140140
<String>[
141141
'xcodebuild',
142+
'clean',
142143
'test',
143144
'-workspace',
144145
'$platform/Runner.xcworkspace',
@@ -220,7 +221,7 @@ void main() {
220221
getMockXcodebuildListProcess(<String>['RunnerTests', 'RunnerUITests']),
221222
// Exit code 66 from testing indicates no tests.
222223
FakeProcessInfo(
223-
MockProcess(exitCode: 66), <String>['xcodebuild', 'test']),
224+
MockProcess(exitCode: 66), <String>['xcodebuild', 'clean', 'test']),
224225
];
225226
final List<String> output = await runCapturingPrint(
226227
runner, <String>['native-test', '--macos', '--no-unit']);
@@ -1469,11 +1470,11 @@ public class FlutterActivityTest {
14691470
getMockXcodebuildListProcess(
14701471
<String>['RunnerTests', 'RunnerUITests']), // iOS list
14711472
FakeProcessInfo(
1472-
MockProcess(), <String>['xcodebuild', 'test']), // iOS run
1473+
MockProcess(), <String>['xcodebuild', 'clean', 'test']), // iOS run
14731474
getMockXcodebuildListProcess(
14741475
<String>['RunnerTests', 'RunnerUITests']), // macOS list
14751476
FakeProcessInfo(
1476-
MockProcess(), <String>['xcodebuild', 'test']), // macOS run
1477+
MockProcess(), <String>['xcodebuild', 'clean', 'test']), // macOS run
14771478
];
14781479

14791480
final List<String> output = await runCapturingPrint(runner, <String>[

script/tool/test/xcode_analyze_command_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void main() {
106106
'xcrun',
107107
const <String>[
108108
'xcodebuild',
109+
'clean',
109110
'analyze',
110111
'-workspace',
111112
'ios/Runner.xcworkspace',
@@ -146,6 +147,7 @@ void main() {
146147
'xcrun',
147148
const <String>[
148149
'xcodebuild',
150+
'clean',
149151
'analyze',
150152
'-workspace',
151153
'ios/Runner.xcworkspace',
@@ -244,6 +246,7 @@ void main() {
244246
'xcrun',
245247
const <String>[
246248
'xcodebuild',
249+
'clean',
247250
'analyze',
248251
'-workspace',
249252
'macos/Runner.xcworkspace',
@@ -278,6 +281,7 @@ void main() {
278281
'xcrun',
279282
const <String>[
280283
'xcodebuild',
284+
'clean',
281285
'analyze',
282286
'-workspace',
283287
'macos/Runner.xcworkspace',
@@ -350,6 +354,7 @@ void main() {
350354
'xcrun',
351355
const <String>[
352356
'xcodebuild',
357+
'clean',
353358
'analyze',
354359
'-workspace',
355360
'ios/Runner.xcworkspace',
@@ -366,6 +371,7 @@ void main() {
366371
'xcrun',
367372
const <String>[
368373
'xcodebuild',
374+
'clean',
369375
'analyze',
370376
'-workspace',
371377
'macos/Runner.xcworkspace',
@@ -406,6 +412,7 @@ void main() {
406412
'xcrun',
407413
const <String>[
408414
'xcodebuild',
415+
'clean',
409416
'analyze',
410417
'-workspace',
411418
'macos/Runner.xcworkspace',
@@ -445,6 +452,7 @@ void main() {
445452
'xcrun',
446453
const <String>[
447454
'xcodebuild',
455+
'clean',
448456
'analyze',
449457
'-workspace',
450458
'ios/Runner.xcworkspace',

0 commit comments

Comments
 (0)