mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add test that app builds if migrated to SwiftPM but SwiftPM is turned off (#153800)
When a Flutter app is migrated to add Swift Package Manager integration, the Xcode project is modified to depend on a local Swift package that's generated by the Flutter tool. This generated package is how plugins are added to the Xcode project if the SwiftPM feature is enabled. If an app has been migrated to SwiftPM but Flutter's SwiftPM feature is disabled, the [tool must continue to generate a Swift package](47c1df9640/packages/flutter_tools/lib/src/macos/darwin_dependency_management.dart (L69-L78)
) to ensure the app continues to build. Otherwise, the Xcode project would depend on a local package that does not exist. This adds a high-level integration test that ensures this behavior works as expected, which mirrors this finer-grained unit test:47c1df9640/packages/flutter_tools/test/general.shard/macos/darwin_dependency_management_test.dart (L340-L382)
Part of https://github.com/flutter/flutter/issues/153448
This commit is contained in:
parent
7cff6d8b6a
commit
88d9f61d12
@ -692,4 +692,114 @@ void main() {
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Migrated app builds after Swift Package Manager is turned off', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_turned_off.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
);
|
||||
|
||||
// Create an app with a plugin and Swift Package Manager integration.
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: 'swift',
|
||||
platform: 'ios',
|
||||
usesSwiftPackageManager: true,
|
||||
options: <String>['--platforms=ios'],
|
||||
);
|
||||
|
||||
final SwiftPackageManagerPlugin integrationTestPlugin =
|
||||
SwiftPackageManagerUtils.integrationTestPlugin('ios');
|
||||
|
||||
SwiftPackageManagerUtils.addDependency(
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
plugin: integrationTestPlugin,
|
||||
);
|
||||
|
||||
// Build the app.
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>['ios', '--config-only', '-v'],
|
||||
);
|
||||
|
||||
// The app should have SwiftPM integration.
|
||||
final File xcodeProjectFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory('ios')
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childFile('project.pbxproj');
|
||||
final File generatedManifestFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory('ios')
|
||||
.childDirectory('Flutter')
|
||||
.childDirectory('ephemeral')
|
||||
.childDirectory('Packages')
|
||||
.childDirectory('FlutterGeneratedPluginSwiftPackage')
|
||||
.childFile('Package.swift');
|
||||
final Directory cocoaPodsPluginFramework = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory('build')
|
||||
.childDirectory('ios')
|
||||
.childDirectory('iphoneos')
|
||||
.childDirectory('Runner.app')
|
||||
.childDirectory('Frameworks')
|
||||
.childDirectory('${integrationTestPlugin.pluginName}.framework');
|
||||
|
||||
expect(xcodeProjectFile.existsSync(), isTrue);
|
||||
expect(generatedManifestFile.existsSync(), isTrue);
|
||||
expect(cocoaPodsPluginFramework.existsSync(), isFalse);
|
||||
|
||||
String xcodeProject = xcodeProjectFile.readAsStringSync();
|
||||
String generatedManifest = generatedManifestFile.readAsStringSync();
|
||||
final String generatedSwiftDependency = '''
|
||||
dependencies: [
|
||||
.package(name: "integration_test", path: "${integrationTestPlugin.swiftPackagePlatformPath}")
|
||||
],
|
||||
''';
|
||||
|
||||
expect(xcodeProject.contains('FlutterGeneratedPluginSwiftPackage'), isTrue);
|
||||
expect(generatedManifest.contains(generatedSwiftDependency), isTrue);
|
||||
|
||||
// Disable Swift Package Manager and do a clean re-build of the app.
|
||||
// The build should succeed.
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
);
|
||||
|
||||
await SwiftPackageManagerUtils.cleanApp(flutterBin, appDirectoryPath);
|
||||
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>['ios', '-v'],
|
||||
);
|
||||
|
||||
// The app should still have SwiftPM integration,
|
||||
// but the plugin should be added using CocoaPods.
|
||||
expect(xcodeProjectFile.existsSync(), isTrue);
|
||||
expect(generatedManifestFile.existsSync(), isTrue);
|
||||
|
||||
xcodeProject = xcodeProjectFile.readAsStringSync();
|
||||
generatedManifest = generatedManifestFile.readAsStringSync();
|
||||
const String emptyDependencies = 'dependencies: [\n \n ],\n';
|
||||
|
||||
expect(xcodeProject.contains('FlutterGeneratedPluginSwiftPackage'), isTrue);
|
||||
expect(generatedManifest.contains('integration_test'), isFalse);
|
||||
expect(generatedManifest.contains(emptyDependencies), isTrue);
|
||||
expect(cocoaPodsPluginFramework.existsSync(), isTrue);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user