Enable Swift Package Manager by default on master channel (#152049)

Changes:

1. Enables Swift Package Manager by default on the main/master channel
2. Fixes tests that fail if Swift Package Manager is enabled

Corresponding docs change: https://github.com/flutter/website/pull/10938

Addresses https://github.com/flutter/flutter/issues/151567
This commit is contained in:
Loïc Sharma
2024-07-24 09:24:31 -07:00
committed by GitHub
parent 0d504914c7
commit 08d8a7fa81
9 changed files with 215 additions and 85 deletions

View File

@@ -186,6 +186,7 @@ const Feature swiftPackageManager = Feature(
environmentOverride: 'SWIFT_PACKAGE_MANAGER',
master: FeatureChannelSetting(
available: true,
enabledByDefault: true,
),
);

View File

@@ -693,7 +693,7 @@ void main() {
),
});
testUsingContext('kotlin/swift plugin project', () async {
testUsingContext('kotlin/swift plugin project without Swift Package Manager', () async {
return _createProject(
projectDir,
<String>['--no-pub', '--template=plugin', '-a', 'kotlin', '--ios-language', 'swift', '--platforms', 'ios,android'],
@@ -718,6 +718,9 @@ void main() {
'ios/Classes/FlutterProjectPlugin.m',
],
);
}, overrides: <Type, Generator>{
// Test flags disable Swift Package Manager.
FeatureFlags: () => TestFeatureFlags(),
});
testUsingContext('swift plugin project with Swift Package Manager', () async {
@@ -1944,7 +1947,7 @@ void main() {
);
});
testUsingContext('can re-gen plugin ios/ and example/ folders, reusing custom org', () async {
testUsingContext('can re-gen plugin ios/ and example/ folders, reusing custom org, without Swift Package Manager', () async {
await _createProject(
projectDir,
<String>[
@@ -1969,6 +1972,7 @@ void main() {
unexpectedPaths: <String>[
'example/android/app/src/main/java/com/example/flutter_project_example/MainActivity.java',
'android/src/main/java/com/example/flutter_project/FlutterProjectPlugin.java',
'ios/flutter_project/Sources/flutter_project/include/flutter_project/FlutterProjectPlugin.h',
],
);
final FlutterProject project = FlutterProject.fromDirectory(projectDir);
@@ -1976,6 +1980,48 @@ void main() {
await project.example.ios.productBundleIdentifier(BuildInfo.debug),
'com.bar.foo.flutterProjectExample',
);
}, overrides: <Type, Generator>{
// Test flags disable Swift Package Manager.
FeatureFlags: () => TestFeatureFlags(),
});
testUsingContext('can re-gen plugin ios/ and example/ folders, reusing custom org, with Swift Package Manager', () async {
await _createProject(
projectDir,
<String>[
'--no-pub',
'--template=plugin',
'--org', 'com.bar.foo',
'-i', 'objc',
'-a', 'java',
'--platforms', 'ios,android',
],
<String>[],
);
projectDir.childDirectory('example').deleteSync(recursive: true);
projectDir.childDirectory('ios').deleteSync(recursive: true);
await _createProject(
projectDir,
<String>['--no-pub', '--template=plugin', '-i', 'objc', '-a', 'java', '--platforms', 'ios,android'],
<String>[
'example/android/app/src/main/java/com/bar/foo/flutter_project_example/MainActivity.java',
'ios/flutter_project/Sources/flutter_project/include/flutter_project/FlutterProjectPlugin.h',
],
unexpectedPaths: <String>[
'example/android/app/src/main/java/com/example/flutter_project_example/MainActivity.java',
'android/src/main/java/com/example/flutter_project/FlutterProjectPlugin.java',
'ios/Classes/FlutterProjectPlugin.h',
],
);
final FlutterProject project = FlutterProject.fromDirectory(projectDir);
expect(
await project.example.ios.productBundleIdentifier(BuildInfo.debug),
'com.bar.foo.flutterProjectExample',
);
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(
isSwiftPackageManagerEnabled: true,
),
});
testUsingContext('fails to re-gen without specified org when org is ambiguous', () async {

View File

@@ -404,7 +404,7 @@ void main() {
});
test('${swiftPackageManager.name} availability and default enabled', () {
expect(swiftPackageManager.master.enabledByDefault, false);
expect(swiftPackageManager.master.enabledByDefault, true);
expect(swiftPackageManager.master.available, true);
expect(swiftPackageManager.beta.enabledByDefault, false);
expect(swiftPackageManager.beta.available, false);

View File

@@ -87,6 +87,7 @@ void main() {
late File outputFlutterFrameworkBinary;
late Directory outputAppFramework;
late File outputAppFrameworkBinary;
late File outputRunnerBinary;
late File outputPluginFrameworkBinary;
late Directory buildPath;
late Directory buildAppFrameworkDsym;
@@ -122,6 +123,10 @@ void main() {
outputAppFramework = frameworkDirectory.childDirectory('App.framework');
outputAppFrameworkBinary = outputAppFramework.childFile('App');
outputRunnerBinary = outputApp.childFile('Runner');
// Exists only if the plugin is built as a dynamic framework.
// This is is the default for CocoaPods but not Swift Package Manager.
outputPluginFrameworkBinary = frameworkDirectory.childDirectory('hello.framework').childFile('hello');
buildPath = fileSystem.directory(fileSystem.path.join(
@@ -141,7 +146,18 @@ void main() {
printOnFailure(buildResult.stderr.toString());
expect(buildResult.exitCode, 0);
expect(outputPluginFrameworkBinary, exists);
// Plugins are built either as a static library (SwiftPM's default)
// or as a dynamic library (CocoaPods's default).
// If built as a dynamic library, the plugin will have a .framework.
// If built as static library, the plugin's symbols will be in the
// Runner binary.
final bool helloDynamic = outputPluginFrameworkBinary.existsSync();
final bool helloStatic = AppleTestUtils
.getExportedSymbols(outputRunnerBinary.path)
.any((String symbol) => symbol.contains('HelloPlugin') && symbol.contains('handle'));
// Plugin is a dynamic xor static framework.
expect(helloDynamic != helloStatic, isTrue);
expect(outputAppFrameworkBinary, exists);
expect(outputAppFramework.childFile('Info.plist'), exists);
@@ -300,6 +316,19 @@ void main() {
);
expect(buildSimulator.exitCode, 0);
// Plugins are built either as a static library (SwiftPM's default)
// or as a dynamic library (CocoaPods's default).
// If built as a dynamic library, the plugin will have a .framework.
// If built as static library, the plugin's symbols will be in the
// Runner binary.
final File runnerBinary = fileSystem.file(fileSystem.path.join(
projectRoot,
'build',
'ios',
'iphonesimulator',
'Runner.app',
'Runner',
));
final File pluginFrameworkBinary = fileSystem.file(fileSystem.path.join(
projectRoot,
'build',
@@ -310,12 +339,21 @@ void main() {
'hello.framework',
'hello',
));
expect(pluginFrameworkBinary, exists);
final ProcessResult archs = processManager.runSync(
<String>['file', pluginFrameworkBinary.path],
);
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library x86_64'));
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library arm64'));
final bool helloDynamic = pluginFrameworkBinary.existsSync();
final bool helloStatic = AppleTestUtils
.getExportedSymbols(runnerBinary.path)
.any((String symbol) => symbol.contains('HelloPlugin') && symbol.contains('handle'));
// Plugin is a dynamic xor static framework.
expect(helloDynamic != helloStatic, isTrue);
if (helloDynamic) {
final ProcessResult archs = processManager.runSync(
<String>['file', pluginFrameworkBinary.path],
);
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library x86_64'));
expect(archs.stdout, contains('Mach-O 64-bit dynamically linked shared library arm64'));
}
});
testWithoutContext('build for simulator with all available architectures', () {