Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include -isysroot -arch and -miphoneos-version-min when creating dummy module App.framework #97689

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dev/devicelab/bin/tasks/module_test_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ dependencies:
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'));
checkFileNotExists(dummyAppFramework.path);
await inDirectory(objectiveCHostApp, () async {
await exec(
'pod',
Expand All @@ -267,6 +270,14 @@ dependencies:
throw TaskResult.failure('Building host app Podfile.lock does not contain expected pods');
}

// Just running "pod install" should create a fake App.framework so CocoaPods recognizes
// it as a framework that needs to be embedded, before Flutter actually creates it.
checkFileExists(dummyAppFramework.path);
final String? version = await minPhoneOSVersion(dummyAppFramework.path);
if (version != '9.0') {
throw TaskResult.failure('Minimum version set to $version, expected 9.0');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test correctly fails on master without the additional flag:

Task result:
{
  "success": false,
  "reason": "Minimum version set to null, expected 9.0"
}

}

await exec(
'xcodebuild',
<String>[
Expand Down
31 changes: 31 additions & 0 deletions dev/devicelab/lib/framework/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ Future<String> fileType(String pathToBinary) {
return eval('file', <String>[pathToBinary]);
}

Future<String?> minPhoneOSVersion(String pathToBinary) async {
final String loadCommands = await eval('otool', <String>[
'-l',
'-arch',
'arm64',
pathToBinary,
]);
if (!loadCommands.contains('LC_VERSION_MIN_IPHONEOS')) {
return null;
}

String? minVersion;
// Load command 7
// cmd LC_VERSION_MIN_IPHONEOS
// cmdsize 16
// version 9.0
// sdk 15.2
// ...
final List<String> lines = LineSplitter.split(loadCommands).toList();
lines.asMap().forEach((int index, String line) {
if (line.contains('LC_VERSION_MIN_IPHONEOS') && lines.length - index - 1 > 3) {
final String versionLine = lines
.skip(index - 1)
.take(4).last;
final RegExp versionRegex = RegExp(r'\s*version\s*(\S*)');
minVersion = versionRegex.firstMatch(versionLine)?.group(1);
}
});
return minVersion;
}

Future<bool> containsBitcode(String pathToBinary) async {
// See: https://stackoverflow.com/questions/32755775/how-to-check-a-static-library-is-built-contain-bitcode
final String loadCommands = await eval('otool', <String>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def install_flutter_application_pod(flutter_application_path)
# CocoaPods will not embed the framework on pod install (before any build phases can run) if the dylib does not exist.
# Create a dummy dylib.
FileUtils.mkdir_p(app_framework_dir)
`echo "static const int Moo = 88;" | xcrun clang -x c -dynamiclib -o "#{app_framework_dylib}" -`
sdk_path = `xcrun --sdk iphoneos --show-sdk-path`.strip
`echo "static const int Moo = 88;" | xcrun clang -x c -arch arm64 -dynamiclib -miphoneos-version-min=9.0 -isysroot "#{sdk_path}" -o "#{app_framework_dylib}" -`
end

# Keep pod and script phase paths relative so they can be checked into source control.
Expand Down