Add XCFramework artifacts (#71113)

This commit is contained in:
Jenn Magder
2020-12-01 10:00:16 -08:00
committed by GitHub
parent e244724794
commit a5ee7f7cfc
8 changed files with 208 additions and 62 deletions

View File

@@ -18,6 +18,7 @@ enum Artifact {
/// The flutter tester binary.
flutterTester,
flutterFramework,
flutterXcframework,
/// The framework directory of the macOS desktop.
flutterMacOSFramework,
vmSnapshotData,
@@ -94,6 +95,8 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
return 'flutter_tester$exe';
case Artifact.flutterFramework:
return 'Flutter.framework';
case Artifact.flutterXcframework:
return 'Flutter.xcframework';
case Artifact.flutterMacOSFramework:
return 'FlutterMacOS.framework';
case Artifact.vmSnapshotData:
@@ -208,8 +211,13 @@ abstract class Artifacts {
);
}
// Returns the requested [artifact] for the [platform] and [mode] combination.
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode });
/// Returns the requested [artifact] for the [platform], [mode], and [environmentType] combination.
String getArtifactPath(
Artifact artifact, {
TargetPlatform platform,
BuildMode mode,
EnvironmentType environmentType,
});
// Returns which set of engine artifacts is currently used for the [platform]
// and [mode] combination.
@@ -235,7 +243,12 @@ class CachedArtifacts implements Artifacts {
final Cache _cache;
@override
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
String getArtifactPath(
Artifact artifact, {
TargetPlatform platform,
BuildMode mode,
EnvironmentType environmentType,
}) {
switch (platform) {
case TargetPlatform.android_arm:
case TargetPlatform.android_arm64:
@@ -243,7 +256,7 @@ class CachedArtifacts implements Artifacts {
case TargetPlatform.android_x86:
return _getAndroidArtifactPath(artifact, platform, mode);
case TargetPlatform.ios:
return _getIosArtifactPath(artifact, platform, mode);
return _getIosArtifactPath(artifact, platform, mode, environmentType);
case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64:
@@ -288,10 +301,12 @@ class CachedArtifacts implements Artifacts {
}
}
String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
String _getIosArtifactPath(Artifact artifact, TargetPlatform platform,
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);
@@ -534,7 +549,12 @@ class LocalEngineArtifacts implements Artifacts {
final Platform _platform;
@override
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
String getArtifactPath(
Artifact artifact, {
TargetPlatform platform,
BuildMode mode,
EnvironmentType environmentType,
}) {
platform ??= _currentHostPlatform(_platform);
final bool isDirectoryArtifact = artifact == Artifact.flutterWebSdk || artifact == Artifact.flutterPatchedSdkPath;
final String artifactFileName = isDirectoryArtifact ? null : _artifactToFileName(artifact, platform, mode);
@@ -547,6 +567,8 @@ class LocalEngineArtifacts implements Artifacts {
case Artifact.vmSnapshotData:
return _fileSystem.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
case Artifact.icuData:
case Artifact.flutterXcframework:
case Artifact.flutterMacOSFramework:
return _fileSystem.path.join(engineOutPath, artifactFileName);
case Artifact.platformKernelDill:
if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
@@ -557,8 +579,6 @@ class LocalEngineArtifacts implements Artifacts {
return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName);
case Artifact.flutterFramework:
return _fileSystem.path.join(engineOutPath, artifactFileName);
case Artifact.flutterMacOSFramework:
return _fileSystem.path.join(engineOutPath, artifactFileName);
case Artifact.flutterPatchedSdkPath:
// When using local engine always use [BuildMode.debug] regardless of
// what was specified in [mode] argument because local engine will
@@ -712,7 +732,12 @@ class OverrideArtifacts implements Artifacts {
final File flutterPatchedSdk;
@override
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
String getArtifactPath(
Artifact artifact, {
TargetPlatform platform,
BuildMode mode,
EnvironmentType environmentType,
}) {
if (artifact == Artifact.frontendServerSnapshotForEngineDartSdk && frontendServer != null) {
return frontendServer.path;
}
@@ -725,7 +750,12 @@ class OverrideArtifacts implements Artifacts {
if (artifact == Artifact.flutterPatchedSdkPath && flutterPatchedSdk != null) {
return flutterPatchedSdk.path;
}
return parent.getArtifactPath(artifact, platform: platform, mode: mode);
return parent.getArtifactPath(
artifact,
platform: platform,
mode: mode,
environmentType: environmentType,
);
}
@override
@@ -742,7 +772,12 @@ String _dartSdkPath(FileSystem fileSystem) {
class _TestArtifacts implements Artifacts {
@override
String getArtifactPath(Artifact artifact, {TargetPlatform platform, BuildMode mode}) {
String getArtifactPath(
Artifact artifact, {
TargetPlatform platform,
BuildMode mode,
EnvironmentType environmentType,
}) {
final StringBuffer buffer = StringBuffer();
buffer.write(artifact);
if (platform != null) {
@@ -751,6 +786,9 @@ class _TestArtifacts implements Artifacts {
if (mode != null) {
buffer.write('.$mode');
}
if (environmentType != null) {
buffer.write('.$environmentType');
}
return buffer.toString();
}

View File

@@ -12,6 +12,7 @@ import '../../base/io.dart';
import '../../base/process.dart';
import '../../build_info.dart';
import '../../globals.dart' as globals hide fs, logger, processManager, artifacts;
import '../../macos/xcode.dart';
import '../../project.dart';
import '../build_system.dart';
import '../depfile.dart';
@@ -267,10 +268,16 @@ abstract class UnpackIOS extends Target {
@override
Future<void> build(Environment environment) async {
if (environment.defines[kSdkRoot] == null) {
throw MissingDefineException(kSdkRoot, name);
}
final Directory sdkRoot = environment.fileSystem.directory(environment.defines[kSdkRoot]);
final EnvironmentType environmentType = environmentTypeFromSdkroot(sdkRoot);
final String basePath = environment.artifacts.getArtifactPath(
Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: buildMode,
environmentType: environmentType,
);
final ProcessResult result = environment.processManager.runSync(<String>[

View File

@@ -459,7 +459,7 @@ end
// copy the corresponding engine.
// A plugin framework built with bitcode must link against the bitcode version
// of Flutter.framework (Release).
_project.ios.copyEngineArtifactToProject(mode);
_project.ios.copyEngineArtifactToProject(mode, EnvironmentType.physical);
final String bitcodeGenerationMode = mode == BuildMode.release ?
'bitcode' : 'marker'; // In release, force bitcode embedding without archiving.

View File

@@ -648,11 +648,11 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
ephemeralDirectory,
);
}
copyEngineArtifactToProject(BuildMode.debug);
copyEngineArtifactToProject(BuildMode.debug, EnvironmentType.physical);
}
}
void copyEngineArtifactToProject(BuildMode mode) {
void copyEngineArtifactToProject(BuildMode mode, EnvironmentType environmentType) {
// Copy framework from engine cache. The actual build mode
// doesn't actually matter as it will be overwritten by xcode_backend.sh.
// However, cocoapods will run before that script and requires something
@@ -662,6 +662,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: mode,
environmentType: environmentType,
)
);
if (framework.existsSync()) {