Adopt Flutter.xcframework in tool (#71495)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'base/common.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/utils.dart';
|
||||
@@ -305,12 +306,14 @@ class CachedArtifacts implements Artifacts {
|
||||
BuildMode mode, EnvironmentType environmentType) {
|
||||
switch (artifact) {
|
||||
case Artifact.genSnapshot:
|
||||
case Artifact.flutterFramework:
|
||||
case Artifact.flutterXcframework:
|
||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
final String engineDir = _getEngineArtifactsPath(platform, mode);
|
||||
return _fileSystem.path.join(engineDir, artifactFileName);
|
||||
case Artifact.flutterFramework:
|
||||
final String engineDir = _getEngineArtifactsPath(platform, mode);
|
||||
return _getIosEngineArtifactPath(engineDir, environmentType, _fileSystem);
|
||||
case Artifact.idevicescreenshot:
|
||||
case Artifact.idevicesyslog:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
@@ -527,6 +530,38 @@ HostPlatform _currentHostPlatformAsHost(Platform platform) {
|
||||
throw UnimplementedError('Host OS not supported.');
|
||||
}
|
||||
|
||||
String _getIosEngineArtifactPath(String engineDirectory,
|
||||
EnvironmentType environmentType, FileSystem fileSystem) {
|
||||
final Directory xcframeworkDirectory = fileSystem
|
||||
.directory(engineDirectory)
|
||||
.childDirectory(_artifactToFileName(Artifact.flutterXcframework));
|
||||
|
||||
if (!xcframeworkDirectory.existsSync()) {
|
||||
throwToolExit('No xcframework found at ${xcframeworkDirectory.path}. Try running "flutter build ios".');
|
||||
}
|
||||
Directory flutterFrameworkSource;
|
||||
for (final Directory platformDirectory
|
||||
in xcframeworkDirectory.listSync().whereType<Directory>()) {
|
||||
if (!platformDirectory.basename.startsWith('ios-')) {
|
||||
continue;
|
||||
}
|
||||
// ios-x86_64-simulator, ios-armv7_arm64 (Xcode 11), or ios-arm64_armv7 (Xcode 12).
|
||||
final bool simulatorDirectory =
|
||||
platformDirectory.basename.endsWith('-simulator');
|
||||
if ((environmentType == EnvironmentType.simulator && simulatorDirectory) ||
|
||||
(environmentType == EnvironmentType.physical && !simulatorDirectory)) {
|
||||
flutterFrameworkSource = platformDirectory;
|
||||
}
|
||||
}
|
||||
if (flutterFrameworkSource == null) {
|
||||
throwToolExit('No iOS frameworks found in ${xcframeworkDirectory.path}');
|
||||
}
|
||||
|
||||
return flutterFrameworkSource
|
||||
.childDirectory(_artifactToFileName(Artifact.flutterFramework))
|
||||
.path;
|
||||
}
|
||||
|
||||
/// Manages the artifacts of a locally built engine.
|
||||
class LocalEngineArtifacts implements Artifacts {
|
||||
LocalEngineArtifacts(
|
||||
@@ -578,7 +613,8 @@ class LocalEngineArtifacts implements Artifacts {
|
||||
case Artifact.platformLibrariesJson:
|
||||
return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName);
|
||||
case Artifact.flutterFramework:
|
||||
return _fileSystem.path.join(engineOutPath, artifactFileName);
|
||||
return _getIosEngineArtifactPath(
|
||||
engineOutPath, environmentType, _fileSystem);
|
||||
case Artifact.flutterPatchedSdkPath:
|
||||
// When using local engine always use [BuildMode.debug] regardless of
|
||||
// what was specified in [mode] argument because local engine will
|
||||
|
||||
@@ -249,7 +249,7 @@ abstract class UnpackIOS extends Target {
|
||||
const Source.pattern(
|
||||
'{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/ios.dart'),
|
||||
Source.artifact(
|
||||
Artifact.flutterFramework,
|
||||
Artifact.flutterXcframework,
|
||||
platform: TargetPlatform.ios,
|
||||
mode: buildMode,
|
||||
),
|
||||
|
||||
@@ -924,14 +924,11 @@ abstract class EngineCachedArtifact extends CachedArtifact {
|
||||
|
||||
_makeFilesExecutable(dir, operatingSystemUtils);
|
||||
|
||||
const List<String> frameworkNames = <String>['Flutter', 'FlutterMacOS'];
|
||||
for (final String frameworkName in frameworkNames) {
|
||||
final File frameworkZip = fileSystem.file(fileSystem.path.join(dir.path, '$frameworkName.framework.zip'));
|
||||
if (frameworkZip.existsSync()) {
|
||||
final Directory framework = fileSystem.directory(fileSystem.path.join(dir.path, '$frameworkName.framework'));
|
||||
framework.createSync();
|
||||
operatingSystemUtils.unzip(frameworkZip, framework);
|
||||
}
|
||||
final File frameworkZip = fileSystem.file(fileSystem.path.join(dir.path, 'FlutterMacOS.framework.zip'));
|
||||
if (frameworkZip.existsSync()) {
|
||||
final Directory framework = fileSystem.directory(fileSystem.path.join(dir.path, 'FlutterMacOS.framework'));
|
||||
framework.createSync();
|
||||
operatingSystemUtils.unzip(frameworkZip, framework);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -295,10 +295,7 @@ LICENSE
|
||||
s.source = { :http => '${_cache.storageBaseUrl}/flutter_infra/flutter/${_cache.engineRevision}/$artifactsMode/artifacts.zip' }
|
||||
s.documentation_url = 'https://flutter.dev/docs'
|
||||
s.platform = :ios, '8.0'
|
||||
s.vendored_frameworks = 'Flutter.framework'
|
||||
s.prepare_command = <<-CMD
|
||||
unzip Flutter.framework -d Flutter.framework
|
||||
CMD
|
||||
s.vendored_frameworks = 'Flutter.xcframework'
|
||||
end
|
||||
''';
|
||||
|
||||
@@ -314,56 +311,31 @@ end
|
||||
Directory modeDirectory,
|
||||
) async {
|
||||
final Status status = globals.logger.startProgress(
|
||||
' ├─Populating Flutter.framework...',
|
||||
' ├─Populating Flutter.xcframework...',
|
||||
);
|
||||
final String engineCacheFlutterFrameworkDirectory = globals.artifacts.getArtifactPath(
|
||||
Artifact.flutterFramework,
|
||||
Artifact.flutterXcframework,
|
||||
platform: TargetPlatform.ios,
|
||||
mode: buildInfo.mode,
|
||||
);
|
||||
final String flutterFrameworkFileName = globals.fs.path.basename(
|
||||
engineCacheFlutterFrameworkDirectory,
|
||||
);
|
||||
final Directory fatFlutterFrameworkCopy = modeDirectory.childDirectory(
|
||||
final Directory flutterFrameworkCopy = modeDirectory.childDirectory(
|
||||
flutterFrameworkFileName,
|
||||
);
|
||||
|
||||
try {
|
||||
// Copy universal engine cache framework to mode directory.
|
||||
// Copy xcframework engine cache framework to mode directory.
|
||||
globals.fsUtils.copyDirectorySync(
|
||||
globals.fs.directory(engineCacheFlutterFrameworkDirectory),
|
||||
fatFlutterFrameworkCopy,
|
||||
flutterFrameworkCopy,
|
||||
);
|
||||
|
||||
if (buildInfo.mode != BuildMode.debug) {
|
||||
final File fatFlutterFrameworkBinary = fatFlutterFrameworkCopy.childFile('Flutter');
|
||||
|
||||
// Remove simulator architecture in profile and release mode.
|
||||
final List<String> lipoCommand = <String>[
|
||||
...globals.xcode.xcrunCommand(),
|
||||
'lipo',
|
||||
fatFlutterFrameworkBinary.path,
|
||||
'-remove',
|
||||
'x86_64',
|
||||
'-output',
|
||||
fatFlutterFrameworkBinary.path
|
||||
];
|
||||
final RunResult lipoResult = await globals.processUtils.run(
|
||||
lipoCommand,
|
||||
allowReentrantFlutter: false,
|
||||
);
|
||||
|
||||
if (lipoResult.exitCode != 0) {
|
||||
throwToolExit(
|
||||
'Unable to remove simulator architecture in ${buildInfo.mode}: ${lipoResult.stderr}',
|
||||
);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
status.stop();
|
||||
}
|
||||
|
||||
await _produceXCFrameworkFromUniversal(buildInfo, fatFlutterFrameworkCopy);
|
||||
await _produceUniversalFromXCFramework(buildInfo, flutterFrameworkCopy);
|
||||
}
|
||||
|
||||
Future<void> _produceAppFramework(
|
||||
@@ -558,112 +530,34 @@ end
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _produceXCFrameworkFromUniversal(BuildInfo buildInfo, Directory fatFramework) async {
|
||||
if (boolArg('xcframework')) {
|
||||
final String frameworkBinaryName = globals.fs.path.basenameWithoutExtension(
|
||||
fatFramework.basename);
|
||||
Future<void> _produceUniversalFromXCFramework(BuildInfo buildInfo, Directory xcframework) async {
|
||||
if (boolArg('universal')) {
|
||||
final String frameworkBinaryName =
|
||||
globals.fs.path.basenameWithoutExtension(xcframework.basename);
|
||||
|
||||
final Status status = globals.logger.startProgress(
|
||||
' ├─Creating $frameworkBinaryName.xcframework...',
|
||||
' ├─Creating $frameworkBinaryName.framework...',
|
||||
);
|
||||
try {
|
||||
if (buildInfo.mode == BuildMode.debug) {
|
||||
await _produceDebugXCFramework(fatFramework, frameworkBinaryName);
|
||||
} else {
|
||||
await _produceXCFramework(
|
||||
<Directory>[fatFramework], frameworkBinaryName,
|
||||
fatFramework.parent);
|
||||
}
|
||||
final Iterable<Directory> frameworks = xcframework
|
||||
.listSync()
|
||||
.whereType<Directory>()
|
||||
.map((Directory triple) => triple
|
||||
.listSync()
|
||||
.whereType<Directory>()
|
||||
.firstWhere((Directory frameworkDirectory) =>
|
||||
frameworkDirectory.basename ==
|
||||
'$frameworkBinaryName.framework'));
|
||||
|
||||
await _produceUniversalFramework(
|
||||
frameworks, frameworkBinaryName, xcframework.parent);
|
||||
} finally {
|
||||
status.stop();
|
||||
}
|
||||
}
|
||||
|
||||
if (!boolArg('universal')) {
|
||||
fatFramework.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _produceDebugXCFramework(Directory fatFramework, String frameworkBinaryName) async {
|
||||
final String frameworkFileName = fatFramework.basename;
|
||||
final File fatFlutterFrameworkBinary = fatFramework.childFile(
|
||||
frameworkBinaryName,
|
||||
);
|
||||
final Directory temporaryOutput = globals.fs.systemTempDirectory.createTempSync(
|
||||
'flutter_tool_build_ios_framework.',
|
||||
);
|
||||
try {
|
||||
// Copy universal framework to variant directory.
|
||||
final Directory iPhoneBuildOutput = temporaryOutput.childDirectory(
|
||||
'ios',
|
||||
)..createSync(recursive: true);
|
||||
final Directory simulatorBuildOutput = temporaryOutput.childDirectory(
|
||||
'simulator',
|
||||
)..createSync(recursive: true);
|
||||
final Directory armFlutterFrameworkDirectory = iPhoneBuildOutput
|
||||
.childDirectory(frameworkFileName);
|
||||
final File armFlutterFrameworkBinary = armFlutterFrameworkDirectory
|
||||
.childFile(frameworkBinaryName);
|
||||
globals.fsUtils.copyDirectorySync(fatFramework, armFlutterFrameworkDirectory);
|
||||
|
||||
// Create iOS framework.
|
||||
List<String> lipoCommand = <String>[
|
||||
...globals.xcode.xcrunCommand(),
|
||||
'lipo',
|
||||
fatFlutterFrameworkBinary.path,
|
||||
'-remove',
|
||||
'x86_64',
|
||||
'-output',
|
||||
armFlutterFrameworkBinary.path
|
||||
];
|
||||
|
||||
RunResult lipoResult = await globals.processUtils.run(
|
||||
lipoCommand,
|
||||
allowReentrantFlutter: false,
|
||||
);
|
||||
|
||||
if (lipoResult.exitCode != 0) {
|
||||
throwToolExit('Unable to create ARM framework: ${lipoResult.stderr}');
|
||||
}
|
||||
|
||||
// Create simulator framework.
|
||||
final Directory simulatorFlutterFrameworkDirectory = simulatorBuildOutput
|
||||
.childDirectory(frameworkFileName);
|
||||
final File simulatorFlutterFrameworkBinary = simulatorFlutterFrameworkDirectory
|
||||
.childFile(frameworkBinaryName);
|
||||
globals.fsUtils.copyDirectorySync(fatFramework, simulatorFlutterFrameworkDirectory);
|
||||
|
||||
lipoCommand = <String>[
|
||||
...globals.xcode.xcrunCommand(),
|
||||
'lipo',
|
||||
fatFlutterFrameworkBinary.path,
|
||||
'-thin',
|
||||
'x86_64',
|
||||
'-output',
|
||||
simulatorFlutterFrameworkBinary.path
|
||||
];
|
||||
|
||||
lipoResult = await globals.processUtils.run(
|
||||
lipoCommand,
|
||||
allowReentrantFlutter: false,
|
||||
);
|
||||
|
||||
if (lipoResult.exitCode != 0) {
|
||||
throwToolExit(
|
||||
'Unable to create simulator framework: ${lipoResult.stderr}');
|
||||
}
|
||||
|
||||
// Create XCFramework from iOS and simulator frameworks.
|
||||
await _produceXCFramework(
|
||||
<Directory>[
|
||||
armFlutterFrameworkDirectory,
|
||||
simulatorFlutterFrameworkDirectory
|
||||
],
|
||||
frameworkBinaryName,
|
||||
fatFramework.parent,
|
||||
);
|
||||
} finally {
|
||||
temporaryOutput.deleteSync(recursive: true);
|
||||
if (!boolArg('xcframework')) {
|
||||
xcframework.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,16 +13,14 @@ import '../macos/xcode.dart';
|
||||
|
||||
const bool kBitcodeEnabledDefault = false;
|
||||
|
||||
Future<void> validateBitcode(BuildMode buildMode, TargetPlatform targetPlatform) async {
|
||||
Future<void> validateBitcode(BuildMode buildMode, TargetPlatform targetPlatform, EnvironmentType environmentType) async {
|
||||
final Artifacts localArtifacts = globals.artifacts;
|
||||
final String flutterFrameworkPath = localArtifacts.getArtifactPath(
|
||||
Artifact.flutterFramework,
|
||||
mode: buildMode,
|
||||
platform: targetPlatform,
|
||||
environmentType: environmentType,
|
||||
);
|
||||
if (!globals.fs.isDirectorySync(flutterFrameworkPath)) {
|
||||
throwToolExit('Flutter.framework not found at $flutterFrameworkPath');
|
||||
}
|
||||
final Xcode xcode = context.get<Xcode>();
|
||||
|
||||
final RunResult clangResult = await xcode.clang(<String>['--version']);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import '../base/fingerprint.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../plugins.dart';
|
||||
import '../project.dart';
|
||||
@@ -28,6 +29,13 @@ Future<void> processPodsIfNeeded(
|
||||
xcodeProject.xcodeProjectInfoFile.path,
|
||||
xcodeProject.podfile.path,
|
||||
xcodeProject.generatedXcodePropertiesFile.path,
|
||||
globals.fs.path.join(
|
||||
Cache.flutterRoot,
|
||||
'packages',
|
||||
'flutter_tools',
|
||||
'bin',
|
||||
'podhelper.rb',
|
||||
),
|
||||
],
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
|
||||
@@ -659,7 +659,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
||||
// to be in this location.
|
||||
final Directory framework = globals.fs.directory(
|
||||
globals.artifacts.getArtifactPath(
|
||||
Artifact.flutterFramework,
|
||||
Artifact.flutterXcframework,
|
||||
platform: TargetPlatform.ios,
|
||||
mode: mode,
|
||||
environmentType: environmentType,
|
||||
@@ -668,7 +668,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
||||
if (framework.existsSync()) {
|
||||
globals.fsUtils.copyDirectorySync(
|
||||
framework,
|
||||
engineCopyDirectory.childDirectory('Flutter.framework'),
|
||||
engineCopyDirectory.childDirectory('Flutter.xcframework'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user