From a9ab8f4e7d2aa971d502836f9364fbd68e52c8eb Mon Sep 17 00:00:00 2001 From: Zach Anderson Date: Tue, 22 May 2018 17:47:16 +0000 Subject: [PATCH] [GN] Hack around Dart 2 application_snapshot deps issue For Dart 2 snapshots, application_snapshots() hardcodes a deps on //utils/kernel-service:copy_kernel_service_snapshot related #33167 Change-Id: I9a598e83a3e8ebb9a27bfe83132f3a957f2fea0e Reviewed-on: https://dart-review.googlesource.com/56161 Reviewed-by: Nate Bosch Commit-Queue: Zach Anderson --- utils/application_snapshot.gni | 48 ++++++++++++++++++++++++++++++++++ utils/dartanalyzer/BUILD.gn | 4 +-- utils/dartdevc/BUILD.gn | 4 +-- utils/pub/BUILD.gn | 4 +-- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/utils/application_snapshot.gni b/utils/application_snapshot.gni index 096b9443ef8..3630beee05d 100644 --- a/utils/application_snapshot.gni +++ b/utils/application_snapshot.gni @@ -15,6 +15,37 @@ declare_args() { } } +# Creates an app-jit snapshot for a Dart program based on a training run. +# +# Parameters: +# main_dart (required): +# The entrypoint to the Dart application. +# +# training_args (required): +# Arguments to pass to the Dart application for the training run. +# +# dart_version (optional): +# Must be 1 or 2. Defaults to 1. +# +# vm_args (optional): +# Additional arguments to the Dart VM. Do not put --preview-dart-2 here. +# Instead set dart_version = 2. +# +# name (optional): +# The name of the snapshot if different from the target name. The output +# will be in $root_gen_dir/$name.dart.snapshot. +# +# extra_deps (optional): +# Any additional build dependencies. +# +# extra_inputs (optional): +# Any extra build inputs. +# +# dot_packages (optional): +# The .packages file for the app. Defaults to the $_dart_root/.packages. +# +# output (optional): +# Overrides the full output path. template("application_snapshot") { assert(defined(invoker.main_dart), "Must specify 'main_dart'") assert(defined(invoker.training_args), "Must specify 'training_args'") @@ -45,8 +76,25 @@ template("application_snapshot") { if (defined(invoker.output)) { output = invoker.output } + dart_version = 1 + if (defined(invoker.dart_version)) { + dart_version = invoker.dart_version + } + assert(dart_version == 1 || dart_version == 2, + "For $target_name, dart_version must be 1 or 2") dart_action(target_name) { deps = extra_deps + + if (dart_version == 2) { + # HACK: When creating app-jit snapshots for Dart 2 apps, the standalone + # Dart VM binary requires the app-jit snapshot for the kernel service to + # be adjacent to it. This deps ensures that it is there, but a different + # approach will be needed when the kernel service itself switches to + # Dart 2 to avoid creating a circular dependence. + deps += [ "$_dart_root/utils/kernel-service:copy_kernel_service_snapshot"] + snapshot_vm_args += [ "--preview-dart-2" ] + } + depfile = "$output.d" script = main_dart diff --git a/utils/dartanalyzer/BUILD.gn b/utils/dartanalyzer/BUILD.gn index 874ee7b8df8..ff06c7bdaa8 100644 --- a/utils/dartanalyzer/BUILD.gn +++ b/utils/dartanalyzer/BUILD.gn @@ -21,9 +21,7 @@ analyzer_files = exec_script("../../tools/list_dart_files.py", "list lines") application_snapshot("generate_dartanalyzer_snapshot") { - vm_args = [ - "--preview-dart-2", - ] + dart_version = 2 main_dart = "../../pkg/analyzer_cli/bin/analyzer.dart" training_args = [ "--dart-sdk=" + rebase_path("../../sdk"), diff --git a/utils/dartdevc/BUILD.gn b/utils/dartdevc/BUILD.gn index 0c5c4e2b064..6165c856771 100644 --- a/utils/dartdevc/BUILD.gn +++ b/utils/dartdevc/BUILD.gn @@ -11,9 +11,7 @@ sdk_summary = "$target_gen_dir/ddc_sdk.sum" sdk_dill = "$target_gen_dir/kernel/ddc_sdk.dill" application_snapshot("dartdevc") { - vm_args = [ - "--preview-dart-2", - ] + dart_version = 2 main_dart = "../../pkg/dev_compiler/bin/dartdevc.dart" diff --git a/utils/pub/BUILD.gn b/utils/pub/BUILD.gn index f34a69a3313..0adf27ad287 100644 --- a/utils/pub/BUILD.gn +++ b/utils/pub/BUILD.gn @@ -10,9 +10,7 @@ application_snapshot("pub") { } application_snapshot("pub2") { + dart_version = 2 main_dart = "../../third_party/pkg/pub/bin/pub.dart" training_args = [ "--help" ] - vm_args = [ - "--preview-dart-2", - ] }