mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
New "build mojo" command to build flx files for Fuchsia. (#6112)
This commit is contained in:
parent
3b952d8456
commit
030b110f69
@ -15,6 +15,7 @@ import 'build_apk.dart';
|
||||
import 'build_aot.dart';
|
||||
import 'build_flx.dart';
|
||||
import 'build_ios.dart';
|
||||
import 'build_mojo.dart';
|
||||
|
||||
class BuildCommand extends FlutterCommand {
|
||||
BuildCommand({bool verboseHelp: false}) {
|
||||
@ -23,6 +24,7 @@ class BuildCommand extends FlutterCommand {
|
||||
addSubcommand(new BuildCleanCommand());
|
||||
addSubcommand(new BuildIOSCommand());
|
||||
addSubcommand(new BuildFlxCommand(verboseHelp: verboseHelp));
|
||||
addSubcommand(new BuildMojoCommand());
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
78
packages/flutter_tools/lib/src/commands/build_mojo.dart
Normal file
78
packages/flutter_tools/lib/src/commands/build_mojo.dart
Normal file
@ -0,0 +1,78 @@
|
||||
// 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';
|
||||
const String _kSnapshotKey = 'snapshot_blob.bin';
|
||||
|
||||
Future<int> createSnapshot({
|
||||
String snapshotterPath,
|
||||
String mainPath,
|
||||
String snapshotPath,
|
||||
String depfilePath
|
||||
String depfilePath,
|
||||
String packages
|
||||
}) {
|
||||
assert(snapshotterPath != null);
|
||||
assert(mainPath != null);
|
||||
assert(snapshotPath != null);
|
||||
assert(packages != null);
|
||||
|
||||
final List<String> args = <String>[
|
||||
tools.getHostToolPath(HostTool.SkySnapshot),
|
||||
'--packages=${path.absolute(PackageMap.globalPackagesPath)}',
|
||||
snapshotterPath,
|
||||
'--packages=$packages',
|
||||
'--snapshot=$snapshotPath'
|
||||
];
|
||||
if (depfilePath != null) {
|
||||
@ -67,6 +71,7 @@ Future<String> buildFlx({
|
||||
}
|
||||
|
||||
Future<int> build({
|
||||
String snapshotterPath,
|
||||
String mainPath: defaultMainPath,
|
||||
String manifestPath: defaultManifestPath,
|
||||
String outputPath,
|
||||
@ -74,14 +79,17 @@ Future<int> build({
|
||||
String depfilePath,
|
||||
String privateKeyPath: defaultPrivateKeyPath,
|
||||
String workingDirPath,
|
||||
String packagesPath,
|
||||
bool precompiledSnapshot: false,
|
||||
bool includeRobotoFonts: true,
|
||||
bool reportLicensedPackages: false
|
||||
}) async {
|
||||
snapshotterPath ??= tools.getHostToolPath(HostTool.SkySnapshot);
|
||||
outputPath ??= defaultFlxOutputPath;
|
||||
snapshotPath ??= defaultSnapshotPath;
|
||||
depfilePath ??= defaultDepfilePath;
|
||||
workingDirPath ??= getAssetBuildDirectory();
|
||||
packagesPath ??= path.absolute(PackageMap.globalPackagesPath);
|
||||
File snapshotFile;
|
||||
|
||||
if (!precompiledSnapshot) {
|
||||
@ -90,9 +98,11 @@ Future<int> build({
|
||||
// In a precompiled snapshot, the instruction buffer contains script
|
||||
// content equivalents
|
||||
int result = await createSnapshot(
|
||||
snapshotterPath: snapshotterPath,
|
||||
mainPath: mainPath,
|
||||
snapshotPath: snapshotPath,
|
||||
depfilePath: depfilePath
|
||||
depfilePath: depfilePath,
|
||||
packages: packagesPath
|
||||
);
|
||||
if (result != 0) {
|
||||
printError('Failed to run the Flutter compiler. Exit code: $result');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user