[flutter_tool] Use engine flutter_runner prebuilts (#43381)

* [flutter_tool] Use engine flutter_runner prebuilts

* Update packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart

Co-Authored-By: Jonah Williams <jonahwilliams@google.com>
This commit is contained in:
Zachary Anderson
2019-10-28 09:38:08 -07:00
committed by GitHub
parent ab260bacd2
commit 0dfabb2ae1
15 changed files with 371 additions and 124 deletions

View File

@@ -69,7 +69,8 @@ class ApplicationPackageFactory {
return applicationBinary == null
? WindowsApp.fromWindowsProject(FlutterProject.current().windows)
: WindowsApp.fromPrebuiltApp(applicationBinary);
case TargetPlatform.fuchsia:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
return applicationBinary == null
? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia)
: FuchsiaApp.fromPrebuiltApp(applicationBinary);
@@ -424,7 +425,8 @@ class ApplicationPackageStore {
case TargetPlatform.ios:
iOS ??= await IOSApp.fromIosProject(FlutterProject.current().ios);
return iOS;
case TargetPlatform.fuchsia:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
fuchsia ??= FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia);
return fuchsia;
case TargetPlatform.darwin_x64:

View File

@@ -58,6 +58,12 @@ enum Artifact {
skyEnginePath,
/// The location of the macOS engine podspec file.
flutterMacOSPodspec,
// Fuchsia artifacts from the engine prebuilts.
fuchsiaKernelCompiler,
fuchsiaPlatformDill,
fuchsiaPatchedSdk,
fuchsiaFlutterJitRunner,
}
String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
@@ -130,6 +136,17 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
return 'FlutterMacOS.podspec';
case Artifact.webPlatformKernelDill:
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';
}
return 'flutter_jit_product_runner-0.far';
}
assert(false, 'Invalid artifact $artifact.');
return null;
@@ -190,8 +207,10 @@ class CachedArtifacts extends Artifacts {
return _getIosArtifactPath(artifact, platform, mode);
case TargetPlatform.darwin_x64:
return _getDarwinArtifactPath(artifact, platform, mode);
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
return _getFuchsiaArtifactPath(artifact, platform, mode);
case TargetPlatform.linux_x64:
case TargetPlatform.fuchsia:
case TargetPlatform.windows_x64:
case TargetPlatform.tester:
case TargetPlatform.web_javascript:
@@ -258,6 +277,28 @@ class CachedArtifacts extends Artifacts {
}
}
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',
fuchsiaArchForTargetPlatform(platform),
getNameForBuildMode(mode),
);
switch (artifact) {
case Artifact.fuchsiaKernelCompiler:
return fs.path.join(root, 'jit', 'dart_binaries', artifactFileName);
case Artifact.fuchsiaPlatformDill:
return fs.path.join(root, 'jit', 'flutter_runner_patched_sdk', artifactFileName);
case Artifact.fuchsiaPatchedSdk:
case Artifact.fuchsiaFlutterJitRunner:
return fs.path.join(root, 'jit', artifactFileName);
default:
assert(false, 'Artifact $artifact not available for platform $platform.');
return null;
}
}
String _getFlutterPatchedSdkPath(BuildMode mode) {
final String engineArtifactsPath = cache.getArtifactDirectory('engine').path;
return fs.path.join(engineArtifactsPath, 'common',
@@ -339,7 +380,8 @@ class CachedArtifacts extends Artifacts {
}
final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : '';
return fs.path.join(engineDir, platformName + suffix);
case TargetPlatform.fuchsia:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
case TargetPlatform.web_javascript:
assert(mode == null, 'Platform $platform does not support different build modes.');
@@ -430,6 +472,12 @@ class LocalEngineArtifacts extends Artifacts {
return fs.path.join(_hostEngineOutPath, _artifactToFileName(artifact));
case Artifact.webPlatformKernelDill:
return fs.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
case Artifact.fuchsiaKernelCompiler:
case Artifact.fuchsiaPlatformDill:
case Artifact.fuchsiaPatchedSdk:
case Artifact.fuchsiaFlutterJitRunner:
assert(false, 'Invalid local engine artifact $artifact.');
return null;
}
assert(false, 'Invalid artifact $artifact.');
return null;

View File

@@ -314,7 +314,8 @@ enum TargetPlatform {
darwin_x64,
linux_x64,
windows_x64,
fuchsia,
fuchsia_arm64,
fuchsia_x64,
tester,
web_javascript,
}
@@ -382,8 +383,10 @@ String getNameForTargetPlatform(TargetPlatform platform) {
return 'linux-x64';
case TargetPlatform.windows_x64:
return 'windows-x64';
case TargetPlatform.fuchsia:
return 'fuchsia';
case TargetPlatform.fuchsia_arm64:
return 'fuchsia-arm64';
case TargetPlatform.fuchsia_x64:
return 'fuchsia-x64';
case TargetPlatform.tester:
return 'flutter-tester';
case TargetPlatform.web_javascript:
@@ -403,6 +406,10 @@ TargetPlatform getTargetPlatformForName(String platform) {
return TargetPlatform.android_x64;
case 'android-x86':
return TargetPlatform.android_x86;
case 'fuchsia-arm64':
return TargetPlatform.fuchsia_arm64;
case 'fuchsia-x64':
return TargetPlatform.fuchsia_x64;
case 'ios':
return TargetPlatform.ios;
case 'darwin-x64':
@@ -463,6 +470,18 @@ String getPlatformNameForAndroidArch(AndroidArch arch) {
return null;
}
String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) {
switch (targetPlatform) {
case TargetPlatform.fuchsia_arm64:
return 'arm64';
case TargetPlatform.fuchsia_x64:
return 'x64';
default:
assert(false);
return null;
}
}
HostPlatform getCurrentHostPlatform() {
if (platform.isMacOS) {
return HostPlatform.darwin_x64;

View File

@@ -10,6 +10,7 @@ import '../base/platform.dart';
import '../build_info.dart';
import '../cache.dart';
import '../fuchsia/fuchsia_build.dart';
import '../fuchsia/fuchsia_pm.dart';
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';
@@ -19,6 +20,17 @@ class BuildFuchsiaCommand extends BuildSubCommand {
BuildFuchsiaCommand({bool verboseHelp = false}) {
usesTargetOption();
addBuildModeFlags(verboseHelp: verboseHelp);
argParser.addOption(
'runner-source',
help: 'The package source to use for the flutter_runner. '
'"${FuchsiaPackageServer.deviceHost}" implies using a runner already on the device. '
'"${FuchsiaPackageServer.toolHost}" implies using a runner distributed with Flutter.',
allowed: <String>[
FuchsiaPackageServer.deviceHost,
FuchsiaPackageServer.toolHost,
],
defaultsTo: FuchsiaPackageServer.toolHost,
);
}
@override
@@ -34,7 +46,7 @@ class BuildFuchsiaCommand extends BuildSubCommand {
};
@override
String get description => 'build the Fuchsia target (Experimental).';
String get description => 'Build the Fuchsia target (Experimental).';
@override
Future<FlutterCommandResult> runCommand() async {
@@ -42,22 +54,24 @@ class BuildFuchsiaCommand extends BuildSubCommand {
final BuildInfo buildInfo = getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
if (!platform.isLinux && !platform.isMacOS) {
throwToolExit('"build Fuchsia" only supported on Linux and MacOS hosts.');
throwToolExit('"build fuchsia" is only supported on Linux and MacOS hosts.');
}
if (!flutterProject.fuchsia.existsSync()) {
throwToolExit('No Fuchsia project configured.');
throwToolExit('No Fuchsia project is configured.');
}
final String appName = flutterProject.fuchsia.project.manifest.appName;
final String cmxPath = fs.path.join(
flutterProject.fuchsia.meta.path, '$appName.cmx');
final File cmxFile = fs.file(cmxPath);
if (!cmxFile.existsSync()) {
throwToolExit('Fuchsia build requires a .cmx file at $cmxPath for the app');
throwToolExit('The Fuchsia build requires a .cmx file at $cmxPath for the app.');
}
await buildFuchsia(
fuchsiaProject: flutterProject.fuchsia,
target: targetFile,
buildInfo: buildInfo);
fuchsiaProject: flutterProject.fuchsia,
target: targetFile,
buildInfo: buildInfo,
runnerPackageSource: argResults['runner-source'],
);
return null;
}
}

View File

@@ -178,7 +178,8 @@ class DeviceManager {
if (hasSpecifiedAllDevices) {
devices = <Device>[
for (Device device in devices)
if (await device.targetPlatform != TargetPlatform.fuchsia &&
if (await device.targetPlatform != TargetPlatform.fuchsia_arm64 &&
await device.targetPlatform != TargetPlatform.fuchsia_x64 &&
await device.targetPlatform != TargetPlatform.web_javascript)
device,
];
@@ -339,7 +340,8 @@ abstract class Device {
case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64:
case TargetPlatform.fuchsia:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
default:
return false;
}

View File

@@ -38,6 +38,7 @@ Future<void> buildFuchsia({
@required FuchsiaProject fuchsiaProject,
@required String target, // E.g., lib/main.dart
BuildInfo buildInfo = BuildInfo.debug,
String runnerPackageSource = FuchsiaPackageServer.toolHost,
}) async {
final Directory outDir = fs.directory(getFuchsiaBuildDirectory());
if (!outDir.existsSync()) {
@@ -50,7 +51,7 @@ Future<void> buildFuchsia({
await _timedBuildStep('fuchsia-build-assets',
() => _buildAssets(fuchsiaProject, target, buildInfo));
await _timedBuildStep('fuchsia-build-package',
() => _buildPackage(fuchsiaProject, target, buildInfo));
() => _buildPackage(fuchsiaProject, target, buildInfo, runnerPackageSource));
}
Future<void> _buildAssets(
@@ -85,7 +86,7 @@ Future<void> _buildAssets(
await outFile.close();
}
void _rewriteCmx(BuildMode mode, File src, File dst) {
void _rewriteCmx(BuildMode mode, String runnerPackageSource, File src, File dst) {
final Map<String, dynamic> cmx = json.decode(src.readAsStringSync());
// If the app author has already specified the runner in the cmx file, then
// do not override it with something else.
@@ -106,7 +107,7 @@ void _rewriteCmx(BuildMode mode, File src, File dst) {
throwToolExit('Fuchsia does not support build mode "$mode"');
break;
}
cmx['runner'] = 'fuchsia-pkg://fuchsia.com/$runner#meta/$runner.cmx';
cmx['runner'] = 'fuchsia-pkg://$runnerPackageSource/$runner#meta/$runner.cmx';
dst.writeAsStringSync(json.encode(cmx));
}
@@ -115,6 +116,7 @@ Future<void> _buildPackage(
FuchsiaProject fuchsiaProject,
String target, // lib/main.dart
BuildInfo buildInfo,
String runnerPackageSource,
) async {
final String outDir = getFuchsiaBuildDirectory();
final String pkgDir = fs.path.join(outDir, 'pkg');
@@ -132,7 +134,7 @@ Future<void> _buildPackage(
final File srcCmx =
fs.file(fs.path.join(fuchsiaProject.meta.path, '$appName.cmx'));
final File dstCmx = fs.file(fs.path.join(outDir, '$appName.cmx'));
_rewriteCmx(buildInfo.mode, srcCmx, dstCmx);
_rewriteCmx(buildInfo.mode, runnerPackageSource, srcCmx, dstCmx);
// Concatenate dilpmanifest and pkgassets into package_manifest.
final File manifestFile = fs.file(packageManifest);

View File

@@ -272,13 +272,15 @@ class FuchsiaDevice extends Device {
}
// Start up a package server.
const String packageServerName = 'flutter_tool';
const String packageServerName = FuchsiaPackageServer.toolHost;
fuchsiaPackageServer = FuchsiaPackageServer(
packageRepo.path, packageServerName, host, port);
if (!await fuchsiaPackageServer.start()) {
printError('Failed to start the Fuchsia package server');
return LaunchResult.failed();
}
// Serve the application's package.
final File farArchive = package.farArchive(
debuggingOptions.buildInfo.mode);
if (!await fuchsiaPackageServer.addPackage(farArchive)) {
@@ -286,6 +288,17 @@ class FuchsiaDevice extends Device {
return LaunchResult.failed();
}
// Serve the flutter_runner.
final File flutterRunnerArchive = fs.file(artifacts.getArtifactPath(
Artifact.fuchsiaFlutterJitRunner,
platform: await targetPlatform,
mode: debuggingOptions.buildInfo.mode,
));
if (!await fuchsiaPackageServer.addPackage(flutterRunnerArchive)) {
printError('Failed to add flutter_runner package to the package server');
return LaunchResult.failed();
}
// Teach the package controller about the package server.
if (!await fuchsiaDeviceTools.amberCtl.addRepoCfg(this, fuchsiaPackageServer)) {
printError('Failed to teach amber about the package server');
@@ -293,6 +306,18 @@ class FuchsiaDevice extends Device {
}
serverRegistered = true;
// Tell the package controller to prefetch the flutter_runner.
String flutterRunnerName = 'flutter_jit_runner';
if (!debuggingOptions.buildInfo.isDebug &&
!debuggingOptions.buildInfo.isProfile) {
flutterRunnerName = 'flutter_jit_product_runner';
}
if (!await fuchsiaDeviceTools.amberCtl.pkgCtlResolve(
this, fuchsiaPackageServer, flutterRunnerName)) {
printError('Failed to get pkgctl to prefetch the flutter_runner');
return LaunchResult.failed();
}
// Tell the package controller to prefetch the app.
if (!await fuchsiaDeviceTools.amberCtl.pkgCtlResolve(
this, fuchsiaPackageServer, appName)) {
@@ -353,8 +378,30 @@ class FuchsiaDevice extends Device {
return true;
}
TargetPlatform _targetPlatform;
Future<TargetPlatform> _queryTargetPlatform() async {
final RunResult result = await shell('uname -m');
if (result.exitCode != 0) {
printError('Could not determine Fuchsia target platform type:\n$result\n'
'Defaulting to arm64.');
return TargetPlatform.fuchsia_arm64;
}
final String machine = result.stdout.trim();
switch (machine) {
case 'aarch64':
return TargetPlatform.fuchsia_arm64;
case 'x86_64':
return TargetPlatform.fuchsia_x64;
default:
printError('Unknown Fuchsia target platform "$machine". '
'Defaulting to arm64.');
return TargetPlatform.fuchsia_arm64;
}
}
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.fuchsia;
Future<TargetPlatform> get targetPlatform async => _targetPlatform ??= await _queryTargetPlatform();
@override
Future<String> get sdkNameAndVersion async {
@@ -389,8 +436,16 @@ class FuchsiaDevice extends Device {
OverrideArtifacts get artifactOverrides {
return _artifactOverrides ??= OverrideArtifacts(
parent: Artifacts.instance,
platformKernelDill: fuchsiaArtifacts.platformKernelDill,
flutterPatchedSdk: fuchsiaArtifacts.flutterPatchedSdk,
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;
@@ -535,7 +590,7 @@ class FuchsiaIsolateDiscoveryProtocol {
'Waiting for a connection from $_isolateName on ${_device.name}...',
timeout: null, // could take an arbitrary amount of time
);
_pollingTimer ??= Timer(_pollDuration, _findIsolate);
unawaited(_findIsolate()); // Completes the _foundUri Future.
return _foundUri.future.then((Uri uri) {
_uri = uri;
return uri;

View File

@@ -15,8 +15,6 @@ import '../convert.dart';
import '../globals.dart';
import '../project.dart';
import 'fuchsia_sdk.dart';
/// This is a simple wrapper around the custom kernel compiler from the Fuchsia
/// SDK.
class FuchsiaKernelCompiler {
@@ -30,20 +28,32 @@ class FuchsiaKernelCompiler {
BuildInfo buildInfo = BuildInfo.debug,
}) async {
// TODO(zra): Use filesystem root and scheme information from buildInfo.
if (fuchsiaArtifacts.kernelCompiler == null) {
throwToolExit('Fuchisa kernel compiler not found');
}
const String multiRootScheme = 'main-root';
final String packagesFile = fuchsiaProject.project.packagesFile.path;
final String outDir = getFuchsiaBuildDirectory();
final String appName = fuchsiaProject.project.manifest.appName;
final String fsRoot = fuchsiaProject.project.directory.path;
final String relativePackagesFile =
fs.path.relative(packagesFile, from: fsRoot);
final String relativePackagesFile = fs.path.relative(packagesFile, from: fsRoot);
final String manifestPath = fs.path.join(outDir, '$appName.dilpmanifest');
final String kernelCompiler = artifacts.getArtifactPath(
Artifact.fuchsiaKernelCompiler,
platform: TargetPlatform.fuchsia_x64, // This file is not arch-specific.
mode: BuildMode.debug,
);
if (!fs.isFileSync(kernelCompiler)) {
throwToolExit('Fuchisa kernel compiler not found at "$kernelCompiler"');
}
final String platformDill = artifacts.getArtifactPath(
Artifact.fuchsiaPlatformDill,
platform: TargetPlatform.fuchsia_x64, // This file is not arch-specific.
mode: buildInfo.mode,
);
if (!fs.isFileSync(platformDill)) {
throwToolExit('Fuchisa platform file not found at "$platformDill"');
}
List<String> flags = <String>[
'--target', 'flutter_runner',
'--platform', fuchsiaArtifacts.platformKernelDill.path,
'--platform', platformDill,
'--filesystem-scheme', 'main-root',
'--filesystem-root', fsRoot,
'--packages', '$multiRootScheme:///$relativePackagesFile',
@@ -82,7 +92,7 @@ class FuchsiaKernelCompiler {
final List<String> command = <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
fuchsiaArtifacts.kernelCompiler.path,
artifacts.getArtifactPath(Artifact.fuchsiaKernelCompiler),
...flags,
];
final Process process = await processUtils.start(command);

View File

@@ -178,6 +178,9 @@ class FuchsiaPM {
class FuchsiaPackageServer {
FuchsiaPackageServer(this._repo, this.name, this._host, this._port);
static const String deviceHost = 'fuchsia.com';
static const String toolHost = 'flutter_tool';
final String _repo;
final String _host;
final int _port;

View File

@@ -102,9 +102,6 @@ class FuchsiaArtifacts {
FuchsiaArtifacts({
this.sshConfig,
this.devFinder,
this.platformKernelDill,
this.flutterPatchedSdk,
this.kernelCompiler,
this.pm,
});
@@ -119,19 +116,6 @@ class FuchsiaArtifacts {
// Don't try to find the artifacts on platforms that are not supported.
return FuchsiaArtifacts();
}
final String fuchsia = Cache.instance.getArtifactDirectory('fuchsia').path;
final String tools = fs.path.join(fuchsia, 'tools');
final String dartPrebuilts = fs.path.join(tools, 'dart_prebuilts');
final File devFinder = fs.file(fs.path.join(tools, 'dev_finder'));
final File platformDill = fs.file(fs.path.join(
dartPrebuilts, 'flutter_runner', 'platform_strong.dill'));
final File patchedSdk = fs.file(fs.path.join(
dartPrebuilts, 'flutter_runner'));
final File kernelCompiler = fs.file(fs.path.join(
dartPrebuilts, 'kernel_compiler.snapshot'));
final File pm = fs.file(fs.path.join(tools, 'pm'));
// If FUCHSIA_BUILD_DIR is defined, then look for the ssh_config dir
// relative to it. Next, if FUCHSIA_SSH_CONFIG is defined, then use it.
// TODO(zra): Consider passing the ssh config path in with a flag.
@@ -142,12 +126,15 @@ class FuchsiaArtifacts {
} else if (platform.environment.containsKey(_kFuchsiaSshConfig)) {
sshConfig = fs.file(platform.environment[_kFuchsiaSshConfig]);
}
final String fuchsia = Cache.instance.getArtifactDirectory('fuchsia').path;
final String tools = fs.path.join(fuchsia, 'tools');
final File devFinder = fs.file(fs.path.join(tools, 'dev_finder'));
final File pm = fs.file(fs.path.join(tools, 'pm'));
return FuchsiaArtifacts(
sshConfig: sshConfig,
devFinder: devFinder.existsSync() ? devFinder : null,
platformKernelDill: platformDill.existsSync() ? platformDill : null,
flutterPatchedSdk: patchedSdk.existsSync() ? patchedSdk : null,
kernelCompiler: kernelCompiler.existsSync() ? kernelCompiler : null,
pm: pm.existsSync() ? pm : null,
);
}
@@ -163,15 +150,6 @@ class FuchsiaArtifacts {
/// Fuchsia devices.
final File devFinder;
/// The location of the Fuchsia-specific platform dill.
final File platformKernelDill;
/// The directory containing [platformKernelDill].
final File flutterPatchedSdk;
/// The snapshot of the Fuchsia kernel compiler.
final File kernelCompiler;
/// The pm tool.
final File pm;
}

View File

@@ -734,7 +734,8 @@ DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) {
return DevelopmentArtifact.linux;
}
return null;
case TargetPlatform.fuchsia:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
// No artifacts currently supported.
return null;