mirror of
https://github.com/flutter/packages.git
synced 2025-06-03 09:41:19 +08:00
[flutter_plugin_tools] Allow disabling Swift Package Manager when building examples (#7145)
You can use the Flutter plugin tool to [build the plugins' examples apps](https://github.com/flutter/packages/tree/main/script/tool#run-dart-integration-tests). Currently, the tool can enable the Swift Package Manager feature. This change allows the tool to disable the Swift Package Manager feature. This will be useful for when SPM is enabled by default on a release channel. Preparation for: https://github.com/flutter/flutter/issues/151567
This commit is contained in:
@ -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
|
||||
@ -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
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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?) ?? '';
|
||||
|
@ -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;
|
||||
@ -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 {
|
||||
@ -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;
|
||||
@ -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 {
|
||||
|
Reference in New Issue
Block a user