Commit 030b110f authored by P.Y. Laligand's avatar P.Y. Laligand Committed by GitHub

New "build mojo" command to build flx files for Fuchsia. (#6112)

parent 3b952d84
...@@ -15,6 +15,7 @@ import 'build_apk.dart'; ...@@ -15,6 +15,7 @@ import 'build_apk.dart';
import 'build_aot.dart'; import 'build_aot.dart';
import 'build_flx.dart'; import 'build_flx.dart';
import 'build_ios.dart'; import 'build_ios.dart';
import 'build_mojo.dart';
class BuildCommand extends FlutterCommand { class BuildCommand extends FlutterCommand {
BuildCommand({bool verboseHelp: false}) { BuildCommand({bool verboseHelp: false}) {
...@@ -23,6 +24,7 @@ class BuildCommand extends FlutterCommand { ...@@ -23,6 +24,7 @@ class BuildCommand extends FlutterCommand {
addSubcommand(new BuildCleanCommand()); addSubcommand(new BuildCleanCommand());
addSubcommand(new BuildIOSCommand()); addSubcommand(new BuildIOSCommand());
addSubcommand(new BuildFlxCommand(verboseHelp: verboseHelp)); addSubcommand(new BuildFlxCommand(verboseHelp: verboseHelp));
addSubcommand(new BuildMojoCommand());
} }
@override @override
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import '../flx.dart';
import '../globals.dart';
import 'build.dart';
const String _kOptionSnapshotter = 'snapshotter-path';
const String _kOptionTarget = 'target';
const String _kOptionPackages = 'packages';
const String _kOptionOutput = 'output-file';
const String _kOptionSnapshot = 'snapshot';
const String _kOptionDepfile = 'depfile';
const String _kOptionWorking = 'working-dir';
const List<String> _kOptions = const <String>[
_kOptionSnapshotter,
_kOptionTarget,
_kOptionPackages,
_kOptionOutput,
_kOptionSnapshot,
_kOptionDepfile,
_kOptionWorking
];
class BuildMojoCommand extends BuildSubCommand {
BuildMojoCommand({bool verboseHelp: false}) {
argParser.addOption(_kOptionSnapshotter,
help: 'The snapshotter executable');
argParser.addOption(_kOptionTarget, help: 'The entry point into the app');
argParser.addOption(_kOptionPackages, help: 'The .packages file');
argParser.addOption(_kOptionOutput, help: 'The generated flx file');
argParser.addOption(_kOptionSnapshot, help: 'The generated snapshot file');
argParser.addOption(_kOptionDepfile, help: 'The generated dependency file');
argParser.addOption(_kOptionWorking,
help: 'The directory where to put temporary files');
commandValidator = () => true;
}
@override
final String name = 'mojo';
@override
final String description = 'Build a Flutter FLX file for Mojo.';
@override
final String usageFooter =
'FLX files are archives of your application code and resources; '
'they are used by the Flutter content handler.';
@override
Future<int> runCommand() async {
await super.runCommand();
if (_kOptions
.any((String option) => !argResults.options.contains(option))) {
printError('Missing option! All options must be specified.');
return 1;
}
String outputPath = argResults[_kOptionOutput];
return await build(
snapshotterPath: argResults[_kOptionSnapshotter],
mainPath: argResults[_kOptionTarget],
outputPath: outputPath,
snapshotPath: argResults[_kOptionSnapshot],
depfilePath: argResults[_kOptionDepfile],
workingDirPath: argResults[_kOptionWorking],
packagesPath: argResults[_kOptionPackages],
includeRobotoFonts: true,
).then((int result) {
if (result != 0) {
printError('Error building $outputPath: $result.');
}
return result;
});
}
}
...@@ -27,16 +27,20 @@ const String defaultPrivateKeyPath = 'privatekey.der'; ...@@ -27,16 +27,20 @@ const String defaultPrivateKeyPath = 'privatekey.der';
const String _kSnapshotKey = 'snapshot_blob.bin'; const String _kSnapshotKey = 'snapshot_blob.bin';
Future<int> createSnapshot({ Future<int> createSnapshot({
String snapshotterPath,
String mainPath, String mainPath,
String snapshotPath, String snapshotPath,
String depfilePath String depfilePath,
String packages
}) { }) {
assert(snapshotterPath != null);
assert(mainPath != null); assert(mainPath != null);
assert(snapshotPath != null); assert(snapshotPath != null);
assert(packages != null);
final List<String> args = <String>[ final List<String> args = <String>[
tools.getHostToolPath(HostTool.SkySnapshot), snapshotterPath,
'--packages=${path.absolute(PackageMap.globalPackagesPath)}', '--packages=$packages',
'--snapshot=$snapshotPath' '--snapshot=$snapshotPath'
]; ];
if (depfilePath != null) { if (depfilePath != null) {
...@@ -67,6 +71,7 @@ Future<String> buildFlx({ ...@@ -67,6 +71,7 @@ Future<String> buildFlx({
} }
Future<int> build({ Future<int> build({
String snapshotterPath,
String mainPath: defaultMainPath, String mainPath: defaultMainPath,
String manifestPath: defaultManifestPath, String manifestPath: defaultManifestPath,
String outputPath, String outputPath,
...@@ -74,14 +79,17 @@ Future<int> build({ ...@@ -74,14 +79,17 @@ Future<int> build({
String depfilePath, String depfilePath,
String privateKeyPath: defaultPrivateKeyPath, String privateKeyPath: defaultPrivateKeyPath,
String workingDirPath, String workingDirPath,
String packagesPath,
bool precompiledSnapshot: false, bool precompiledSnapshot: false,
bool includeRobotoFonts: true, bool includeRobotoFonts: true,
bool reportLicensedPackages: false bool reportLicensedPackages: false
}) async { }) async {
snapshotterPath ??= tools.getHostToolPath(HostTool.SkySnapshot);
outputPath ??= defaultFlxOutputPath; outputPath ??= defaultFlxOutputPath;
snapshotPath ??= defaultSnapshotPath; snapshotPath ??= defaultSnapshotPath;
depfilePath ??= defaultDepfilePath; depfilePath ??= defaultDepfilePath;
workingDirPath ??= getAssetBuildDirectory(); workingDirPath ??= getAssetBuildDirectory();
packagesPath ??= path.absolute(PackageMap.globalPackagesPath);
File snapshotFile; File snapshotFile;
if (!precompiledSnapshot) { if (!precompiledSnapshot) {
...@@ -90,9 +98,11 @@ Future<int> build({ ...@@ -90,9 +98,11 @@ Future<int> build({
// In a precompiled snapshot, the instruction buffer contains script // In a precompiled snapshot, the instruction buffer contains script
// content equivalents // content equivalents
int result = await createSnapshot( int result = await createSnapshot(
snapshotterPath: snapshotterPath,
mainPath: mainPath, mainPath: mainPath,
snapshotPath: snapshotPath, snapshotPath: snapshotPath,
depfilePath: depfilePath depfilePath: depfilePath,
packages: packagesPath
); );
if (result != 0) { if (result != 0) {
printError('Failed to run the Flutter compiler. Exit code: $result'); printError('Failed to run the Flutter compiler. Exit code: $result');
......
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