[flutter_tool] Teach the tool about local engine Fuchsia artifacts (#43759)
This commit is contained in:
@@ -61,8 +61,6 @@ enum Artifact {
|
||||
|
||||
// Fuchsia artifacts from the engine prebuilts.
|
||||
fuchsiaKernelCompiler,
|
||||
fuchsiaPlatformDill,
|
||||
fuchsiaPatchedSdk,
|
||||
fuchsiaFlutterJitRunner,
|
||||
}
|
||||
|
||||
@@ -138,10 +136,6 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
|
||||
return 'flutter_ddc_sdk.dill';
|
||||
case Artifact.fuchsiaKernelCompiler:
|
||||
return 'kernel_compiler.snapshot';
|
||||
case Artifact.fuchsiaPlatformDill:
|
||||
return 'platform_strong.dill';
|
||||
case Artifact.fuchsiaPatchedSdk:
|
||||
return 'flutter_runner_patched_sdk';
|
||||
case Artifact.fuchsiaFlutterJitRunner:
|
||||
if (mode == BuildMode.debug || mode == BuildMode.profile) {
|
||||
return 'flutter_jit_runner-0.far';
|
||||
@@ -245,18 +239,17 @@ class CachedArtifacts extends Artifacts {
|
||||
final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
|
||||
return fs.path.join(engineDir, hostPlatform, _artifactToFileName(artifact));
|
||||
default:
|
||||
assert(false, 'Artifact $artifact not available for platform $platform.');
|
||||
return null;
|
||||
return _getHostArtifactPath(artifact, platform, mode);
|
||||
}
|
||||
}
|
||||
|
||||
String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
switch (artifact) {
|
||||
case Artifact.genSnapshot:
|
||||
case Artifact.snapshotDart:
|
||||
case Artifact.flutterFramework:
|
||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
final String engineDir = _getEngineArtifactsPath(platform, mode);
|
||||
return fs.path.join(engineDir, artifactFileName);
|
||||
case Artifact.ideviceId:
|
||||
@@ -264,21 +257,23 @@ class CachedArtifacts extends Artifacts {
|
||||
case Artifact.idevicescreenshot:
|
||||
case Artifact.idevicesyslog:
|
||||
case Artifact.idevicename:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
return cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path;
|
||||
case Artifact.iosDeploy:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
return cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path;
|
||||
case Artifact.ideviceinstaller:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
return cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path;
|
||||
case Artifact.iproxy:
|
||||
final String artifactFileName = _artifactToFileName(artifact);
|
||||
return cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path;
|
||||
default:
|
||||
assert(false, 'Artifact $artifact not available for platform $platform.');
|
||||
return null;
|
||||
return _getHostArtifactPath(artifact, platform, mode);
|
||||
}
|
||||
}
|
||||
|
||||
String _getFuchsiaArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
|
||||
final String artifactFileName = _artifactToFileName(artifact, platform, mode);
|
||||
final String root = fs.path.join(
|
||||
cache.getArtifactDirectory('flutter_runner').path,
|
||||
'flutter',
|
||||
@@ -286,16 +281,20 @@ class CachedArtifacts extends Artifacts {
|
||||
getNameForBuildMode(mode),
|
||||
);
|
||||
switch (artifact) {
|
||||
case Artifact.fuchsiaKernelCompiler:
|
||||
return fs.path.join(root, 'jit', 'dart_binaries', artifactFileName);
|
||||
case Artifact.fuchsiaPlatformDill:
|
||||
case Artifact.flutterPatchedSdkPath:
|
||||
const String artifactFileName = 'flutter_runner_patched_sdk';
|
||||
return fs.path.join(root, 'jit', artifactFileName);
|
||||
case Artifact.platformKernelDill:
|
||||
final String artifactFileName = _artifactToFileName(artifact, platform, mode);
|
||||
return fs.path.join(root, 'jit', 'flutter_runner_patched_sdk', artifactFileName);
|
||||
case Artifact.fuchsiaPatchedSdk:
|
||||
case Artifact.fuchsiaKernelCompiler:
|
||||
final String artifactFileName = _artifactToFileName(artifact, platform, mode);
|
||||
return fs.path.join(root, 'jit', 'dart_binaries', artifactFileName);
|
||||
case Artifact.fuchsiaFlutterJitRunner:
|
||||
final String artifactFileName = _artifactToFileName(artifact, platform, mode);
|
||||
return fs.path.join(root, 'jit', artifactFileName);
|
||||
default:
|
||||
assert(false, 'Artifact $artifact not available for platform $platform.');
|
||||
return null;
|
||||
return _getHostArtifactPath(artifact, platform, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,6 +422,9 @@ class LocalEngineArtifacts extends Artifacts {
|
||||
case Artifact.vmSnapshotData:
|
||||
return fs.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
|
||||
case Artifact.platformKernelDill:
|
||||
if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
|
||||
return fs.path.join(engineOutPath, 'flutter_runner_patched_sdk', artifactFileName);
|
||||
}
|
||||
return fs.path.join(_getFlutterPatchedSdkPath(mode), artifactFileName);
|
||||
case Artifact.platformLibrariesJson:
|
||||
return fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName);
|
||||
@@ -435,6 +437,9 @@ class LocalEngineArtifacts extends Artifacts {
|
||||
// what was specified in [mode] argument because local engine will
|
||||
// have only one flutter_patched_sdk in standard location, that
|
||||
// is happen to be what debug(non-release) mode is using.
|
||||
if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
|
||||
return fs.path.join(engineOutPath, 'flutter_runner_patched_sdk');
|
||||
}
|
||||
return _getFlutterPatchedSdkPath(BuildMode.debug);
|
||||
case Artifact.flutterWebSdk:
|
||||
return _getFlutterWebSdkPath();
|
||||
@@ -473,11 +478,14 @@ class LocalEngineArtifacts extends Artifacts {
|
||||
case Artifact.webPlatformKernelDill:
|
||||
return fs.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
|
||||
case Artifact.fuchsiaKernelCompiler:
|
||||
case Artifact.fuchsiaPlatformDill:
|
||||
case Artifact.fuchsiaPatchedSdk:
|
||||
final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
|
||||
final String dartBinaries = 'dart_binaries-$mode-$hostPlatform';
|
||||
return fs.path.join(engineOutPath, 'host_bundle', dartBinaries, 'kernel_compiler.dart.snapshot');
|
||||
case Artifact.fuchsiaFlutterJitRunner:
|
||||
assert(false, 'Invalid local engine artifact $artifact.');
|
||||
return null;
|
||||
if (mode == BuildMode.debug || mode == BuildMode.profile) {
|
||||
return fs.path.join(engineOutPath, 'flutter_jit_runner-0.far');
|
||||
}
|
||||
return fs.path.join(engineOutPath, 'flutter_jit_product_runner-0.far');
|
||||
}
|
||||
assert(false, 'Invalid artifact $artifact.');
|
||||
return null;
|
||||
|
||||
@@ -575,6 +575,9 @@ class ExceptionMeasurement {
|
||||
final String target;
|
||||
final dynamic exception;
|
||||
final StackTrace stackTrace;
|
||||
|
||||
@override
|
||||
String toString() => 'target: $target\nexception:$exception\n$stackTrace';
|
||||
}
|
||||
|
||||
/// Helper class to collect measurement data.
|
||||
|
||||
@@ -207,19 +207,33 @@ class KernelSnapshot extends Target {
|
||||
if (environment.defines[kBuildMode] == null) {
|
||||
throw MissingDefineException(kBuildMode, 'kernel_snapshot');
|
||||
}
|
||||
if (environment.defines[kTargetPlatform] == null) {
|
||||
throw MissingDefineException(kTargetPlatform, 'kernel_snapshot');
|
||||
}
|
||||
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
||||
final String targetFile = environment.defines[kTargetFile] ?? fs.path.join('lib', 'main.dart');
|
||||
final String packagesPath = environment.projectDir.childFile('.packages').path;
|
||||
final String targetFileAbsolute = fs.file(targetFile).absolute.path;
|
||||
// everything besides 'false' is considered to be enabled.
|
||||
final bool trackWidgetCreation = environment.defines[kTrackWidgetCreation] != 'false';
|
||||
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
|
||||
|
||||
TargetModel targetModel = TargetModel.flutter;
|
||||
if (targetPlatform == TargetPlatform.fuchsia_x64 ||
|
||||
targetPlatform == TargetPlatform.fuchsia_arm64) {
|
||||
targetModel = TargetModel.flutterRunner;
|
||||
}
|
||||
|
||||
final CompilerOutput output = await compiler.compile(
|
||||
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
sdkRoot: artifacts.getArtifactPath(
|
||||
Artifact.flutterPatchedSdkPath,
|
||||
platform: targetPlatform,
|
||||
mode: buildMode,
|
||||
),
|
||||
aot: buildMode != BuildMode.debug,
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation && buildMode == BuildMode.debug,
|
||||
targetModel: TargetModel.flutter,
|
||||
targetModel: targetModel,
|
||||
outputFilePath: environment.buildDir.childFile('app.dill').path,
|
||||
packagesPath: packagesPath,
|
||||
linkPlatformKernelIn: buildMode == BuildMode.release,
|
||||
|
||||
@@ -171,10 +171,15 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
|
||||
String outputPath,
|
||||
String initializeFromDill,
|
||||
bool runCold = false,
|
||||
TargetPlatform targetPlatform,
|
||||
}) async {
|
||||
codeGenerator.updatePackages(flutterProject);
|
||||
final ResidentCompiler residentCompiler = ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
artifacts.getArtifactPath(
|
||||
Artifact.flutterPatchedSdkPath,
|
||||
platform: targetPlatform,
|
||||
mode: buildMode,
|
||||
),
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
||||
|
||||
@@ -432,24 +432,6 @@ class FuchsiaDevice extends Device {
|
||||
@override
|
||||
void clearLogs() {}
|
||||
|
||||
@override
|
||||
OverrideArtifacts get artifactOverrides {
|
||||
return _artifactOverrides ??= OverrideArtifacts(
|
||||
parent: Artifacts.instance,
|
||||
platformKernelDill: fs.file(artifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPlatformDill,
|
||||
platform: TargetPlatform.fuchsia_x64,
|
||||
mode: BuildMode.debug,
|
||||
)),
|
||||
flutterPatchedSdk: fs.file(artifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPatchedSdk,
|
||||
platform: TargetPlatform.fuchsia_x64,
|
||||
mode: BuildMode.debug,
|
||||
)),
|
||||
);
|
||||
}
|
||||
OverrideArtifacts _artifactOverrides;
|
||||
|
||||
@override
|
||||
bool get supportsScreenshot => false;
|
||||
|
||||
|
||||
@@ -38,13 +38,13 @@ class FuchsiaKernelCompiler {
|
||||
final String kernelCompiler = artifacts.getArtifactPath(
|
||||
Artifact.fuchsiaKernelCompiler,
|
||||
platform: TargetPlatform.fuchsia_x64, // This file is not arch-specific.
|
||||
mode: BuildMode.debug,
|
||||
mode: buildInfo.mode,
|
||||
);
|
||||
if (!fs.isFileSync(kernelCompiler)) {
|
||||
throwToolExit('Fuchisa kernel compiler not found at "$kernelCompiler"');
|
||||
}
|
||||
final String platformDill = artifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPlatformDill,
|
||||
Artifact.platformKernelDill,
|
||||
platform: TargetPlatform.fuchsia_x64, // This file is not arch-specific.
|
||||
mode: buildInfo.mode,
|
||||
);
|
||||
@@ -92,7 +92,7 @@ class FuchsiaKernelCompiler {
|
||||
|
||||
final List<String> command = <String>[
|
||||
artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||
artifacts.getArtifactPath(Artifact.fuchsiaKernelCompiler),
|
||||
kernelCompiler,
|
||||
...flags,
|
||||
];
|
||||
final Process process = await processUtils.start(command);
|
||||
|
||||
@@ -37,12 +37,17 @@ class FlutterDevice {
|
||||
this.fileSystemScheme,
|
||||
this.viewFilter,
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
TargetPlatform targetPlatform,
|
||||
List<String> experimentalFlags,
|
||||
ResidentCompiler generator,
|
||||
@required BuildMode buildMode,
|
||||
}) : assert(trackWidgetCreation != null),
|
||||
generator = generator ?? ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
artifacts.getArtifactPath(
|
||||
Artifact.flutterPatchedSdkPath,
|
||||
platform: targetPlatform,
|
||||
mode: buildMode,
|
||||
),
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
@@ -66,8 +71,12 @@ class FlutterDevice {
|
||||
ResidentCompiler generator,
|
||||
}) async {
|
||||
ResidentCompiler generator;
|
||||
final TargetPlatform targetPlatform = await device.targetPlatform;
|
||||
if (device.platformType == PlatformType.fuchsia) {
|
||||
targetModel = TargetModel.flutterRunner;
|
||||
}
|
||||
if (featureFlags.isWebIncrementalCompilerEnabled &&
|
||||
await device.targetPlatform == TargetPlatform.web_javascript) {
|
||||
targetPlatform == TargetPlatform.web_javascript) {
|
||||
generator = ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterWebSdk, mode: buildMode),
|
||||
buildMode: buildMode,
|
||||
@@ -80,12 +89,17 @@ class FlutterDevice {
|
||||
);
|
||||
} else if (flutterProject.hasBuilders) {
|
||||
generator = await CodeGeneratingResidentCompiler.create(
|
||||
targetPlatform: targetPlatform,
|
||||
buildMode: buildMode,
|
||||
flutterProject: flutterProject,
|
||||
);
|
||||
} else {
|
||||
generator = ResidentCompiler(
|
||||
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
|
||||
artifacts.getArtifactPath(
|
||||
Artifact.flutterPatchedSdkPath,
|
||||
platform: targetPlatform,
|
||||
mode: buildMode,
|
||||
),
|
||||
buildMode: buildMode,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
@@ -102,6 +116,7 @@ class FlutterDevice {
|
||||
viewFilter: viewFilter,
|
||||
experimentalFlags: experimentalFlags,
|
||||
targetModel: targetModel,
|
||||
targetPlatform: targetPlatform,
|
||||
generator: generator,
|
||||
buildMode: buildMode,
|
||||
);
|
||||
|
||||
@@ -231,6 +231,9 @@ class FakeDevice extends Fake implements Device {
|
||||
@override
|
||||
Future<TargetPlatform> get targetPlatform async => _targetPlatform;
|
||||
|
||||
@override
|
||||
final PlatformType platformType = PlatformType.ios;
|
||||
|
||||
@override
|
||||
Future<LaunchResult> startApp(
|
||||
ApplicationPackage package, {
|
||||
|
||||
@@ -236,7 +236,6 @@ flutter_tools:lib/''');
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
|
||||
test('aot_elf_profile throws error if missing target platform', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build(const AotElfProfile(),
|
||||
androidEnvironment..defines.remove(kTargetPlatform));
|
||||
@@ -244,7 +243,6 @@ flutter_tools:lib/''');
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
|
||||
test('aot_assembly_profile throws error if missing build mode', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build(const AotAssemblyProfile(),
|
||||
iosEnvironment..defines.remove(kBuildMode));
|
||||
|
||||
@@ -126,76 +126,6 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('Fuchsia device artifact overrides', () {
|
||||
MemoryFileSystem memoryFileSystem;
|
||||
File devFinder;
|
||||
File sshConfig;
|
||||
File platformDill;
|
||||
File patchedSdk;
|
||||
MockArtifacts mockArtifacts;
|
||||
|
||||
setUp(() {
|
||||
memoryFileSystem = MemoryFileSystem();
|
||||
devFinder = memoryFileSystem.file('dev_finder');
|
||||
sshConfig = memoryFileSystem.file('ssh_config');
|
||||
platformDill = memoryFileSystem.file('platform_strong.dill');
|
||||
patchedSdk = memoryFileSystem.file('flutter_runner_patched_sdk');
|
||||
|
||||
mockArtifacts = MockArtifacts();
|
||||
when(mockArtifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPlatformDill,
|
||||
platform: anyNamed('platform'),
|
||||
mode: anyNamed('mode'),
|
||||
)).thenReturn(platformDill.path);
|
||||
when(mockArtifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPatchedSdk,
|
||||
platform: anyNamed('platform'),
|
||||
mode: anyNamed('mode'),
|
||||
)).thenReturn(patchedSdk.path);
|
||||
});
|
||||
|
||||
testUsingContext('exist', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('fuchsia-device');
|
||||
expect(device.artifactOverrides, isNotNull);
|
||||
expect(device.artifactOverrides.platformKernelDill.path, equals(platformDill.path));
|
||||
expect(device.artifactOverrides.flutterPatchedSdk.path, equals(patchedSdk.path));
|
||||
}, overrides: <Type, Generator>{
|
||||
Artifacts: () => mockArtifacts,
|
||||
FileSystem: () => memoryFileSystem,
|
||||
FuchsiaArtifacts: () => FuchsiaArtifacts(
|
||||
sshConfig: sshConfig,
|
||||
devFinder: devFinder,
|
||||
),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('are used', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('fuchsia-device');
|
||||
expect(device.artifactOverrides, isNotNull);
|
||||
expect(device.artifactOverrides.platformKernelDill.path, equals(platformDill.path));
|
||||
expect(device.artifactOverrides.flutterPatchedSdk.path, equals(patchedSdk.path));
|
||||
await context.run<void>(
|
||||
body: () {
|
||||
expect(Artifacts.instance.getArtifactPath(Artifact.platformKernelDill),
|
||||
equals(platformDill.path));
|
||||
expect(Artifacts.instance.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
equals(patchedSdk.path));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Artifacts: () => device.artifactOverrides,
|
||||
},
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
Artifacts: () => mockArtifacts,
|
||||
FileSystem: () => memoryFileSystem,
|
||||
FuchsiaArtifacts: () => FuchsiaArtifacts(
|
||||
sshConfig: sshConfig,
|
||||
devFinder: devFinder,
|
||||
),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
});
|
||||
|
||||
group('displays friendly error when', () {
|
||||
MockProcessManager mockProcessManager;
|
||||
MockProcessResult mockProcessResult;
|
||||
@@ -480,12 +410,12 @@ void main() {
|
||||
mode: anyNamed('mode'),
|
||||
)).thenReturn(compilerSnapshot.path);
|
||||
when(mockArtifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPlatformDill,
|
||||
Artifact.platformKernelDill,
|
||||
platform: anyNamed('platform'),
|
||||
mode: anyNamed('mode'),
|
||||
)).thenReturn(platformDill.path);
|
||||
when(mockArtifacts.getArtifactPath(
|
||||
Artifact.fuchsiaPatchedSdk,
|
||||
Artifact.flutterPatchedSdkPath,
|
||||
platform: anyNamed('platform'),
|
||||
mode: anyNamed('mode'),
|
||||
)).thenReturn(patchedSdk.path);
|
||||
|
||||
Reference in New Issue
Block a user