Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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", "--xcode-warnings-exceptions=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", "--xcode-warnings-exceptions=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
4 changes: 2 additions & 2 deletions .ci/targets/macos_platform_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ 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", "--xcode-warnings-exceptions=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", "--xcode-warnings-exceptions=script/configs/xcode_warnings_exceptions.yaml"]
- name: native test
script: .ci/scripts/tool_runner.sh
args: ["native-test", "--macos"]
Expand Down
3 changes: 3 additions & 0 deletions script/configs/xcode_warnings_exceptions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The list of plugins that are allowed to have Xcode warnings.
#
# 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
15 changes: 14 additions & 1 deletion script/tool/lib/src/xcode_analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
'Sets the minimum macOS deployment version to use when compiling, '
'overriding the default minimum version. This can be used to find '
'deprecation warnings that will affect the plugin in the future.');
argParser.addMultiOption(
_xcodeWarningsExceptionsArg,
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>[],
);
}

static const String _minIOSVersionArg = 'ios-min-version';
static const String _minMacOSVersionArg = 'macos-min-version';
static const String _xcodeWarningsExceptionsArg = 'xcode-warnings-exceptions';

final Xcode _xcode;

Expand All @@ -45,12 +53,16 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
final String description =
'Runs Xcode analysis on the iOS and/or macOS example apps.';

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

@override
Future<void> initializeRun() async {
if (!(getBoolArg(platformIOS) || getBoolArg(platformMacOS))) {
printError('At least one platform flag must be provided.');
throw ToolExit(exitInvalidArguments);
}

_xcodeWarningsExceptions = getYamlListArg(_xcodeWarningsExceptionsArg);
}

@override
Expand Down Expand Up @@ -121,7 +133,8 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
hostPlatform: platform,
extraFlags: <String>[
...extraFlags,
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
if (!_xcodeWarningsExceptions.contains(plugin.directory.basename))
'GCC_TREAT_WARNINGS_AS_ERRORS=YES',
],
);
if (exitCode == 0) {
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
Loading