提交 6442c624 编写于 作者: P P.Y. Laligand 提交者: GitHub

Use the flutter tool to build flx files with gn. (#3067)

上级 71f2871f
......@@ -45,6 +45,17 @@ template("flutter_app") {
flutter_snapshot_dir = get_label_info(flutter_snapshot_label, "root_out_dir")
flutter_snapshot = "$flutter_snapshot_dir/sky_snapshot"
dart_binary_label = "//dart/runtime/bin:dart_no_observatory($host_toolchain)"
dart_binary_dir = get_label_info(dart_binary_label, "root_out_dir")
dart_binary = "$dart_binary_dir/dart_no_observatory"
flutter_tools_label = "//lib/flutter/packages/flutter_tools"
flutter_tools_gen_dir = get_label_info(flutter_tools_label, "target_gen_dir")
flutter_tools_name = get_label_info(flutter_tools_label, "name")
flutter_tools_packages = "$flutter_tools_gen_dir/$flutter_tools_name.packages"
flutter_tools_main = "$flutter_tools_label/bin/flutter_tools.dart"
dot_packages = "$target_gen_dir/$dart_package_name.packages"
bundle_path = "$root_out_dir/$bundle_name"
snapshot_path = "$target_gen_dir/${target_name}_snapshot.bin"
depfile_path = "${snapshot_path}.d"
......@@ -70,27 +81,37 @@ template("flutter_app") {
script = "//flutter/build/package.py"
args = [
"--snapshotter",
"--root",
rebase_path(dart_binary_dir),
"--dart",
rebase_path(dart_binary),
"--flutter-tools-packages",
rebase_path(flutter_tools_packages),
"--flutter-tools-main",
rebase_path(flutter_tools_main),
"--snapshotter-path",
rebase_path(flutter_snapshot),
"--working-dir",
rebase_path("$target_gen_dir/build"),
"--app-dir",
rebase_path("."),
"--main-dart",
rebase_path(main_dart),
"--packages",
rebase_path("$target_gen_dir/$dart_package_name.packages"),
"--bundle",
rebase_path(dot_packages),
"--output-file",
rebase_path(bundle_path),
"--bundle-header",
"#!mojo mojo:flutter_content_handler",
"--snapshot",
rebase_path(snapshot_path),
"--depfile",
rebase_path(depfile_path),
"--build-output",
rebase_path(bundle_path, root_build_dir),
]
deps = [
":$dart_package_name",
dart_binary_label,
flutter_snapshot_label,
flutter_tools_label,
]
if (defined(invoker.deps)) {
......
......@@ -6,16 +6,26 @@
import argparse
import subprocess
import os
import StringIO
import sys
import zipfile
def main():
parser = argparse.ArgumentParser(description='Package a Flutter application')
parser.add_argument('--snapshotter', type=str, required=True,
help='The snapshot binary to use')
parser.add_argument('--root', type=str, required=True,
help='The root of the output directory')
parser.add_argument('--dart', type=str, required=True,
help='The Dart binary to use')
parser.add_argument('--flutter-tools-packages', type=str, required=True,
help='The package map for the Flutter tool')
parser.add_argument('--flutter-tools-main', type=str, required=True,
help='The main.drt file for the Flutter tool')
parser.add_argument('--snapshotter-path', type=str, required=True,
help='The Flutter snapshotter')
parser.add_argument('--working-dir', type=str, required=True,
help='The directory where to put intermediate files')
parser.add_argument('--app-dir', type=str, required=True,
help='The root of the app')
parser.add_argument('--main-dart', type=str, required=True,
help='The main.dart file to use')
parser.add_argument('--packages', type=str, required=True,
......@@ -24,36 +34,30 @@ def main():
help='Path to application snapshot')
parser.add_argument('--depfile', type=str, required=True,
help='Where to output dependency information')
parser.add_argument('--build-output', type=str, required=True,
help='The final target to use in the dependency information')
parser.add_argument('--bundle', type=str, required=True,
parser.add_argument('--output-file', type=str, required=True,
help='Where to output application bundle')
parser.add_argument('--bundle-header', type=str, required=True,
help='String to prepend to bundle')
args = parser.parse_args()
env = os.environ.copy()
env['LD_LIBRARY_PATH'] = args.root
result = subprocess.call([
args.snapshotter,
args.dart,
'--packages=%s' % args.flutter_tools_packages,
args.flutter_tools_main,
'build',
'mojo',
'--snapshotter-path=%s' % args.snapshotter_path,
'--working-dir=%s' % args.working_dir,
'--target=%s' % args.main_dart,
'--packages=%s' % args.packages,
'--snapshot=%s' % args.snapshot,
'--depfile=%s' % args.depfile,
'--build-output=%s' % args.build_output,
args.main_dart,
])
if result != 0:
return result
archive = StringIO.StringIO()
with zipfile.ZipFile(archive, 'w') as z:
z.write(args.snapshot, 'snapshot_blob.bin', zipfile.ZIP_DEFLATED)
with open(args.bundle, 'w') as f:
if args.bundle_header:
f.write(args.bundle_header)
f.write('\n')
f.write(archive.getvalue())
'--output-file=%s' % args.output_file,
], env=env, cwd=args.app_dir)
return result
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册