Skip to content
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
47 changes: 31 additions & 16 deletions script/tool/lib/src/build_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
defaultsTo: '',
help: 'Enables the given Dart SDK experiments.',
);
argParser.addFlag(_swiftPackageManagerFlag);
argParser.addFlag(_swiftPackageManagerFlag, defaultsTo: null);
}

// Maps the switch this command uses to identify a platform to information
Expand Down Expand Up @@ -115,13 +115,22 @@ class BuildExamplesCommand extends PackageLoopingCommand {
'single key "$_pluginToolsConfigGlobalKey" containing a list of build '
'arguments.';

/// Returns true if `--swift-package-manager` flag was passed along with
/// either `--ios` or `--macos`.
bool get usingSwiftPackageManager {
/// Returns whether the Swift Package Manager feature should be enabled,
/// disabled, or left to the release channel's default value.
bool? get _swiftPackageManagerFeatureConfig {
final List<String> platformFlags = _platforms.keys.toList();
return getBoolArg(_swiftPackageManagerFlag) &&
(platformFlags.contains(platformIOS) ||
platformFlags.contains(platformMacOS));
if (!platformFlags.contains(platformIOS) &&
!platformFlags.contains(platformMacOS)) {
return null;
}

// TODO(loic-sharma): Allow enabling on stable once Swift Package Manager
// feature is available on stable.
if (platform.environment['CHANNEL'] != 'master') {
return null;
}

return getNullableBoolArg(_swiftPackageManagerFlag);
}

@override
Expand All @@ -135,15 +144,21 @@ class BuildExamplesCommand extends PackageLoopingCommand {
throw ToolExit(_exitNoPlatformFlags);
}

// TODO(vashworth): Enable on stable once Swift Package Manager feature is
// available on stable.
if (usingSwiftPackageManager &&
platform.environment['CHANNEL'] != 'stable') {
await processRunner.runAndStream(
flutterCommand,
<String>['config', '--enable-swift-package-manager'],
exitOnError: true,
);
switch (_swiftPackageManagerFeatureConfig) {
case true:
await processRunner.runAndStream(
flutterCommand,
<String>['config', '--enable-swift-package-manager'],
exitOnError: true,
);
case false:
await processRunner.runAndStream(
flutterCommand,
<String>['config', '--no-enable-swift-package-manager'],
exitOnError: true,
);
case null:
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions script/tool/lib/src/common/package_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ abstract class PackageCommand extends Command<void> {
return (argResults![key] as bool?) ?? false;
}

/// Convenience accessor for boolean arguments.
bool? getNullableBoolArg(String key) {
return argResults![key] as bool?;
}

/// Convenience accessor for String arguments.
String getStringArg(String key) {
return (argResults![key] as String?) ?? '';
Expand Down
171 changes: 171 additions & 0 deletions script/tool/test/build_examples_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,53 @@ void main() {
]));
});

test('building for iOS with CocoaPods on master channel', () async {
mockPlatform.isMacOS = true;
mockPlatform.environment['CHANNEL'] = 'master';

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

final Directory pluginExampleDirectory = getExampleDir(plugin);

final List<String> output = await runCapturingPrint(runner, <String>[
'build-examples',
'--ios',
'--enable-experiment=exp1',
'--no-swift-package-manager',
]);

expect(
output,
containsAllInOrder(<String>[
'\nBUILDING plugin/example for iOS',
]),
);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>['config', '--no-enable-swift-package-manager'],
null,
),
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>[
'build',
'ios',
'--no-codesign',
'--enable-experiment=exp1'
],
pluginExampleDirectory.path,
),
]),
);
});

test('building for iOS with Swift Package Manager on master channel',
() async {
mockPlatform.isMacOS = true;
Expand Down Expand Up @@ -212,6 +259,50 @@ void main() {
);
});

test(
'building for iOS with CocoaPods on stable channel does not disable SPM',
() async {
mockPlatform.isMacOS = true;
mockPlatform.environment['CHANNEL'] = 'stable';

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

final Directory pluginExampleDirectory = getExampleDir(plugin);

final List<String> output = await runCapturingPrint(runner, <String>[
'build-examples',
'--ios',
'--enable-experiment=exp1',
'--no-swift-package-manager',
]);

expect(
output,
containsAllInOrder(<String>[
'\nBUILDING plugin/example for iOS',
]),
);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>[
'build',
'ios',
'--no-codesign',
'--enable-experiment=exp1'
],
pluginExampleDirectory.path,
),
]),
);
});

test(
'building for iOS with Swift Package Manager on stable channel does not enable SPM',
() async {
Expand Down Expand Up @@ -353,6 +444,48 @@ void main() {
]));
});

test('building for macOS with CocoaPods on master channel', () async {
mockPlatform.isMacOS = true;
mockPlatform.environment['CHANNEL'] = 'master';

final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
platformMacOS: const PlatformDetails(PlatformSupport.inline),
});

final Directory pluginExampleDirectory = getExampleDir(plugin);

final List<String> output = await runCapturingPrint(runner,
<String>['build-examples', '--macos', '--no-swift-package-manager']);

expect(
output,
containsAllInOrder(<String>[
'\nBUILDING plugin/example for macOS',
]),
);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>['config', '--no-enable-swift-package-manager'],
null,
),
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>[
'build',
'macos',
],
pluginExampleDirectory.path,
),
]),
);
});


test('building for macOS with Swift Package Manager on master channel',
() async {
mockPlatform.isMacOS = true;
Expand Down Expand Up @@ -395,6 +528,44 @@ void main() {
);
});

test(
'building for macOS with CocoaPods on stable channel does not disable SPM',
() async {
mockPlatform.isMacOS = true;
mockPlatform.environment['CHANNEL'] = 'stable';

final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
platformSupport: <String, PlatformDetails>{
platformMacOS: const PlatformDetails(PlatformSupport.inline),
});

final Directory pluginExampleDirectory = getExampleDir(plugin);

final List<String> output = await runCapturingPrint(runner,
<String>['build-examples', '--macos', '--no-swift-package-manager']);

expect(
output,
containsAllInOrder(<String>[
'\nBUILDING plugin/example for macOS',
]),
);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>[
'build',
'macos',
],
pluginExampleDirectory.path,
),
]),
);
});

test(
'building for macOS with Swift Package Manager on stable channel does not enable SPM',
() async {
Expand Down