Unverified Commit 5b58d5c5 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Exclude armv7 from iOS add-to-app plugins (#101943)

parent 607db54a
...@@ -265,11 +265,36 @@ dependencies: ...@@ -265,11 +265,36 @@ dependencies:
final File objectiveCAnalyticsOutputFile = File(path.join(tempDir.path, 'analytics-objc.log')); final File objectiveCAnalyticsOutputFile = File(path.join(tempDir.path, 'analytics-objc.log'));
final Directory objectiveCBuildDirectory = Directory(path.join(tempDir.path, 'build-objc')); final Directory objectiveCBuildDirectory = Directory(path.join(tempDir.path, 'build-objc'));
section('Build iOS Objective-C host app');
final File dummyAppFramework = File(path.join(projectDir.path, '.ios', 'Flutter', 'App.framework', 'App')); final File dummyAppFramework = File(path.join(projectDir.path, '.ios', 'Flutter', 'App.framework', 'App'));
checkFileNotExists(dummyAppFramework.path); checkFileNotExists(dummyAppFramework.path);
await inDirectory(objectiveCHostApp, () async { await inDirectory(objectiveCHostApp, () async {
section('Validate iOS Objective-C host app Podfile');
final File podfile = File(path.join(objectiveCHostApp.path, 'Podfile'));
String podfileContent = await podfile.readAsString();
final String podFailure = await eval(
'pod',
<String>['install'],
environment: <String, String>{
'LANG': 'en_US.UTF-8',
},
canFail: true,
);
if (!podFailure.contains('Missing `flutter_post_install(installer)` in Podfile `post_install` block')
|| !podFailure.contains('Add `flutter_post_install(installer)` to your Podfile `post_install` block to build Flutter plugins')) {
print(podfileContent);
throw TaskResult.failure('pod install unexpectedly succeed without "flutter_post_install" post_install block');
}
podfileContent = '''
$podfileContent
post_install do |installer|
flutter_post_install(installer)
end
''';
await podfile.writeAsString(podfileContent, flush: true);
await exec( await exec(
'pod', 'pod',
<String>['install'], <String>['install'],
...@@ -298,6 +323,8 @@ dependencies: ...@@ -298,6 +323,8 @@ dependencies:
throw TaskResult.failure('Minimum version set to $version, expected 9.0'); throw TaskResult.failure('Minimum version set to $version, expected 9.0');
} }
section('Build iOS Objective-C host app');
await exec( await exec(
'xcodebuild', 'xcodebuild',
<String>[ <String>[
...@@ -378,6 +405,86 @@ dependencies: ...@@ -378,6 +405,86 @@ dependencies:
); );
} }
section('Archive iOS Objective-C host app');
await inDirectory(objectiveCHostApp, () async {
final Directory objectiveCBuildArchiveDirectory = Directory(path.join(tempDir.path, 'build-objc-archive'));
await exec(
'xcodebuild',
<String>[
'-workspace',
'Host.xcworkspace',
'-scheme',
'Host',
'-configuration',
'Release',
'CODE_SIGNING_ALLOWED=NO',
'CODE_SIGNING_REQUIRED=NO',
'CODE_SIGN_IDENTITY=-',
'EXPANDED_CODE_SIGN_IDENTITY=-',
'-archivePath',
objectiveCBuildArchiveDirectory.path,
'COMPILER_INDEX_STORE_ENABLE=NO',
'archive'
],
environment: <String, String> {
'FLUTTER_ANALYTICS_LOG_FILE': objectiveCAnalyticsOutputFile.path,
},
);
final String archivedAppPath = path.join(
'${objectiveCBuildArchiveDirectory.path}.xcarchive',
'Products',
'Applications',
'Host.app',
);
checkFileExists(path.join(
archivedAppPath,
'Host',
));
checkFileNotExists(path.join(
archivedAppPath,
'Frameworks',
'App.framework',
'flutter_assets',
'isolate_snapshot_data',
));
final String builtFlutterBinary = path.join(
archivedAppPath,
'Frameworks',
'Flutter.framework',
'Flutter',
);
checkFileExists(builtFlutterBinary);
if ((await fileType(builtFlutterBinary)).contains('armv7')) {
throw TaskResult.failure('Unexpected armv7 architecture slice in $builtFlutterBinary');
}
await containsBitcode(builtFlutterBinary);
final String builtAppBinary = path.join(
archivedAppPath,
'Frameworks',
'App.framework',
'App',
);
checkFileExists(builtAppBinary);
if ((await fileType(builtAppBinary)).contains('armv7')) {
throw TaskResult.failure('Unexpected armv7 architecture slice in $builtAppBinary');
}
await containsBitcode(builtAppBinary);
// The host app example builds plugins statically, url_launcher_ios.framework
// should not exist.
checkDirectoryNotExists(path.join(
archivedAppPath,
'Frameworks',
'url_launcher_ios.framework',
));
});
section('Run platform unit tests'); section('Run platform unit tests');
final String resultBundleTemp = Directory.systemTemp.createTempSync('flutter_module_test_ios_xcresult.').path; final String resultBundleTemp = Directory.systemTemp.createTempSync('flutter_module_test_ios_xcresult.').path;
......
...@@ -13,3 +13,7 @@ target 'ios_add2appTests' do ...@@ -13,3 +13,7 @@ target 'ios_add2appTests' do
install_flutter_engine_pod install_flutter_engine_pod
pod 'EarlGreyTest' pod 'EarlGreyTest'
end end
post_install do |installer|
flutter_post_install(installer)
end
...@@ -6,3 +6,7 @@ load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb') ...@@ -6,3 +6,7 @@ load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'Host' do target 'Host' do
install_all_flutter_pods flutter_application_path install_all_flutter_pods flutter_application_path
end end
post_install do |installer|
flutter_post_install(installer)
end
...@@ -15,6 +15,21 @@ require 'json' ...@@ -15,6 +15,21 @@ require 'json'
# Optional, defaults to two levels up from the directory of this script. # Optional, defaults to two levels up from the directory of this script.
# MyApp/my_flutter/.ios/Flutter/../.. # MyApp/my_flutter/.ios/Flutter/../..
def install_all_flutter_pods(flutter_application_path = nil) def install_all_flutter_pods(flutter_application_path = nil)
# defined_in_file is a Pathname to the Podfile set by CocoaPods.
pod_contents = File.read(defined_in_file)
unless pod_contents.include? 'flutter_post_install'
puts <<~POSTINSTALL
Add `flutter_post_install(installer)` to your Podfile `post_install` block to build Flutter plugins:
post_install do |installer|
flutter_post_install(installer)
end
POSTINSTALL
raise 'Missing `flutter_post_install(installer)` in Podfile `post_install` block'
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_application_path ||= File.join('..', '..') flutter_application_path ||= File.join('..', '..')
install_flutter_engine_pod install_flutter_engine_pod
install_flutter_plugin_pods(flutter_application_path) install_flutter_plugin_pods(flutter_application_path)
...@@ -46,7 +61,7 @@ def install_flutter_engine_pod ...@@ -46,7 +61,7 @@ def install_flutter_engine_pod
# Keep pod path relative so it can be checked into Podfile.lock. # Keep pod path relative so it can be checked into Podfile.lock.
# Process will be run from project directory. # Process will be run from project directory.
engine_pathname = Pathname.new engine_dir engine_pathname = Pathname.new engine_dir
# defined_in_file is set by CocoaPods and is a Pathname to the Podfile. # defined_in_file is a Pathname to the Podfile set by CocoaPods.
project_directory_pathname = defined_in_file.dirname project_directory_pathname = defined_in_file.dirname
relative = engine_pathname.relative_path_from project_directory_pathname relative = engine_pathname.relative_path_from project_directory_pathname
...@@ -77,7 +92,9 @@ def install_flutter_plugin_pods(flutter_application_path) ...@@ -77,7 +92,9 @@ def install_flutter_plugin_pods(flutter_application_path)
FileUtils.mkdir_p(symlinks_dir) FileUtils.mkdir_p(symlinks_dir)
plugins_file = File.expand_path('.flutter-plugins-dependencies', flutter_application_path) plugins_file = File.expand_path('.flutter-plugins-dependencies', flutter_application_path)
plugin_pods = flutter_parse_dependencies_file_for_ios_plugin(plugins_file)
# flutter_parse_plugins_file is in Flutter root podhelper.rb
plugin_pods = flutter_parse_plugins_file(plugins_file, 'ios')
plugin_pods.each do |plugin_hash| plugin_pods.each do |plugin_hash|
plugin_name = plugin_hash['name'] plugin_name = plugin_hash['name']
plugin_path = plugin_hash['path'] plugin_path = plugin_hash['path']
...@@ -127,21 +144,6 @@ def install_flutter_application_pod(flutter_application_path) ...@@ -127,21 +144,6 @@ def install_flutter_application_pod(flutter_application_path)
:execution_position => :before_compile :execution_position => :before_compile
end end
# .flutter-plugins-dependencies format documented at
# https://flutter.dev/go/plugins-list-migration
def flutter_parse_dependencies_file_for_ios_plugin(file)
file_path = File.expand_path(file)
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
def flutter_root def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', '..', 'Flutter', 'Generated.xcconfig'), __FILE__) generated_xcode_build_settings_path = File.expand_path(File.join('..', '..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path) unless File.exist?(generated_xcode_build_settings_path)
...@@ -155,3 +157,23 @@ def flutter_root ...@@ -155,3 +157,23 @@ def flutter_root
# This should never happen... # This should never happen...
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end end
# Run the post-install script to set build settings on Flutter plugins.
#
# @example
# post_install do |installer|
# flutter_post_install(installer)
# end
# @param [Pod::Installer] installer Passed to the `post_install` block.
# @param [boolean] skip Do not change any build configurations. Set to suppress
# "Missing `flutter_post_install" exception.
def flutter_post_install(installer, skip: false)
return if skip
installer.pods_project.targets.each do |target|
target.build_configurations.each do |build_configuration|
# flutter_additional_ios_build_settings is in Flutter root podhelper.rb
flutter_additional_ios_build_settings(target)
end
end
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