Unverified Commit 3744b82d authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Support .flutter-plugins-dependencies (#59209)

parent 802ba9ac
......@@ -106,12 +106,12 @@ Future<void> main() async {
final String swiftPluginPath = path.join(tempDir.path, swiftPluginName);
final File objcPubspec = File(path.join(objcAppPath, 'pubspec.yaml'));
String podspecContent = objcPubspec.readAsStringSync();
podspecContent = podspecContent.replaceFirst(
String pubspecContent = objcPubspec.readAsStringSync();
pubspecContent = pubspecContent.replaceFirst(
'\ndependencies:\n',
'\ndependencies:\n $objcPluginName:\n path: $objcPluginPath\n $swiftPluginName:\n path: $swiftPluginPath\n device_info:\n',
);
objcPubspec.writeAsStringSync(podspecContent, flush: true);
objcPubspec.writeAsStringSync(pubspecContent, flush: true);
await inDirectory(objcAppPath, () async {
await flutter(
......@@ -167,7 +167,7 @@ Future<void> main() async {
final String swiftAppPath = path.join(tempDir.path, swiftAppName);
final File swiftPubspec = File(path.join(swiftAppPath, 'pubspec.yaml'));
swiftPubspec.writeAsStringSync(podspecContent, flush: true);
swiftPubspec.writeAsStringSync(pubspecContent, flush: true);
await inDirectory(swiftAppPath, () async {
await flutter(
......@@ -202,6 +202,71 @@ Future<void> main() async {
_validatePodfile(swiftAppPath);
section('Remove iOS support from plugin');
Directory(path.join(objcPluginPath, 'ios')).deleteSync(recursive: true);
const String iosPlatformMap = '''
ios:
pluginClass: TestPluginObjcPlugin''';
final File pluginPubspec = File(path.join(objcPluginPath, 'pubspec.yaml'));
String pluginPubspecContent = pluginPubspec.readAsStringSync();
if (!pluginPubspecContent.contains(iosPlatformMap)) {
return TaskResult.failure('Plugin pubspec.yaml missing iOS platform map');
}
pluginPubspecContent = pluginPubspecContent.replaceFirst(iosPlatformMap, '');
pluginPubspec.writeAsStringSync(pluginPubspecContent, flush: true);
await inDirectory(swiftAppPath, () async {
await flutter('clean');
await flutter(
'build',
options: <String>[
'ios',
'--no-codesign'
],
);
});
section('Validate plugin without iOS platform');
final File podfileLockFile = File(path.join(swiftAppPath, 'ios', 'Podfile.lock'));
final String podfileLockOutput = podfileLockFile.readAsStringSync();
if (!podfileLockOutput.contains(':path: ".symlinks/plugins/device_info/ios"')
|| !podfileLockOutput.contains(':path: Flutter')
// test_plugin_objc no longer supports iOS, shouldn't be present.
|| podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin_objc/ios"')
|| !podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin_swift/ios"')) {
return TaskResult.failure('Podfile.lock does not contain expected pods');
}
final String pluginSymlinks = path.join(
swiftAppPath,
'ios',
'.symlinks',
'plugins',
);
checkDirectoryExists(path.join(
pluginSymlinks,
'device_info',
'ios',
));
checkDirectoryExists(path.join(
pluginSymlinks,
'test_plugin_swift',
'ios',
));
// test_plugin_objc no longer supports iOS, shouldn't exist!
checkDirectoryNotExists(path.join(
pluginSymlinks,
'test_plugin_objc',
));
return TaskResult.success(null);
} catch (e) {
return TaskResult.failure(e.toString());
......
......@@ -693,6 +693,13 @@ void checkDirectoryExists(String directory) {
}
}
/// Checks that the directory does not exist, otherwise throws a [FileSystemException].
void checkDirectoryNotExists(String directory) {
if (exists(Directory(directory))) {
throw FileSystemException('Expected directory to not exist.', directory);
}
}
/// Check that `collection` contains all entries in `values`.
void checkCollectionContains<T>(Iterable<T> values, Iterable<T> collection) {
for (final T value in values) {
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
require 'json'
# Minimum CocoaPods Ruby version is 2.0.
# Don't depend on features newer than that.
......@@ -105,35 +107,32 @@ def flutter_install_ios_plugin_pods(ios_application_path = nil)
symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
system('mkdir', '-p', symlink_plugins_dir)
plugins_file = File.join(ios_application_path, '..', '.flutter-plugins')
plugins_file = File.join(ios_application_path, '..', '.flutter-plugins-dependencies')
plugin_pods = flutter_parse_plugins_file(plugins_file)
plugin_pods.each do |name, path|
symlink = File.join(symlink_plugins_dir, name)
File.symlink(path, symlink)
# Keep pod path relative so it can be checked into Podfile.lock.
pod name, :path => File.join('.symlinks', 'plugins', name, 'ios')
plugin_pods.each do |plugin_hash|
plugin_name = plugin_hash['name']
plugin_path = plugin_hash['path']
if (plugin_name && plugin_path)
symlink = File.join(symlink_plugins_dir, plugin_name)
File.symlink(plugin_path, symlink)
# Keep pod path relative so it can be checked into Podfile.lock.
pod plugin_name, :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
end
end
end
# .flutter-plugins-dependencies format documented at
# https://flutter.dev/go/plugins-list-migration
def flutter_parse_plugins_file(file)
file_path = File.expand_path(file)
unless File.exists? file_path
return {};
end
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split('=')
if plugin.length == 2
podname = plugin[0].strip
path = plugin[1].strip
podpath = File.expand_path(path, file_path)
generated_key_values[podname] = File.expand_path(path, file_path)
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
return [] unless File.exists? file_path
dependencies_file = File.read(file)
dependencies_hash = JSON.parse(dependencies_file)
# dependencies_hash.dig('plugins', 'ios') not available until Ruby 2.3
return [] unless dependencies_hash.has_key?('plugins')
return [] unless dependencies_hash['plugins'].has_key?('ios')
dependencies_hash['plugins']['ios'] || []
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment