Skip to content

Commit 1292dc3

Browse files
authored
Add CI steps to test iOS and macOS plugins with both CocoaPods and Swift Package Manager (#6557)
Tests new Swift Package Manager feature added in flutter/flutter#146256. Fixes flutter/flutter#146901.
1 parent 2925db2 commit 1292dc3

File tree

4 files changed

+198
-2
lines changed

4 files changed

+198
-2
lines changed

.ci/targets/ios_platform_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tasks:
1111
infra_step: true
1212
- name: build examples
1313
script: .ci/scripts/tool_runner.sh
14-
args: ["build-examples", "--ios"]
14+
args: ["build-examples", "--ios", "--swift-package-manager"]
1515
- name: xcode analyze
1616
script: .ci/scripts/tool_runner.sh
1717
args: ["xcode-analyze", "--ios"]

.ci/targets/macos_platform_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tasks:
88
infra_step: true
99
- name: build examples
1010
script: .ci/scripts/tool_runner.sh
11-
args: ["build-examples", "--macos"]
11+
args: ["build-examples", "--macos", "--swift-package-manager"]
1212
- name: xcode analyze
1313
script: .ci/scripts/tool_runner.sh
1414
args: ["xcode-analyze", "--macos"]

script/tool/lib/src/build_examples_command.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const String _flutterBuildTypeWindows = 'windows';
3838

3939
const String _flutterBuildTypeAndroidAlias = 'android';
4040

41+
/// Key for Swift Package Manager.
42+
const String _swiftPackageManagerFlag = 'swift-package-manager';
43+
4144
/// A command to build the example applications for packages.
4245
class BuildExamplesCommand extends PackageLoopingCommand {
4346
/// Creates an instance of the build command.
@@ -58,6 +61,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
5861
defaultsTo: '',
5962
help: 'Enables the given Dart SDK experiments.',
6063
);
64+
argParser.addFlag(_swiftPackageManagerFlag);
6165
}
6266

6367
// Maps the switch this command uses to identify a platform to information
@@ -111,6 +115,15 @@ class BuildExamplesCommand extends PackageLoopingCommand {
111115
'single key "$_pluginToolsConfigGlobalKey" containing a list of build '
112116
'arguments.';
113117

118+
/// Returns true if `--swift-package-manager` flag was passed along with
119+
/// either `--ios` or `--macos`.
120+
bool get usingSwiftPackageManager {
121+
final List<String> platformFlags = _platforms.keys.toList();
122+
return getBoolArg(_swiftPackageManagerFlag) &&
123+
(platformFlags.contains(platformIOS) ||
124+
platformFlags.contains(platformMacOS));
125+
}
126+
114127
@override
115128
Future<void> initializeRun() async {
116129
final List<String> platformFlags = _platforms.keys.toList();
@@ -121,6 +134,17 @@ class BuildExamplesCommand extends PackageLoopingCommand {
121134
'were specified. At least one platform must be provided.');
122135
throw ToolExit(_exitNoPlatformFlags);
123136
}
137+
138+
// TODO(vashworth): Enable on stable once Swift Package Manager feature is
139+
// available on stable.
140+
if (usingSwiftPackageManager &&
141+
platform.environment['CHANNEL'] != 'stable') {
142+
await processRunner.runAndStream(
143+
flutterCommand,
144+
<String>['config', '--enable-swift-package-manager'],
145+
exitOnError: true,
146+
);
147+
}
124148
}
125149

126150
@override

script/tool/test/build_examples_command_test.dart

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,98 @@ void main() {
164164
]));
165165
});
166166

167+
test('building for iOS with Swift Package Manager on master channel',
168+
() async {
169+
mockPlatform.isMacOS = true;
170+
mockPlatform.environment['CHANNEL'] = 'master';
171+
172+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
173+
platformSupport: <String, PlatformDetails>{
174+
platformIOS: const PlatformDetails(PlatformSupport.inline),
175+
});
176+
177+
final Directory pluginExampleDirectory = getExampleDir(plugin);
178+
179+
final List<String> output = await runCapturingPrint(runner, <String>[
180+
'build-examples',
181+
'--ios',
182+
'--enable-experiment=exp1',
183+
'--swift-package-manager',
184+
]);
185+
186+
expect(
187+
output,
188+
containsAllInOrder(<String>[
189+
'\nBUILDING plugin/example for iOS',
190+
]),
191+
);
192+
193+
expect(
194+
processRunner.recordedCalls,
195+
orderedEquals(<ProcessCall>[
196+
ProcessCall(
197+
getFlutterCommand(mockPlatform),
198+
const <String>['config', '--enable-swift-package-manager'],
199+
null,
200+
),
201+
ProcessCall(
202+
getFlutterCommand(mockPlatform),
203+
const <String>[
204+
'build',
205+
'ios',
206+
'--no-codesign',
207+
'--enable-experiment=exp1'
208+
],
209+
pluginExampleDirectory.path,
210+
),
211+
]),
212+
);
213+
});
214+
215+
test(
216+
'building for iOS with Swift Package Manager on stable channel does not enable SPM',
217+
() async {
218+
mockPlatform.isMacOS = true;
219+
mockPlatform.environment['CHANNEL'] = 'stable';
220+
221+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
222+
platformSupport: <String, PlatformDetails>{
223+
platformIOS: const PlatformDetails(PlatformSupport.inline),
224+
});
225+
226+
final Directory pluginExampleDirectory = getExampleDir(plugin);
227+
228+
final List<String> output = await runCapturingPrint(runner, <String>[
229+
'build-examples',
230+
'--ios',
231+
'--enable-experiment=exp1',
232+
'--swift-package-manager',
233+
]);
234+
235+
expect(
236+
output,
237+
containsAllInOrder(<String>[
238+
'\nBUILDING plugin/example for iOS',
239+
]),
240+
);
241+
242+
expect(
243+
processRunner.recordedCalls,
244+
orderedEquals(<ProcessCall>[
245+
ProcessCall(
246+
getFlutterCommand(mockPlatform),
247+
const <String>[
248+
'build',
249+
'ios',
250+
'--no-codesign',
251+
'--enable-experiment=exp1'
252+
],
253+
pluginExampleDirectory.path,
254+
),
255+
]),
256+
);
257+
});
258+
167259
test(
168260
'building for Linux when plugin is not set up for Linux results in no-op',
169261
() async {
@@ -261,6 +353,86 @@ void main() {
261353
]));
262354
});
263355

356+
test('building for macOS with Swift Package Manager on master channel',
357+
() async {
358+
mockPlatform.isMacOS = true;
359+
mockPlatform.environment['CHANNEL'] = 'master';
360+
361+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
362+
platformSupport: <String, PlatformDetails>{
363+
platformMacOS: const PlatformDetails(PlatformSupport.inline),
364+
});
365+
366+
final Directory pluginExampleDirectory = getExampleDir(plugin);
367+
368+
final List<String> output = await runCapturingPrint(runner,
369+
<String>['build-examples', '--macos', '--swift-package-manager']);
370+
371+
expect(
372+
output,
373+
containsAllInOrder(<String>[
374+
'\nBUILDING plugin/example for macOS',
375+
]),
376+
);
377+
378+
expect(
379+
processRunner.recordedCalls,
380+
orderedEquals(<ProcessCall>[
381+
ProcessCall(
382+
getFlutterCommand(mockPlatform),
383+
const <String>['config', '--enable-swift-package-manager'],
384+
null,
385+
),
386+
ProcessCall(
387+
getFlutterCommand(mockPlatform),
388+
const <String>[
389+
'build',
390+
'macos',
391+
],
392+
pluginExampleDirectory.path,
393+
),
394+
]),
395+
);
396+
});
397+
398+
test(
399+
'building for macOS with Swift Package Manager on stable channel does not enable SPM',
400+
() async {
401+
mockPlatform.isMacOS = true;
402+
mockPlatform.environment['CHANNEL'] = 'stable';
403+
404+
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
405+
platformSupport: <String, PlatformDetails>{
406+
platformMacOS: const PlatformDetails(PlatformSupport.inline),
407+
});
408+
409+
final Directory pluginExampleDirectory = getExampleDir(plugin);
410+
411+
final List<String> output = await runCapturingPrint(runner,
412+
<String>['build-examples', '--macos', '--swift-package-manager']);
413+
414+
expect(
415+
output,
416+
containsAllInOrder(<String>[
417+
'\nBUILDING plugin/example for macOS',
418+
]),
419+
);
420+
421+
expect(
422+
processRunner.recordedCalls,
423+
orderedEquals(<ProcessCall>[
424+
ProcessCall(
425+
getFlutterCommand(mockPlatform),
426+
const <String>[
427+
'build',
428+
'macos',
429+
],
430+
pluginExampleDirectory.path,
431+
),
432+
]),
433+
);
434+
});
435+
264436
test('building for web with no implementation results in no-op', () async {
265437
createFakePlugin('plugin', packagesDir);
266438

0 commit comments

Comments
 (0)