From b5d6b9ae0da280265b1b4377a3e05121e263a497 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 2 Jul 2015 17:07:44 -0700 Subject: [PATCH] Add skyx packages for all the Sky demos (except game) This CL factors the skyx build logic out of sky/apk/rules.gni so that we can build skyx bundles without building entire APKs. This change makes it possible to build skyx bundles for all the examples (except game). TBR=eseidel@google.com Review URL: https://codereview.chromium.org/1222673003. --- engine/src/flutter/build/skyx.gni | 106 ++++++++++++++++++++ engine/src/flutter/tools/skyx.py | 12 ++- engine/src/flutter/tools/skyx/bin/skyx.dart | 8 +- 3 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 engine/src/flutter/build/skyx.gni diff --git a/engine/src/flutter/build/skyx.gni b/engine/src/flutter/build/skyx.gni new file mode 100644 index 0000000000..2306558d20 --- /dev/null +++ b/engine/src/flutter/build/skyx.gni @@ -0,0 +1,106 @@ +# Copyright 2015 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. + +declare_args() { + # Controls whether we build app.skyx bundles in the sky_app template below. + # An app.skyx bundle contains all the code an resources needed to run a Sky + # app offline. Unfortunately, we don't yet have all the Dart packages we need + # to create skyx packages installed on the build bots, so this functionality + # is currently disabled. This flag allows for local testing of this feature. + enable_skyx = false +} + +package_root = "$root_gen_dir/dart-pkg/packages" + +template("skyx") { + bundle_prefix = target_name + bundle = "$target_gen_dir/${bundle_prefix}.skyx" + snapshot = "$target_gen_dir/${bundle_prefix}_snapshot.bin" + + action("gen_${bundle_prefix}_snapshot") { + main_dart = invoker.main_dart + + inputs = [ + main_dart, + ] + outputs = [ + snapshot, + ] + + if (defined(invoker.sources)) { + inputs += sources + } + + sky_packager_dir = + get_label_info("//sky/tools/packager($host_toolchain)", "root_out_dir") + + script = "//sky/tools/sky_packager.py" + + src_dir = "//" + cwd = rebase_path(src_dir, root_build_dir) + + args = [ + rebase_path("$sky_packager_dir/sky_packager", src_dir), + rebase_path(main_dart, src_dir), + "--package-root", + rebase_path(package_root, src_dir), + "--snapshot", + rebase_path(snapshot, src_dir), + "-C", + cwd, + ] + + deps = [ + "//sky/tools/packager($host_toolchain)", + "//sky/sdk", + ] + + if (defined(invoker.deps)) { + deps += invoker.deps + } + } + + action("gen_${bundle_prefix}_bundle") { + asset_base = "$package_root/sky/assets/material-design-icons" + + sources = [ + "//sky/tools/skyx/bin/skyx.dart", + snapshot, + ] + + outputs = [ + bundle, + ] + + script = "//sky/tools/skyx.py" + args = [ + "--asset-base", + rebase_path(asset_base, root_build_dir), + "--snapshot", + rebase_path(snapshot, root_build_dir), + "-o", + rebase_path(bundle, root_build_dir), + ] + + if (defined(invoker.manifest)) { + sources += [ invoker.manifest ] + args += [ + "--manifest", + rebase_path(invoker.manifest, root_build_dir), + ] + } + + deps = [ + ":gen_${bundle_prefix}_snapshot", + ] + } + + group(target_name) { + if (enable_skyx) { + deps = [ + ":gen_${bundle_prefix}_bundle", + ] + } + } +} diff --git a/engine/src/flutter/tools/skyx.py b/engine/src/flutter/tools/skyx.py index f15edaa97e..094b35abd6 100755 --- a/engine/src/flutter/tools/skyx.py +++ b/engine/src/flutter/tools/skyx.py @@ -14,20 +14,24 @@ DART_SDK = os.path.join(SRC_ROOT, 'third_party', 'dart-sdk', 'dart-sdk', 'bin') def main(): parser = argparse.ArgumentParser(description='Packaging tool for Sky apps') - parser.add_argument('manifest', type=str) + parser.add_argument('--manifest', type=str) parser.add_argument('--asset-base', type=str) parser.add_argument('--snapshot', type=str) parser.add_argument('-o', '--output-file', type=str) args = parser.parse_args() - subprocess.check_call([ + command = [ os.path.join(DART_SDK, 'dart'), os.path.join(SKY_TOOLS_DIR, 'skyx', 'bin', 'skyx.dart'), '--asset-base', args.asset_base, '--snapshot', args.snapshot, '--output-file', args.output_file, - args.manifest, - ]) + ] + + if args.manifest: + command += ['--manifest', args.manifest] + + subprocess.check_call(command) if __name__ == '__main__': sys.exit(main()) diff --git a/engine/src/flutter/tools/skyx/bin/skyx.dart b/engine/src/flutter/tools/skyx/bin/skyx.dart index 989b5c5d20..9bab5e1107 100644 --- a/engine/src/flutter/tools/skyx/bin/skyx.dart +++ b/engine/src/flutter/tools/skyx/bin/skyx.dart @@ -65,6 +65,8 @@ Iterable parseMaterialAssets(Map manifestDescriptor) sync* { } Future loadManifest(String manifestPath) async { + if (manifestPath == null) + return null; String manifestDescriptor = await new File(manifestPath).readAsString(); return loadYaml(manifestDescriptor); } @@ -85,8 +87,9 @@ main(List argv) async { ArgParser parser = new ArgParser(); parser.addFlag('help', abbr: 'h', negatable: false); parser.addOption('asset-base'); - parser.addOption('snapshot'); + parser.addOption('manifest'); parser.addOption('output-file', abbr: 'o'); + parser.addOption('snapshot'); ArgResults args = parser.parse(argv); if (args['help']) { @@ -94,8 +97,7 @@ main(List argv) async { return; } - String manifestPath = args.rest.first; - + String manifestPath = args['manifest']; Map manifestDescriptor = await loadManifest(manifestPath); Iterable materialAssets = parseMaterialAssets(manifestDescriptor);