Unverified Commit ce9cde8c authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Avoid thinning frameworks in iOS extensions (#64674)

parent a3fe33af
......@@ -7,12 +7,14 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/ios.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;
import 'package:meta/meta.dart';
Future<void> main() async {
await task(() async {
section('Copy test Flutter App with WatchOS Companion');
section('Copy test Flutter App with watchOS Companion');
String watchDeviceID;
String phoneDeviceID;
......@@ -33,22 +35,54 @@ Future<void> main() async {
await inDirectory(projectDir, () async {
await flutter(
'build',
options: <String>['ios', '--no-codesign'],
options: <String>['ios', '--no-codesign', '--release'],
);
});
final bool appReleaseBuilt = exists(Directory(path.join(
final String appBundle = Directory(path.join(
projectDir.path,
'build',
'ios',
'iphoneos',
'Runner.app',
)));
)).path;
if (!appReleaseBuilt) {
return TaskResult.failure(
'Failed to build flutter iOS app with WatchOS companion in release mode.');
}
final String appFrameworkPath = path.join(
appBundle,
'Frameworks',
'App.framework',
'App',
);
final String flutterFrameworkPath = path.join(
appBundle,
'Frameworks',
'Flutter.framework',
'Flutter',
);
checkDirectoryExists(appBundle);
await _checkFlutterFrameworkArchs(appFrameworkPath, isSimulator: false);
await _checkFlutterFrameworkArchs(flutterFrameworkPath, isSimulator: false);
// Check the watch extension framework added in the Podfile
// is in place with the expected watch archs.
final String watchExtensionFrameworkPath = path.join(
appBundle,
'Watch',
'watch.app',
'PlugIns',
'watch Extension.appex',
'Frameworks',
'EFQRCode.framework',
'EFQRCode',
);
_checkWatchExtensionFrameworkArchs(watchExtensionFrameworkPath);
section('Clean build');
await inDirectory(projectDir, () async {
await flutter('clean');
});
section('Create debug build');
......@@ -59,20 +93,18 @@ Future<void> main() async {
);
});
final bool appDebugBuilt = exists(Directory(path.join(
projectDir.path,
'build',
'ios',
'iphoneos',
'Runner.app',
)));
checkDirectoryExists(appBundle);
await _checkFlutterFrameworkArchs(appFrameworkPath, isSimulator: false);
await _checkFlutterFrameworkArchs(flutterFrameworkPath, isSimulator: false);
_checkWatchExtensionFrameworkArchs(watchExtensionFrameworkPath);
if (!appDebugBuilt) {
return TaskResult.failure(
'Failed to build flutter iOS app with WatchOS companion in debug mode.');
}
section('Clean build');
await inDirectory(projectDir, () async {
await flutter('clean');
});
section('Create build for a simulator device');
section('Run app on simulator device');
// Xcode 11.4 simctl create makes the runtime argument optional, and defaults to latest.
// TODO(jmagman): Remove runtime parsing when devicelab upgrades to Xcode 11.4 https://github.com/flutter/flutter/issues/54889
......@@ -160,34 +192,6 @@ Future<void> main() async {
workingDirectory: flutterDirectory.path,
);
await inDirectory(projectDir, () async {
await flutter(
'build',
options: <String>[
'ios',
'--debug',
'--no-codesign',
'-d',
phoneDeviceID
],
);
});
final bool appSimulatorBuilt = exists(Directory(path.join(
projectDir.path,
'build',
'ios',
'iphoneos',
'Runner.app',
)));
if (!appSimulatorBuilt) {
return TaskResult.failure(
'Failed to build flutter iOS app with WatchOS companion in debug mode for simulated device.');
}
section('Run app on simulator device');
// Boot simulator devices.
await eval(
'xcrun',
......@@ -227,9 +231,36 @@ Future<void> main() async {
final int exitCode = await process.exitCode;
if (exitCode != 0)
if (exitCode != 0) {
return TaskResult.failure(
'Failed to start flutter iOS app with WatchOS companion on simulated device.');
}
final String simulatorAppBundle = Directory(path.join(
projectDir.path,
'build',
'ios',
'iphonesimulator',
'Runner.app',
)).path;
checkDirectoryExists(simulatorAppBundle);
final String simulatorAppFrameworkPath = path.join(
simulatorAppBundle,
'Frameworks',
'App.framework',
'App',
);
final String simulatorFlutterFrameworkPath = path.join(
simulatorAppBundle,
'Frameworks',
'Flutter.framework',
'Flutter',
);
await _checkFlutterFrameworkArchs(simulatorAppFrameworkPath, isSimulator: true);
await _checkFlutterFrameworkArchs(simulatorFlutterFrameworkPath, isSimulator: true);
return TaskResult.success(null);
} catch (e) {
......@@ -268,3 +299,35 @@ Future<void> main() async {
}
});
}
Future<void> _checkFlutterFrameworkArchs(String frameworkPath, {
@required bool isSimulator
}) async {
checkFileExists(frameworkPath);
final String archs = await fileType(frameworkPath);
if (isSimulator == archs.contains('armv7')) {
throw TaskResult.failure('$frameworkPath armv7 architecture unexpected');
}
if (isSimulator == archs.contains('arm64')) {
throw TaskResult.failure('$frameworkPath arm64 architecture unexpected');
}
if (isSimulator != archs.contains('x86_64')) {
throw TaskResult.failure(
'$frameworkPath x86_64 architecture unexpected');
}
}
Future<void> _checkWatchExtensionFrameworkArchs(String frameworkPath) async {
checkFileExists(frameworkPath);
final String archs = await fileType(frameworkPath);
if (!archs.contains('armv7k')) {
throw TaskResult.failure('$frameworkPath armv7k architecture missing');
}
if (!archs.contains('arm64_32')) {
throw TaskResult.failure('$frameworkPath arm64_32 architecture missing');
}
}
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
target 'watch Extension' do
platform :watchos
use_frameworks!
use_modular_headers!
pod 'EFQRCode/watchOS', '5.1.6'
end
......@@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
......@@ -257,11 +257,10 @@ ThinFramework() {
}
ThinAppFrameworks() {
local app_path="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
local frameworks_dir="${app_path}/Frameworks"
local xcode_frameworks_dir="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
[[ -d "$frameworks_dir" ]] || return 0
find "${app_path}" -type d -name "*.framework" | while read framework_dir; do
[[ -d "${xcode_frameworks_dir}" ]] || return 0
find "${xcode_frameworks_dir}" -type d -name "*.framework" | while read framework_dir; do
ThinFramework "$framework_dir" "$ARCHS"
done
}
......
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