Skip to content

Commit

Permalink
Split the snapshot generation into a separate action (flutter#3168)
Browse files Browse the repository at this point in the history
This is to ensure that the depfile generated by the snapshotter has
the correct target.
  • Loading branch information
petrhosek authored and abarth committed Nov 2, 2016
1 parent 16077d4 commit 2c092bc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
57 changes: 43 additions & 14 deletions build/flutter_app.gni
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,62 @@ template("flutter_app") {

main_dart = invoker.main_dart

action(target_name) {
flutter_snapshot_name = target_name + "_snapshot"

action(flutter_snapshot_name) {
depfile = depfile_path

inputs = [
main_dart,
]

outputs = [
bundle_path,
snapshot_path,
]

if (defined(invoker.sources)) {
sources = invoker.sources
}

script = "//flutter/build/snapshot.py"

args = [
"--snapshotter-path",
rebase_path(flutter_snapshot),
"--app-dir",
rebase_path("."),
"--main-dart",
rebase_path(main_dart),
"--packages",
rebase_path(dot_packages),
"--snapshot",
rebase_path(snapshot_path),
"--depfile",
rebase_path(depfile_path),
"--build-output",
rebase_path(snapshot_path, root_build_dir),

]

deps = [
":$dart_package_name",
flutter_snapshot_label,
]

if (defined(invoker.deps)) {
deps += invoker.deps
}
}

action(target_name) {
inputs = [
snapshot_path,
]

outputs = [
bundle_path,
]

script = "//flutter/build/package.py"

args = [
Expand All @@ -92,33 +132,22 @@ template("flutter_app") {
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(dot_packages),
"--output-file",
rebase_path(bundle_path),
"--snapshot",
rebase_path(snapshot_path),
"--depfile",
rebase_path(depfile_path),
]

deps = [
":$dart_package_name",
":$flutter_snapshot_name",
dart_binary_label,
flutter_snapshot_label,
flutter_tools_label,
]

if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}
9 changes: 0 additions & 9 deletions build/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ def main():
help='The package map for the Flutter tool')
parser.add_argument('--flutter-tools-main', type=str, required=True,
help='The main.dart 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,
help='The package map to use')
parser.add_argument('--snapshot', type=str, required=True,
help='Path to application snapshot')
parser.add_argument('--depfile', type=str, required=True,
help='Where to output dependency information')
parser.add_argument('--output-file', type=str, required=True,
help='Where to output application bundle')

Expand All @@ -49,12 +43,9 @@ def main():
args.dart,
'--packages=%s' % args.flutter_tools_packages,
args.flutter_tools_main,
'--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,
'--output-file=%s' % args.output_file,
'--header=#!mojo mojo:flutter_content_handler',
], env=env, cwd=args.app_dir)
Expand Down
45 changes: 45 additions & 0 deletions build/snapshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# 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 argparse
import subprocess
import os
import sys


def main():
parser = argparse.ArgumentParser(description='Snapshot a Flutter application')

parser.add_argument('--snapshotter-path', type=str, required=True,
help='The Flutter snapshotter')
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,
help='The package map to use')
parser.add_argument('--snapshot', type=str, required=True,
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='Target name used in the depfile')

args = parser.parse_args()

result = subprocess.call([
args.snapshotter_path,
'--packages=%s' % args.packages,
'--snapshot=%s' % args.snapshot,
'--depfile=%s' % args.depfile,
'--build-output=%s' % args.build_output,
args.main_dart,
], cwd=args.app_dir)

return result


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 2c092bc

Please sign in to comment.