[tool] Update Swift Package Manager handling (#11234)

Updates the repo tooling for Swift Package manager being on by default on main, and for analysis now working with Swift Package Manager:
- Explicitly disables SwiftPM for the build-all test, instead of relying on it being off by default
- No longer disable SwiftPM for example apps before running analysis, since it's no longer necessary to do so, and we don't want to rely on CocoaPods for core tests going forward.

Fixes https://github.com/flutter/flutter/issues/183521
Fixes https://github.com/flutter/flutter/issues/172427
This commit is contained in:
stuartmorgan-g
2026-03-12 13:20:02 -04:00
committed by GitHub
parent 02f231f376
commit 86543faf4d
7 changed files with 54 additions and 52 deletions

View File

@@ -10,10 +10,11 @@ exclusions=("script/configs/exclude_all_packages_app.yaml")
# Add a wasm-specific exclusion file if "--wasm" is specified.
if [[ "$1" == "--wasm" ]]; then
exclusions+=",script/configs/exclude_all_packages_app_wasm.yaml"
shift 1
fi
# Delete ./all_packages if it exists already
rm -rf ./all_packages
dart ./script/tool/bin/flutter_plugin_tools.dart create-all-packages-app \
--output-dir=. --exclude "$exclusions"
--output-dir=. --exclude "$exclusions" "$@"

View File

@@ -8,6 +8,9 @@ tasks:
infra_step: true
- name: create all_packages app
script: .ci/scripts/create_all_packages_app.sh
# build-examples builds with Swift Package Manager, so run build-all without
# it to test both modes in CI.
args: ["--no-swift-package-manager"]
infra_step: true # Note infra steps failing prevents "always" from running.
- name: build all_packages for iOS debug
script: .ci/scripts/build_all_packages_app.sh

View File

@@ -8,6 +8,9 @@ tasks:
infra_step: true
- name: create all_packages app
script: .ci/scripts/create_all_packages_app.sh
# build-examples builds with Swift Package Manager, so run build-all without
# it to test both modes in CI.
args: ["--no-swift-package-manager"]
infra_step: true # Note infra steps failing prevents "always" from running.
- name: build all_packages for macOS debug
script: .ci/scripts/build_all_packages_app.sh

View File

@@ -440,14 +440,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
final xcode = Xcode(processRunner: processRunner, log: true);
final errors = <String>[];
for (final RepositoryPackage example in package.getExamples()) {
// See https://github.com/flutter/flutter/issues/172427 for discussion of
// why this is currently necessary.
print('Disabling Swift Package Manager...');
setSwiftPackageManagerState(example, enabled: false);
// Unconditionally re-run build with --debug --config-only, to ensure that
// the project is in a debug state even if it was previously configured,
// and that SwiftPM is disabled.
// the project is in a debug state even if it was previously configured.
print('Running flutter build --config-only...');
final bool buildSuccess = await runConfigOnlyBuild(
example,
@@ -490,9 +484,6 @@ class AnalyzeCommand extends PackageLoopingCommand {
'${getRelativePosixPath(example.directory, from: package.directory)} failed analysis.',
);
}
print('Removing Swift Package Manager override...');
setSwiftPackageManagerState(example, enabled: null);
}
return errors.isEmpty
? PackageResult.success()

View File

@@ -13,6 +13,7 @@ import 'common/core.dart';
import 'common/file_utils.dart';
import 'common/output_utils.dart';
import 'common/package_command.dart';
import 'common/plugin_utils.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/repository_package.dart';
@@ -52,10 +53,18 @@ class CreateAllPackagesAppCommand extends PackageCommand {
'The replacement will be done before any tool-driven '
'modifications.',
);
argParser.addFlag(
_swiftPackageManagerFlag,
defaultsTo: null,
help:
'Explicitly sets the app-level flag for Swift Package Manager in '
'pubspec.yaml.',
);
}
static const String _legacySourceFlag = 'legacy-source';
static const String _outputDirectoryFlag = 'output-dir';
static const String _swiftPackageManagerFlag = 'swift-package-manager';
/// The location to create the synthesized app project.
Directory get _appDirectory => packagesDir.fileSystem
@@ -121,6 +130,13 @@ class CreateAllPackagesAppCommand extends PackageCommand {
// flutter pub get above, so can't currently be run on Windows.
if (!platform.isWindows) _updateMacosPodfile(),
]);
final bool? swiftPackageManagerOverride = getNullableBoolArg(
_swiftPackageManagerFlag,
);
if (swiftPackageManagerOverride != null) {
setSwiftPackageManagerState(app, enabled: swiftPackageManagerOverride);
}
}
Future<int> _createApp() async {

View File

@@ -1093,47 +1093,6 @@ packages/package_a/lib/foo.dart
});
group('Xcode analyze', () {
test('temporarily disables Swift Package Manager', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformDetails>{
platformIOS: const PlatformDetails(PlatformSupport.inline),
},
);
final RepositoryPackage example = plugin.getExamples().first;
final String originalPubspecContents = example.pubspecFile
.readAsStringSync();
String? buildTimePubspecContents;
processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>[], () {
buildTimePubspecContents = example.pubspecFile.readAsStringSync();
}),
];
await runCapturingPrint(runner, <String>[
'analyze',
'--no-dart',
'--ios',
]);
// Ensure that SwiftPM was disabled for the package.
expect(
originalPubspecContents,
isNot(contains('enable-swift-package-manager: false')),
);
expect(
buildTimePubspecContents,
contains('enable-swift-package-manager: false'),
);
// And that it was undone after.
expect(
example.pubspecFile.readAsStringSync().trim(),
originalPubspecContents.trim(),
);
});
group('iOS', () {
test('skip if iOS is not supported', () async {
createFakePlugin(

View File

@@ -11,6 +11,7 @@ import 'package:flutter_plugin_tools/src/create_all_packages_app_command.dart';
import 'package:platform/platform.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
import 'mocks.dart';
import 'util.dart';
@@ -496,6 +497,34 @@ android {
);
});
test('disables Swift Package Manager if requested', () async {
writeFakeFlutterCreateOutput(testRoot);
createFakePlugin('plugina', packagesDir);
await runCapturingPrint(runner, <String>[
'create-all-packages-app',
'--no-swift-package-manager',
]);
final Pubspec pubspec = command.app.parsePubspec();
final flutterConfig = pubspec.flutter?['config'] as YamlMap?;
expect(flutterConfig?['enable-swift-package-manager'], false);
});
test('enables Swift Package Manager if requested', () async {
writeFakeFlutterCreateOutput(testRoot);
createFakePlugin('plugina', packagesDir);
await runCapturingPrint(runner, <String>[
'create-all-packages-app',
'--swift-package-manager',
]);
final Pubspec pubspec = command.app.parsePubspec();
final flutterConfig = pubspec.flutter?['config'] as YamlMap?;
expect(flutterConfig?['enable-swift-package-manager'], true);
});
test('calls flutter pub get', () async {
writeFakeFlutterCreateOutput(testRoot);
createFakePlugin('plugina', packagesDir);