mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[Swift Package Manager] Test removing the last Flutter plugin (#153519)
The Flutter tool has a bug where removing the last Flutter plugin does not correctly update the CocoaPods integration. This adds a test to ensure that the generated Swift package is properly updated when the last Flutter plugin is removed. See: https://github.com/flutter/flutter/issues/11819#issuecomment-2289782626
This commit is contained in:
parent
bced008679
commit
15876ff6ea
@ -607,4 +607,89 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||||
|
|
||||||
|
test('Removing the last plugin updates the generated Swift package', () async {
|
||||||
|
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||||
|
.createTempSync('swift_package_manager_remove_last_plugin.');
|
||||||
|
final String workingDirectoryPath = workingDirectory.path;
|
||||||
|
try {
|
||||||
|
await SwiftPackageManagerUtils.enableSwiftPackageManager(
|
||||||
|
flutterBin,
|
||||||
|
workingDirectoryPath,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create an app with a plugin.
|
||||||
|
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 to generate the Swift package.
|
||||||
|
await SwiftPackageManagerUtils.buildApp(
|
||||||
|
flutterBin,
|
||||||
|
appDirectoryPath,
|
||||||
|
options: <String>['ios', '--config-only', '-v'],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify the generated Swift package depends on the plugin.
|
||||||
|
final File generatedManifestFile = fileSystem
|
||||||
|
.directory(appDirectoryPath)
|
||||||
|
.childDirectory('ios')
|
||||||
|
.childDirectory('Flutter')
|
||||||
|
.childDirectory('ephemeral')
|
||||||
|
.childDirectory('Packages')
|
||||||
|
.childDirectory('FlutterGeneratedPluginSwiftPackage')
|
||||||
|
.childFile('Package.swift');
|
||||||
|
|
||||||
|
expect(generatedManifestFile.existsSync(), isTrue);
|
||||||
|
|
||||||
|
String generatedManifest = generatedManifestFile.readAsStringSync();
|
||||||
|
final String generatedSwiftDependency = '''
|
||||||
|
dependencies: [
|
||||||
|
.package(name: "integration_test", path: "${integrationTestPlugin.swiftPackagePlatformPath}")
|
||||||
|
],
|
||||||
|
''';
|
||||||
|
|
||||||
|
expect(generatedManifest.contains(generatedSwiftDependency), isTrue);
|
||||||
|
|
||||||
|
// Remove the plugin and rebuild the app to re-generate the Swift package.
|
||||||
|
SwiftPackageManagerUtils.removeDependency(
|
||||||
|
appDirectoryPath: appDirectoryPath,
|
||||||
|
plugin: integrationTestPlugin,
|
||||||
|
);
|
||||||
|
|
||||||
|
await SwiftPackageManagerUtils.buildApp(
|
||||||
|
flutterBin,
|
||||||
|
appDirectoryPath,
|
||||||
|
options: <String>['ios', '--config-only', '-v'],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify the generated Swift package does not depend on the plugin.
|
||||||
|
expect(generatedManifestFile.existsSync(), isTrue);
|
||||||
|
|
||||||
|
generatedManifest = generatedManifestFile.readAsStringSync();
|
||||||
|
const String emptyDependencies = 'dependencies: [\n \n ],\n';
|
||||||
|
|
||||||
|
expect(generatedManifest.contains(generatedSwiftDependency), isFalse);
|
||||||
|
expect(generatedManifest.contains(emptyDependencies), isTrue);
|
||||||
|
} finally {
|
||||||
|
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||||
|
ErrorHandlingFileSystem.deleteIfExists(
|
||||||
|
workingDirectory,
|
||||||
|
recursive: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||||
}
|
}
|
||||||
|
@ -245,6 +245,24 @@ class SwiftPackageManagerUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void removeDependency({
|
||||||
|
required SwiftPackageManagerPlugin plugin,
|
||||||
|
required String appDirectoryPath,
|
||||||
|
}) {
|
||||||
|
final File pubspec = fileSystem.file(
|
||||||
|
fileSystem.path.join(appDirectoryPath, 'pubspec.yaml'),
|
||||||
|
);
|
||||||
|
final String pubspecContent = pubspec.readAsStringSync();
|
||||||
|
final String updatedPubspecContent = pubspecContent.replaceFirst(
|
||||||
|
'\n ${plugin.pluginName}:\n path: ${plugin.pluginPath}\n',
|
||||||
|
'\n',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(updatedPubspecContent, isNot(pubspecContent));
|
||||||
|
|
||||||
|
pubspec.writeAsStringSync(updatedPubspecContent);
|
||||||
|
}
|
||||||
|
|
||||||
static void disableSwiftPackageManagerByPubspec({
|
static void disableSwiftPackageManagerByPubspec({
|
||||||
required String appDirectoryPath,
|
required String appDirectoryPath,
|
||||||
}) {
|
}) {
|
||||||
@ -378,4 +396,5 @@ class SwiftPackageManagerPlugin {
|
|||||||
final String platform;
|
final String platform;
|
||||||
String get exampleAppPath => fileSystem.path.join(pluginPath, 'example');
|
String get exampleAppPath => fileSystem.path.join(pluginPath, 'example');
|
||||||
String get exampleAppPlatformPath => fileSystem.path.join(exampleAppPath, platform);
|
String get exampleAppPlatformPath => fileSystem.path.join(exampleAppPath, platform);
|
||||||
|
String get swiftPackagePlatformPath => fileSystem.path.join(pluginPath, platform, pluginName);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user