From 030b110f69352332ed4e7550e15a03a8d382a8f8 Mon Sep 17 00:00:00 2001 From: "P.Y. Laligand" Date: Fri, 30 Sep 2016 10:23:33 -0700 Subject: [PATCH] New "build mojo" command to build flx files for Fuchsia. (#6112) --- .../flutter_tools/lib/src/commands/build.dart | 2 + .../lib/src/commands/build_mojo.dart | 78 +++++++++++++++++++ packages/flutter_tools/lib/src/flx.dart | 18 ++++- 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 packages/flutter_tools/lib/src/commands/build_mojo.dart diff --git a/packages/flutter_tools/lib/src/commands/build.dart b/packages/flutter_tools/lib/src/commands/build.dart index ace05fd846..d6b5676225 100644 --- a/packages/flutter_tools/lib/src/commands/build.dart +++ b/packages/flutter_tools/lib/src/commands/build.dart @@ -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 diff --git a/packages/flutter_tools/lib/src/commands/build_mojo.dart b/packages/flutter_tools/lib/src/commands/build_mojo.dart new file mode 100644 index 0000000000..e1e625162c --- /dev/null +++ b/packages/flutter_tools/lib/src/commands/build_mojo.dart @@ -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 _kOptions = const [ + _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 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; + }); + } +} diff --git a/packages/flutter_tools/lib/src/flx.dart b/packages/flutter_tools/lib/src/flx.dart index dc028845d6..c159c55c97 100644 --- a/packages/flutter_tools/lib/src/flx.dart +++ b/packages/flutter_tools/lib/src/flx.dart @@ -27,16 +27,20 @@ const String defaultPrivateKeyPath = 'privatekey.der'; const String _kSnapshotKey = 'snapshot_blob.bin'; Future 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 args = [ - tools.getHostToolPath(HostTool.SkySnapshot), - '--packages=${path.absolute(PackageMap.globalPackagesPath)}', + snapshotterPath, + '--packages=$packages', '--snapshot=$snapshotPath' ]; if (depfilePath != null) { @@ -67,6 +71,7 @@ Future buildFlx({ } Future build({ + String snapshotterPath, String mainPath: defaultMainPath, String manifestPath: defaultManifestPath, String outputPath, @@ -74,14 +79,17 @@ Future 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 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');