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

Methods in build_ios_framework for universal and XCFrameworks (#69736)

parent 580cacf4
...@@ -339,7 +339,7 @@ end ...@@ -339,7 +339,7 @@ end
status.stop(); status.stop();
} }
await _produceXCFramework(buildInfo, fatFlutterFrameworkCopy); await _produceXCFrameworkFromUniversal(buildInfo, fatFlutterFrameworkCopy);
} }
Future<void> _produceAppFramework(BuildInfo buildInfo, Directory modeDirectory) async { Future<void> _produceAppFramework(BuildInfo buildInfo, Directory modeDirectory) async {
...@@ -399,7 +399,7 @@ end ...@@ -399,7 +399,7 @@ end
} }
final Directory destinationAppFrameworkDirectory = modeDirectory.childDirectory(appFrameworkName); final Directory destinationAppFrameworkDirectory = modeDirectory.childDirectory(appFrameworkName);
await _produceXCFramework(buildInfo, destinationAppFrameworkDirectory); await _produceXCFrameworkFromUniversal(buildInfo, destinationAppFrameworkDirectory);
} }
Future<void> _producePlugins( Future<void> _producePlugins(
...@@ -496,69 +496,17 @@ end ...@@ -496,69 +496,17 @@ end
continue; continue;
} }
final String binaryName = globals.fs.path.basenameWithoutExtension(podFrameworkName); final String binaryName = globals.fs.path.basenameWithoutExtension(podFrameworkName);
if (boolArg('universal')) {
globals.fsUtils.copyDirectorySync( final List<Directory> frameworks = <Directory>[
podProduct as Directory, podProduct as Directory,
modeDirectory.childDirectory(podFrameworkName),
);
final List<String> lipoCommand = <String>[
...globals.xcode.xcrunCommand(),
'lipo',
'-create',
globals.fs.path.join(podProduct.path, binaryName),
if (mode == BuildMode.debug) if (mode == BuildMode.debug)
simulatorBuildConfiguration simulatorBuildConfiguration
.childDirectory(binaryName) .childDirectory(builtProduct.basename)
.childDirectory(podFrameworkName) .childDirectory(podFrameworkName)
.childFile(binaryName)
.path,
'-output',
modeDirectory.childDirectory(podFrameworkName).childFile(binaryName).path
]; ];
final RunResult pluginsLipoResult = await globals.processUtils.run( await _produceUniversalFramework(frameworks, binaryName, modeDirectory);
lipoCommand, await _produceXCFramework(frameworks, binaryName, modeDirectory);
workingDirectory: outputDirectory.path,
allowReentrantFlutter: false,
);
if (pluginsLipoResult.exitCode != 0) {
throwToolExit(
'Unable to create universal $binaryName.framework: ${buildPluginsResult.stderr}',
);
}
}
if (boolArg('xcframework')) {
final List<String> xcframeworkCommand = <String>[
...globals.xcode.xcrunCommand(),
'xcodebuild',
'-create-xcframework',
'-framework',
podProduct.path,
if (mode == BuildMode.debug)
'-framework',
if (mode == BuildMode.debug)
simulatorBuildConfiguration
.childDirectory(binaryName)
.childDirectory(podFrameworkName)
.path,
'-output',
modeDirectory.childFile('$binaryName.xcframework').path
];
final RunResult xcframeworkResult = await globals.processUtils.run(
xcframeworkCommand,
workingDirectory: outputDirectory.path,
allowReentrantFlutter: false,
);
if (xcframeworkResult.exitCode != 0) {
throwToolExit(
'Unable to create $binaryName.xcframework: ${xcframeworkResult.stderr}',
);
}
}
} }
} }
} finally { } finally {
...@@ -566,7 +514,7 @@ end ...@@ -566,7 +514,7 @@ end
} }
} }
Future<void> _produceXCFramework(BuildInfo buildInfo, Directory fatFramework) async { Future<void> _produceXCFrameworkFromUniversal(BuildInfo buildInfo, Directory fatFramework) async {
if (boolArg('xcframework')) { if (boolArg('xcframework')) {
final String frameworkBinaryName = globals.fs.path.basenameWithoutExtension( final String frameworkBinaryName = globals.fs.path.basenameWithoutExtension(
fatFramework.basename); fatFramework.basename);
...@@ -578,7 +526,9 @@ end ...@@ -578,7 +526,9 @@ end
if (buildInfo.mode == BuildMode.debug) { if (buildInfo.mode == BuildMode.debug) {
await _produceDebugXCFramework(fatFramework, frameworkBinaryName); await _produceDebugXCFramework(fatFramework, frameworkBinaryName);
} else { } else {
await _produceNonDebugXCFramework(buildInfo, fatFramework, frameworkBinaryName); await _produceXCFramework(
<Directory>[fatFramework], frameworkBinaryName,
fatFramework.parent);
} }
} finally { } finally {
status.stop(); status.stop();
...@@ -660,15 +610,34 @@ end ...@@ -660,15 +610,34 @@ end
} }
// Create XCFramework from iOS and simulator frameworks. // Create XCFramework from iOS and simulator frameworks.
await _produceXCFramework(
<Directory>[
armFlutterFrameworkDirectory,
simulatorFlutterFrameworkDirectory
],
frameworkBinaryName,
fatFramework.parent,
);
} finally {
temporaryOutput.deleteSync(recursive: true);
}
}
Future<void> _produceXCFramework(Iterable<Directory> frameworks,
String frameworkBinaryName, Directory outputDirectory) async {
if (!boolArg('xcframework')) {
return;
}
final List<String> xcframeworkCommand = <String>[ final List<String> xcframeworkCommand = <String>[
...globals.xcode.xcrunCommand(), ...globals.xcode.xcrunCommand(),
'xcodebuild', 'xcodebuild',
'-create-xcframework', '-create-xcframework',
'-framework', armFlutterFrameworkDirectory.path, for (Directory framework in frameworks) ...<String>[
'-framework', simulatorFlutterFrameworkDirectory.path, '-framework',
'-output', fatFramework.parent framework.path
.childFile('$frameworkBinaryName.xcframework') ],
.path '-output',
outputDirectory.childDirectory('$frameworkBinaryName.xcframework').path
]; ];
final RunResult xcframeworkResult = await globals.processUtils.run( final RunResult xcframeworkResult = await globals.processUtils.run(
...@@ -678,39 +647,45 @@ end ...@@ -678,39 +647,45 @@ end
if (xcframeworkResult.exitCode != 0) { if (xcframeworkResult.exitCode != 0) {
throwToolExit( throwToolExit(
'Unable to create XCFramework: ${xcframeworkResult.stderr}', 'Unable to create $frameworkBinaryName.xcframework: ${xcframeworkResult.stderr}');
);
} }
} finally {
temporaryOutput.deleteSync(recursive: true);
} }
Future<void> _produceUniversalFramework(Iterable<Directory> frameworks,
String frameworkBinaryName, Directory outputDirectory) async {
if (!boolArg('universal')) {
return;
} }
final Directory outputFrameworkDirectory =
outputDirectory.childDirectory('$frameworkBinaryName.framework');
Future<void> _produceNonDebugXCFramework( // Copy the first framework over completely to get headers, resources, etc.
BuildInfo buildInfo, globals.fsUtils.copyDirectorySync(
Directory fatFramework, frameworks.first,
String frameworkBinaryName, outputFrameworkDirectory,
) async { );
// Simulator is only supported in Debug mode.
// "Fat" framework here must only contain arm. // Recreate the framework binary by lipo'ing the framework binaries together.
final List<String> xcframeworkCommand = <String>[ final List<String> lipoCommand = <String>[
...globals.xcode.xcrunCommand(), ...globals.xcode.xcrunCommand(),
'xcodebuild', 'lipo',
'-create-xcframework', '-create',
'-framework', fatFramework.path, for (Directory framework in frameworks) ...<String>[
'-output', fatFramework.parent framework.childFile(frameworkBinaryName).path
.childFile('$frameworkBinaryName.xcframework') ],
.path '-output',
outputFrameworkDirectory.childFile(frameworkBinaryName).path
]; ];
final RunResult xcframeworkResult = await globals.processUtils.run( final RunResult lipoResult = await globals.processUtils.run(
xcframeworkCommand, lipoCommand,
workingDirectory: outputDirectory.path,
allowReentrantFlutter: false, allowReentrantFlutter: false,
); );
if (xcframeworkResult.exitCode != 0) { if (lipoResult.exitCode != 0) {
throwToolExit( throwToolExit(
'Unable to create XCFramework: ${xcframeworkResult.stderr}'); 'Unable to create $frameworkBinaryName.framework: ${lipoResult.stderr}');
} }
} }
} }
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