Skip to content

Commit 45c1997

Browse files
authored
[tool] Add --xcode-warnings-exceptions flag (#8524)
Today, we treat Xcode warnings as errors on all iOS and macOS plugins. However, the google_sign_in_ios plugin has dependencies with warnings. We're unable to suppress these warnings when using Swift Package Manager. As a workaround, we'll need to disable Xcode warnings for the google_sign_in_ios plugin. This will be done in a subsequent pull request (see #7356). This change introduces `--xcode-warnings-exceptions` to the `native-test` command. When running Xcode test, `GCC_TREAT_WARNINGS_AS_ERRORS` will be provided only if the plugin isn't on the exception list. Additionally, plugins that are the exception list are excluded from the `xcode-analyze` command. Part of flutter/flutter#146904
1 parent bc8c522 commit 45c1997

File tree

5 files changed

+124
-9
lines changed

5 files changed

+124
-9
lines changed

.ci/targets/ios_platform_tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ tasks:
1414
args: ["build-examples", "--ios", "--swift-package-manager"]
1515
- name: xcode analyze
1616
script: .ci/scripts/tool_runner.sh
17-
args: ["xcode-analyze", "--ios"]
17+
args: ["xcode-analyze", "--ios", "--exclude=script/configs/xcode_warnings_exceptions.yaml"]
1818
- name: xcode analyze deprecation
1919
# Ensure we don't accidentally introduce deprecated code.
2020
script: .ci/scripts/tool_runner.sh
21-
args: ["xcode-analyze", "--ios", "--ios-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml"]
21+
args: ["xcode-analyze", "--ios", "--ios-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml,script/configs/xcode_warnings_exceptions.yaml"]
2222
- name: native test
2323
script: .ci/scripts/tool_runner.sh
2424
# Simulator name and version must match name and version in create_simulator.sh
25-
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=17.0"]
25+
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=17.0", "--xcode-warnings-exceptions=script/configs/xcode_warnings_exceptions.yaml"]
2626
- name: boot simulator
2727
# Ensure simulator is still booted
2828
script: .ci/scripts/boot_simulator.sh

.ci/targets/macos_platform_tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ tasks:
1111
args: ["build-examples", "--macos", "--swift-package-manager"]
1212
- name: xcode analyze
1313
script: .ci/scripts/tool_runner.sh
14-
args: ["xcode-analyze", "--macos"]
14+
args: ["xcode-analyze", "--macos", "--exclude=script/configs/xcode_warnings_exceptions.yaml"]
1515
- name: xcode analyze deprecation
1616
# Ensure we don't accidentally introduce deprecated code.
1717
script: .ci/scripts/tool_runner.sh
18-
args: ["xcode-analyze", "--macos", "--macos-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml"]
18+
args: ["xcode-analyze", "--macos", "--macos-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml,script/configs/xcode_warnings_exceptions.yaml"]
1919
- name: native test
2020
script: .ci/scripts/tool_runner.sh
21-
args: ["native-test", "--macos"]
21+
args: ["native-test", "--macos", "--xcode-warnings-exceptions=script/configs/xcode_warnings_exceptions.yaml"]
2222
- name: drive examples
2323
script: .ci/scripts/tool_runner.sh
2424
args: ["drive-examples", "--macos", "--exclude=script/configs/exclude_integration_macos.yaml"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The list of plugins that are known to produce Xcode warnings.
2+
# These should be excluded from Xcode analysis and "treat warnings as errors"
3+
# should be disabled when running their native tests.
4+
#
5+
# All entries here should have an explanation for why they are here.

script/tool/lib/src/native_test_command.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const String _integrationTestFlag = 'integration';
2121

2222
const String _iOSDestinationFlag = 'ios-destination';
2323

24+
const String _xcodeWarningsExceptionsFlag = 'xcode-warnings-exceptions';
25+
2426
const int _exitNoIOSSimulators = 3;
2527

2628
/// The error message logged when a FlutterTestRunner test is not annotated with
@@ -65,6 +67,14 @@ class NativeTestCommand extends PackageLoopingCommand {
6567
help: 'Runs native unit tests', defaultsTo: true);
6668
argParser.addFlag(_integrationTestFlag,
6769
help: 'Runs native integration (UI) tests', defaultsTo: true);
70+
71+
argParser.addMultiOption(
72+
_xcodeWarningsExceptionsFlag,
73+
help: 'A list of packages that are allowed to have Xcode warnings.\n\n'
74+
'Alternately, a list of one or more YAML files that contain a list '
75+
'of packages to allow Xcode warnings.',
76+
defaultsTo: <String>[],
77+
);
6878
}
6979

7080
// The ABI of the host.
@@ -100,6 +110,8 @@ this command.
100110

101111
List<String> _requestedPlatforms = <String>[];
102112

113+
Set<String> _xcodeWarningsExceptions = <String>{};
114+
103115
@override
104116
Future<void> initializeRun() async {
105117
_platforms = <String, _PlatformDetails>{
@@ -151,6 +163,8 @@ this command.
151163
destination,
152164
];
153165
}
166+
167+
_xcodeWarningsExceptions = getYamlListArg(_xcodeWarningsExceptionsFlag);
154168
}
155169

156170
@override
@@ -487,7 +501,8 @@ this command.
487501
extraFlags: <String>[
488502
if (testTarget != null) '-only-testing:$testTarget',
489503
...extraFlags,
490-
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
504+
if (!_xcodeWarningsExceptions.contains(plugin.directory.basename))
505+
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
491506
],
492507
);
493508

script/tool/test/native_test_command_test.dart

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const String _androidIntegrationTestFilter =
2727
'-Pandroid.testInstrumentationRunnerArguments.'
2828
'notAnnotation=io.flutter.plugins.DartIntegrationTest';
2929

30+
const String _simulatorDeviceId = '1E76A0FD-38AC-4537-A989-EA639D7D012A';
31+
3032
final Map<String, dynamic> _kDeviceListMap = <String, dynamic>{
3133
'runtimes': <Map<String, dynamic>>[
3234
<String, dynamic>{
@@ -137,6 +139,7 @@ void main() {
137139
String platform, {
138140
String? destination,
139141
List<String> extraFlags = const <String>[],
142+
bool treatWarningsAsErrors = true,
140143
}) {
141144
return ProcessCall(
142145
'xcrun',
@@ -152,7 +155,7 @@ void main() {
152155
'Debug',
153156
if (destination != null) ...<String>['-destination', destination],
154157
...extraFlags,
155-
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
158+
if (treatWarningsAsErrors) 'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
156159
],
157160
package.path);
158161
}
@@ -349,7 +352,7 @@ void main() {
349352
null),
350353
getTargetCheckCall(pluginExampleDirectory, 'ios'),
351354
getRunTestCall(pluginExampleDirectory, 'ios',
352-
destination: 'id=1E76A0FD-38AC-4537-A989-EA639D7D012A'),
355+
destination: 'id=$_simulatorDeviceId'),
353356
]));
354357
});
355358
});
@@ -1450,6 +1453,98 @@ public class FlutterActivityTest {
14501453
getTargetCheckCall(pluginExampleDirectory, 'macos'),
14511454
]));
14521455
});
1456+
1457+
test('Xcode warnings exceptions list', () async {
1458+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
1459+
platformSupport: <String, PlatformDetails>{
1460+
platformIOS: const PlatformDetails(PlatformSupport.inline)
1461+
});
1462+
1463+
final Directory pluginExampleDirectory = getExampleDir(plugin);
1464+
1465+
processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
1466+
FakeProcessInfo(MockProcess(stdout: jsonEncode(_kDeviceListMap)),
1467+
<String>['simctl', 'list']),
1468+
getMockXcodebuildListProcess(
1469+
<String>['RunnerTests', 'RunnerUITests']),
1470+
];
1471+
1472+
await runCapturingPrint(runner, <String>[
1473+
'native-test',
1474+
'--ios',
1475+
'--xcode-warnings-exceptions=plugin'
1476+
]);
1477+
1478+
expect(
1479+
processRunner.recordedCalls,
1480+
contains(
1481+
getRunTestCall(pluginExampleDirectory, 'ios',
1482+
destination: 'id=$_simulatorDeviceId',
1483+
treatWarningsAsErrors: false),
1484+
));
1485+
});
1486+
1487+
test('Xcode warnings exceptions file', () async {
1488+
final File configFile = packagesDir.childFile('exceptions.yaml');
1489+
await configFile.writeAsString('- plugin');
1490+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
1491+
platformSupport: <String, PlatformDetails>{
1492+
platformIOS: const PlatformDetails(PlatformSupport.inline)
1493+
});
1494+
1495+
final Directory pluginExampleDirectory = getExampleDir(plugin);
1496+
1497+
processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
1498+
FakeProcessInfo(MockProcess(stdout: jsonEncode(_kDeviceListMap)),
1499+
<String>['simctl', 'list']),
1500+
getMockXcodebuildListProcess(
1501+
<String>['RunnerTests', 'RunnerUITests']),
1502+
];
1503+
1504+
await runCapturingPrint(runner, <String>[
1505+
'native-test',
1506+
'--ios',
1507+
'--xcode-warnings-exceptions=${configFile.path}'
1508+
]);
1509+
1510+
expect(
1511+
processRunner.recordedCalls,
1512+
contains(
1513+
getRunTestCall(pluginExampleDirectory, 'ios',
1514+
destination: 'id=$_simulatorDeviceId',
1515+
treatWarningsAsErrors: false),
1516+
));
1517+
});
1518+
1519+
test('treat warnings as errors if plugin not on exceptions list',
1520+
() async {
1521+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
1522+
platformSupport: <String, PlatformDetails>{
1523+
platformIOS: const PlatformDetails(PlatformSupport.inline)
1524+
});
1525+
1526+
final Directory pluginExampleDirectory = getExampleDir(plugin);
1527+
1528+
processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
1529+
FakeProcessInfo(MockProcess(stdout: jsonEncode(_kDeviceListMap)),
1530+
<String>['simctl', 'list']),
1531+
getMockXcodebuildListProcess(
1532+
<String>['RunnerTests', 'RunnerUITests']),
1533+
];
1534+
1535+
await runCapturingPrint(runner, <String>[
1536+
'native-test',
1537+
'--ios',
1538+
'--xcode-warnings-exceptions=foo,bar'
1539+
]);
1540+
1541+
expect(
1542+
processRunner.recordedCalls,
1543+
contains(
1544+
getRunTestCall(pluginExampleDirectory, 'ios',
1545+
destination: 'id=$_simulatorDeviceId'),
1546+
));
1547+
});
14531548
});
14541549

14551550
group('multiplatform', () {

0 commit comments

Comments
 (0)