Skip to content

[tool] Add --xcode-warnings-exceptions flag #8524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .ci/targets/ios_platform_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ tasks:
args: ["build-examples", "--ios", "--swift-package-manager"]
- name: xcode analyze
script: .ci/scripts/tool_runner.sh
args: ["xcode-analyze", "--ios"]
args: ["xcode-analyze", "--ios", "--exclude=script/configs/xcode_warnings_exceptions.yaml"]
- name: xcode analyze deprecation
# Ensure we don't accidentally introduce deprecated code.
script: .ci/scripts/tool_runner.sh
args: ["xcode-analyze", "--ios", "--ios-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml"]
args: ["xcode-analyze", "--ios", "--ios-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml,script/configs/xcode_warnings_exceptions.yaml"]
- name: native test
script: .ci/scripts/tool_runner.sh
# Simulator name and version must match name and version in create_simulator.sh
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=17.0"]
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=17.0", "--xcode-warnings-exceptions=script/configs/xcode_warnings_exceptions.yaml"]
- name: boot simulator
# Ensure simulator is still booted
script: .ci/scripts/boot_simulator.sh
Expand Down
6 changes: 3 additions & 3 deletions .ci/targets/macos_platform_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ tasks:
args: ["build-examples", "--macos", "--swift-package-manager"]
- name: xcode analyze
script: .ci/scripts/tool_runner.sh
args: ["xcode-analyze", "--macos"]
args: ["xcode-analyze", "--macos", "--exclude=script/configs/xcode_warnings_exceptions.yaml"]
- name: xcode analyze deprecation
# Ensure we don't accidentally introduce deprecated code.
script: .ci/scripts/tool_runner.sh
args: ["xcode-analyze", "--macos", "--macos-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml"]
args: ["xcode-analyze", "--macos", "--macos-min-version=14.0", "--exclude=script/configs/exclude_xcode_deprecation.yaml,script/configs/xcode_warnings_exceptions.yaml"]
- name: native test
script: .ci/scripts/tool_runner.sh
args: ["native-test", "--macos"]
args: ["native-test", "--macos", "--xcode-warnings-exceptions=script/configs/xcode_warnings_exceptions.yaml"]
- name: drive examples
script: .ci/scripts/tool_runner.sh
args: ["drive-examples", "--macos", "--exclude=script/configs/exclude_integration_macos.yaml"]
5 changes: 5 additions & 0 deletions script/configs/xcode_warnings_exceptions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The list of plugins that are known to produce Xcode warnings.
# These should be excluded from Xcode analysis and "treat warnings as errors"
# should be disabled when running their native tests.
#
# All entries here should have an explanation for why they are here.
17 changes: 16 additions & 1 deletion script/tool/lib/src/native_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const String _integrationTestFlag = 'integration';

const String _iOSDestinationFlag = 'ios-destination';

const String _xcodeWarningsExceptionsFlag = 'xcode-warnings-exceptions';

const int _exitNoIOSSimulators = 3;

/// The error message logged when a FlutterTestRunner test is not annotated with
Expand Down Expand Up @@ -65,6 +67,14 @@ class NativeTestCommand extends PackageLoopingCommand {
help: 'Runs native unit tests', defaultsTo: true);
argParser.addFlag(_integrationTestFlag,
help: 'Runs native integration (UI) tests', defaultsTo: true);

argParser.addMultiOption(
_xcodeWarningsExceptionsFlag,
help: 'A list of packages that are allowed to have Xcode warnings.\n\n'
'Alternately, a list of one or more YAML files that contain a list '
'of packages to allow Xcode warnings.',
defaultsTo: <String>[],
);
}

// The ABI of the host.
Expand Down Expand Up @@ -100,6 +110,8 @@ this command.

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

Set<String> _xcodeWarningsExceptions = <String>{};

@override
Future<void> initializeRun() async {
_platforms = <String, _PlatformDetails>{
Expand Down Expand Up @@ -151,6 +163,8 @@ this command.
destination,
];
}

_xcodeWarningsExceptions = getYamlListArg(_xcodeWarningsExceptionsFlag);
}

@override
Expand Down Expand Up @@ -487,7 +501,8 @@ this command.
extraFlags: <String>[
if (testTarget != null) '-only-testing:$testTarget',
...extraFlags,
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
if (!_xcodeWarningsExceptions.contains(plugin.directory.basename))
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
],
);

Expand Down
99 changes: 97 additions & 2 deletions script/tool/test/native_test_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const String _androidIntegrationTestFilter =
'-Pandroid.testInstrumentationRunnerArguments.'
'notAnnotation=io.flutter.plugins.DartIntegrationTest';

const String _simulatorDeviceId = '1E76A0FD-38AC-4537-A989-EA639D7D012A';

final Map<String, dynamic> _kDeviceListMap = <String, dynamic>{
'runtimes': <Map<String, dynamic>>[
<String, dynamic>{
Expand Down Expand Up @@ -137,6 +139,7 @@ void main() {
String platform, {
String? destination,
List<String> extraFlags = const <String>[],
bool treatWarningsAsErrors = true,
}) {
return ProcessCall(
'xcrun',
Expand All @@ -152,7 +155,7 @@ void main() {
'Debug',
if (destination != null) ...<String>['-destination', destination],
...extraFlags,
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
if (treatWarningsAsErrors) 'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
],
package.path);
}
Expand Down Expand Up @@ -349,7 +352,7 @@ void main() {
null),
getTargetCheckCall(pluginExampleDirectory, 'ios'),
getRunTestCall(pluginExampleDirectory, 'ios',
destination: 'id=1E76A0FD-38AC-4537-A989-EA639D7D012A'),
destination: 'id=$_simulatorDeviceId'),
]));
});
});
Expand Down Expand Up @@ -1450,6 +1453,98 @@ public class FlutterActivityTest {
getTargetCheckCall(pluginExampleDirectory, 'macos'),
]));
});

test('Xcode warnings exceptions list', () async {
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
platformIOS: const PlatformDetails(PlatformSupport.inline)
});

final Directory pluginExampleDirectory = getExampleDir(plugin);

processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(stdout: jsonEncode(_kDeviceListMap)),
<String>['simctl', 'list']),
getMockXcodebuildListProcess(
<String>['RunnerTests', 'RunnerUITests']),
];

await runCapturingPrint(runner, <String>[
'native-test',
'--ios',
'--xcode-warnings-exceptions=plugin'
]);

expect(
processRunner.recordedCalls,
contains(
getRunTestCall(pluginExampleDirectory, 'ios',
destination: 'id=$_simulatorDeviceId',
treatWarningsAsErrors: false),
));
});

test('Xcode warnings exceptions file', () async {
final File configFile = packagesDir.childFile('exceptions.yaml');
await configFile.writeAsString('- plugin');
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
platformIOS: const PlatformDetails(PlatformSupport.inline)
});

final Directory pluginExampleDirectory = getExampleDir(plugin);

processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(stdout: jsonEncode(_kDeviceListMap)),
<String>['simctl', 'list']),
getMockXcodebuildListProcess(
<String>['RunnerTests', 'RunnerUITests']),
];

await runCapturingPrint(runner, <String>[
'native-test',
'--ios',
'--xcode-warnings-exceptions=${configFile.path}'
]);

expect(
processRunner.recordedCalls,
contains(
getRunTestCall(pluginExampleDirectory, 'ios',
destination: 'id=$_simulatorDeviceId',
treatWarningsAsErrors: false),
));
});

test('treat warnings as errors if plugin not on exceptions list',
() async {
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
platformIOS: const PlatformDetails(PlatformSupport.inline)
});

final Directory pluginExampleDirectory = getExampleDir(plugin);

processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(stdout: jsonEncode(_kDeviceListMap)),
<String>['simctl', 'list']),
getMockXcodebuildListProcess(
<String>['RunnerTests', 'RunnerUITests']),
];

await runCapturingPrint(runner, <String>[
'native-test',
'--ios',
'--xcode-warnings-exceptions=foo,bar'
]);

expect(
processRunner.recordedCalls,
contains(
getRunTestCall(pluginExampleDirectory, 'ios',
destination: 'id=$_simulatorDeviceId'),
));
});
});

group('multiplatform', () {
Expand Down