From e842c9b0b5dca8d7e1a39f79e667c4a1ba50ffb9 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Tue, 6 Feb 2018 21:51:13 +0000 Subject: [PATCH] [infra] Use dart_action() instead of python scripts This change shifts logic for invoking Dart scripts during the build from a couple of python scripts to a new template called dart_action(). Change-Id: Ic0818122cd7317cbd22a7255d880fe8f87271b7e Reviewed-on: https://dart-review.googlesource.com/39260 Commit-Queue: Zach Anderson Reviewed-by: Ryan Macnak --- build/compiled_action.gni | 10 +++- build/dart_action.gni | 92 +++++++++++++++++++++++++++++ tools/patch_sdk.py | 63 -------------------- tools/run_dart.py | 60 ------------------- utils/application_snapshot.gni | 2 +- utils/dartanalyzer/BUILD.gn | 37 ++---------- utils/dartdevc/BUILD.gn | 103 ++++++++++----------------------- utils/generate_patch_sdk.gni | 41 +++---------- utils/kernel-service/BUILD.gn | 9 +-- 9 files changed, 151 insertions(+), 266 deletions(-) create mode 100644 build/dart_action.gni delete mode 100755 tools/patch_sdk.py delete mode 100755 tools/run_dart.py diff --git a/build/compiled_action.gni b/build/compiled_action.gni index e332763732e..5b5afa75f5b 100644 --- a/build/compiled_action.gni +++ b/build/compiled_action.gni @@ -74,7 +74,7 @@ if (host_os == "win") { _host_executable_suffix = "" } -_dart_root = rebase_path("..") +_dart_root = get_path_info("..", "abspath") template("compiled_action") { assert(defined(invoker.tool), "tool must be defined for $target_name") @@ -120,6 +120,10 @@ template("compiled_action") { deps += invoker.deps } + if (defined(invoker.depfile)) { + depfile = invoker.depfile + } + # The script takes as arguments the binary to run, and then the arguments # to pass it. args = [ @@ -173,6 +177,10 @@ template("compiled_action_foreach") { deps += invoker.deps } + if (defined(invoker.depfile)) { + depfile = invoker.depfile + } + # The script takes as arguments the binary to run, and then the arguments # to pass it. args = [ diff --git a/build/dart_action.gni b/build/dart_action.gni new file mode 100644 index 00000000000..81c147f4a56 --- /dev/null +++ b/build/dart_action.gni @@ -0,0 +1,92 @@ +# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +import("compiled_action.gni") +import("executable_suffix.gni") +import("prebuilt_dart_sdk.gni") + +_dart_root = get_path_info("..", "abspath") + +# A template for running Dart scripts during the build. This should *not* be +# used for generating snapshots. It uses the dart binary from the prebuilt +# Dart SDK if one is available, and dart_bootstrap otherwise. +# +# Parameters: +# script: +# The un-rebased path to the Dart script. +# +# args: +# The arguments to pass to the Dart script. + +# packages (optional): +# The un-rebased path to the .packages file. +# +# Forwarded to action() with the usual meaning: +# depfile +# deps +# inputs +# outputs +# visibility +template("dart_action") { + assert(defined(invoker.script), "script must be defined for $target_name") + assert(defined(invoker.outputs), "outputs must be defined for $target_name") + assert(defined(invoker.args), "args must be defined for $target_name") + assert(!defined(invoker.sources), + "dart_action doesn't take a sources arg. Use inputs instead.") + + if (prebuilt_dart_exe_works) { + action(target_name) { + forward_variables_from(invoker, [ + "inputs", + "outputs", + "deps", + "visibility", + "depfile", + ]) + script = "$_dart_root/build/gn_run_binary.py" + prebuilt_dart_binary = + "$_dart_root/tools/sdks/$host_os/dart-sdk/bin/dart$executable_suffix" + + inputs += [ invoker.script ] + if (defined(invoker.packages)) { + inputs += [ invoker.packages ] + } + + args = [ + "compiled_action", + rebase_path(prebuilt_dart_binary), + ] + if (defined(invoker.packages)) { + args += [ + "--packages=" + rebase_path(invoker.packages), + ] + } + args += [ rebase_path(invoker.script) ] + invoker.args + } + } else { + compiled_action(target_name) { + forward_variables_from(invoker, [ + "inputs", + "outputs", + "deps", + "visibility", + "depfile", + ]) + + inputs += [ invoker.script ] + if (defined(invoker.packages)) { + inputs += [ invoker.packages ] + } + + tool = "runtime/bin:dart_bootstrap" + args = [] + if (defined(invoker.packages)) { + args += [ + "--packages=" + rebase_path(invoker.packages), + ] + } + args += [ rebase_path(invoker.script) ] + invoker.args + } + } +} diff --git a/tools/patch_sdk.py b/tools/patch_sdk.py deleted file mode 100755 index dfa0b6027e2..00000000000 --- a/tools/patch_sdk.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -# for details. 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 os -import subprocess -import sys -import utils - -usage = """patch_sdk.py [options]""" - -def DisplayBootstrapWarning(): - print """\ - - -WARNING: Your system cannot run the checked-in Dart SDK. Using the -bootstrap Dart executable will make debug builds slow. -Please see the Wiki for instructions on replacing the checked-in Dart SDK. - -https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools - -""" - -def BuildArguments(): - result = argparse.ArgumentParser(usage=usage) - result.add_argument("-q", "--quiet", - help="emit no output", - default=False, - action="store_true") - result.add_argument("--dart-executable", - help="dart executable", - default=None) - result.add_argument("--script", - help="patch script to run", - default=None) - return result - -def main(): - # Parse the options. - parser = BuildArguments() - (options, args) = parser.parse_known_args() - if utils.CheckedInSdkCheckExecutable(): - options.dart_executable = utils.CheckedInSdkExecutable() - elif options.dart_executable is not None: - if not options.quiet: - DisplayBootstrapWarning() - options.dart_executable = os.path.abspath(options.dart_executable) - else: - print >> sys.stderr, 'ERROR: cannot locate dart executable' - return -1 - - if options.script is not None: - dart_file = options.script - else: - dart_file = os.path.join(os.path.dirname(__file__), 'patch_sdk.dart') - - subprocess.check_call([options.dart_executable, dart_file] + args) - return 0 - -if __name__ == '__main__': - sys.exit(main()) diff --git a/tools/run_dart.py b/tools/run_dart.py deleted file mode 100755 index a77d15f489a..00000000000 --- a/tools/run_dart.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -# for details. 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 os -import subprocess -import sys -import utils - -usage = """run_dart.py [--dart=]