2014-06-12 23:35:55 +04:00
|
|
|
# Copyright 2014 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.
|
|
|
|
|
|
|
|
# This file introduces two related templates that act like action and
|
|
|
|
# action_foreach but instead of running a Python script, it will compile a
|
|
|
|
# given tool in the host toolchain and run that (either once or over the list
|
|
|
|
# of inputs, depending on the variant).
|
|
|
|
#
|
|
|
|
# Parameters
|
|
|
|
#
|
|
|
|
# tool (required)
|
|
|
|
# [label] Label of the tool to run. This should be an executable, and
|
|
|
|
# this label should not include a toolchain (anything in parens). The
|
|
|
|
# host compile of this tool will be used.
|
|
|
|
#
|
|
|
|
# outputs (required)
|
|
|
|
# [list of files] Like the outputs of action (if using "compiled_action",
|
|
|
|
# this would be just the list of outputs), or action_foreach (if using
|
|
|
|
# "compiled_action_foreach", this would contain source expansions mapping
|
|
|
|
# input to output files).
|
|
|
|
#
|
|
|
|
# args (required)
|
|
|
|
# [list of strings] Same meaning as action/action_foreach.
|
|
|
|
#
|
2014-08-29 00:24:32 +04:00
|
|
|
# inputs (optional)
|
|
|
|
# Files the binary takes as input. The step will be re-run whenever any
|
|
|
|
# of these change. If inputs is empty, the step will run only when the
|
|
|
|
# binary itself changes.
|
|
|
|
#
|
2014-06-12 23:35:55 +04:00
|
|
|
# visibility
|
|
|
|
# deps
|
|
|
|
# args (all optional)
|
|
|
|
# Same meaning as action/action_foreach.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Example of usage:
|
|
|
|
#
|
|
|
|
# compiled_action("run_my_tool") {
|
|
|
|
# tool = "//tools/something:mytool"
|
|
|
|
# outputs = [
|
|
|
|
# "$target_gen_dir/mysource.cc",
|
|
|
|
# "$target_gen_dir/mysource.h",
|
|
|
|
# ]
|
|
|
|
#
|
|
|
|
# # The tool takes this input.
|
2014-07-09 21:29:31 +04:00
|
|
|
# inputs = [ "my_input_file.idl" ]
|
2014-06-12 23:35:55 +04:00
|
|
|
#
|
|
|
|
# # In this case, the tool takes as arguments the input file and the output
|
|
|
|
# # build dir (both relative to the "cd" that the script will be run in)
|
|
|
|
# # and will produce the output files listed above.
|
|
|
|
# args = [
|
|
|
|
# rebase_path("my_input_file.idl", root_build_dir),
|
|
|
|
# "--output-dir", rebase_path(target_gen_dir, root_build_dir),
|
|
|
|
# ]
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# You would typically declare your tool like this:
|
|
|
|
# if (host_toolchain == current_toolchain) {
|
|
|
|
# executable("mytool") {
|
|
|
|
# ...
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# The if statement around the executable is optional. That says "I only care
|
|
|
|
# about this target in the host toolchain". Usually this is what you want, and
|
|
|
|
# saves unnecessarily compiling your tool for the target platform. But if you
|
|
|
|
# need a target build of your tool as well, just leave off the if statement.
|
|
|
|
|
2015-02-20 05:55:19 +03:00
|
|
|
if (host_os == "win") {
|
2014-09-02 23:50:29 +04:00
|
|
|
_host_executable_suffix = ".exe"
|
|
|
|
} else {
|
|
|
|
_host_executable_suffix = ""
|
|
|
|
}
|
|
|
|
|
2014-06-12 23:35:55 +04:00
|
|
|
template("compiled_action") {
|
|
|
|
assert(defined(invoker.tool), "tool 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")
|
|
|
|
|
2014-08-29 00:24:32 +04:00
|
|
|
assert(!defined(invoker.sources),
|
|
|
|
"compiled_action doesn't take a sources arg. Use inputs instead.")
|
|
|
|
|
2014-06-12 23:35:55 +04:00
|
|
|
action(target_name) {
|
2015-09-03 18:58:41 +03:00
|
|
|
forward_variables_from(invoker,
|
|
|
|
[
|
|
|
|
"deps",
|
|
|
|
"inputs",
|
|
|
|
"outputs",
|
|
|
|
"testonly",
|
|
|
|
"visibility",
|
|
|
|
])
|
2016-05-03 04:06:33 +03:00
|
|
|
if (!defined(deps)) {
|
|
|
|
deps = []
|
|
|
|
}
|
|
|
|
if (!defined(inputs)) {
|
|
|
|
inputs = []
|
|
|
|
}
|
2014-06-12 23:35:55 +04:00
|
|
|
|
|
|
|
script = "//build/gn_run_binary.py"
|
|
|
|
|
|
|
|
# Constuct the host toolchain version of the tool.
|
|
|
|
host_tool = invoker.tool + "($host_toolchain)"
|
|
|
|
|
|
|
|
# Get the path to the executable. Currently, this assumes that the tool
|
|
|
|
# does not specify output_name so that the target name is the name to use.
|
|
|
|
# If that's not the case, we'll need another argument to the script to
|
|
|
|
# specify this, since we can't know what the output name is (it might be in
|
|
|
|
# another file not processed yet).
|
gn format //build
A starting point for doing all of src, and adding a PRESUBMIT.
Includes https://codereview.chromium.org/772663002/ and https://codereview.chromium.org/770053002/.
I haven't pushed new binaries yet.
Generated via:
> cd build
> git ls-files *.gn *.gni | sed -e "s/^/@..\\\\out\\\\Debug\\\\gn format --in-place /" >x.bat && x.bat
The only things that I don't love in the current output are:
1. Turning
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--android-sdk-tools", rebased_android_sdk_build_tools,
"--dex-path", rebased_output,
]
into:
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--android-sdk-tools",
rebased_android_sdk_build_tools,
"--dex-path",
rebased_output,
]
The heuristic for this isn't trivial though, and it also affects e.g. '-Xclang' in cflags, as well
as assignments to temporaries that are later assigned to args.
2. Turning single line
if (defined(invoker.inputs)) { inputs = invoker.inputs }
into
if (defined(invoker.inputs)) {
inputs = invoker.inputs
}
This could be argued to be an improvement, but as it's very boilerplate-y perhaps an exception to
allow single line in this case is worthwhile. I think there was discussion of new syntax for this
case too, something like "inputs ?= invoker.inputs" maybe.
In both cases, I think it's worthwhile to get formatting turned on, and then go back and special
case these if we decide it's worthwhile.
R=brettw@chromium.org
BUG=348474
Review URL: https://codereview.chromium.org/766573003
Cr-Original-Commit-Position: refs/heads/master@{#306305}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b199254f481c5db36d56e83fce40594b06d2b81f
2014-12-02 03:25:20 +03:00
|
|
|
host_executable =
|
|
|
|
get_label_info(host_tool, "root_out_dir") + "/" +
|
|
|
|
get_label_info(host_tool, "name") + _host_executable_suffix
|
2014-06-12 23:35:55 +04:00
|
|
|
|
2014-08-29 00:24:32 +04:00
|
|
|
# Add the executable itself as an input.
|
|
|
|
inputs += [ host_executable ]
|
|
|
|
|
2015-09-03 18:58:41 +03:00
|
|
|
deps += [ host_tool ]
|
2014-06-12 23:35:55 +04:00
|
|
|
|
|
|
|
# The script takes as arguments the binary to run, and then the arguments
|
|
|
|
# to pass it.
|
gn format //build
A starting point for doing all of src, and adding a PRESUBMIT.
Includes https://codereview.chromium.org/772663002/ and https://codereview.chromium.org/770053002/.
I haven't pushed new binaries yet.
Generated via:
> cd build
> git ls-files *.gn *.gni | sed -e "s/^/@..\\\\out\\\\Debug\\\\gn format --in-place /" >x.bat && x.bat
The only things that I don't love in the current output are:
1. Turning
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--android-sdk-tools", rebased_android_sdk_build_tools,
"--dex-path", rebased_output,
]
into:
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--android-sdk-tools",
rebased_android_sdk_build_tools,
"--dex-path",
rebased_output,
]
The heuristic for this isn't trivial though, and it also affects e.g. '-Xclang' in cflags, as well
as assignments to temporaries that are later assigned to args.
2. Turning single line
if (defined(invoker.inputs)) { inputs = invoker.inputs }
into
if (defined(invoker.inputs)) {
inputs = invoker.inputs
}
This could be argued to be an improvement, but as it's very boilerplate-y perhaps an exception to
allow single line in this case is worthwhile. I think there was discussion of new syntax for this
case too, something like "inputs ?= invoker.inputs" maybe.
In both cases, I think it's worthwhile to get formatting turned on, and then go back and special
case these if we decide it's worthwhile.
R=brettw@chromium.org
BUG=348474
Review URL: https://codereview.chromium.org/766573003
Cr-Original-Commit-Position: refs/heads/master@{#306305}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b199254f481c5db36d56e83fce40594b06d2b81f
2014-12-02 03:25:20 +03:00
|
|
|
args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args
|
2014-06-12 23:35:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template("compiled_action_foreach") {
|
|
|
|
assert(defined(invoker.sources), "sources must be defined for $target_name")
|
|
|
|
assert(defined(invoker.tool), "tool 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")
|
|
|
|
|
|
|
|
action_foreach(target_name) {
|
2015-09-03 18:58:41 +03:00
|
|
|
forward_variables_from(invoker,
|
|
|
|
[
|
|
|
|
"deps",
|
|
|
|
"inputs",
|
|
|
|
"outputs",
|
|
|
|
"sources",
|
|
|
|
"testonly",
|
|
|
|
"visibility",
|
|
|
|
])
|
2016-05-03 04:06:33 +03:00
|
|
|
if (!defined(deps)) {
|
|
|
|
deps = []
|
|
|
|
}
|
|
|
|
if (!defined(inputs)) {
|
|
|
|
inputs = []
|
|
|
|
}
|
2014-06-12 23:35:55 +04:00
|
|
|
|
|
|
|
script = "//build/gn_run_binary.py"
|
|
|
|
|
|
|
|
# Constuct the host toolchain version of the tool.
|
|
|
|
host_tool = invoker.tool + "($host_toolchain)"
|
|
|
|
|
|
|
|
# Get the path to the executable. Currently, this assumes that the tool
|
|
|
|
# does not specify output_name so that the target name is the name to use.
|
|
|
|
# If that's not the case, we'll need another argument to the script to
|
|
|
|
# specify this, since we can't know what the output name is (it might be in
|
|
|
|
# another file not processed yet).
|
gn format //build
A starting point for doing all of src, and adding a PRESUBMIT.
Includes https://codereview.chromium.org/772663002/ and https://codereview.chromium.org/770053002/.
I haven't pushed new binaries yet.
Generated via:
> cd build
> git ls-files *.gn *.gni | sed -e "s/^/@..\\\\out\\\\Debug\\\\gn format --in-place /" >x.bat && x.bat
The only things that I don't love in the current output are:
1. Turning
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--android-sdk-tools", rebased_android_sdk_build_tools,
"--dex-path", rebased_output,
]
into:
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--android-sdk-tools",
rebased_android_sdk_build_tools,
"--dex-path",
rebased_output,
]
The heuristic for this isn't trivial though, and it also affects e.g. '-Xclang' in cflags, as well
as assignments to temporaries that are later assigned to args.
2. Turning single line
if (defined(invoker.inputs)) { inputs = invoker.inputs }
into
if (defined(invoker.inputs)) {
inputs = invoker.inputs
}
This could be argued to be an improvement, but as it's very boilerplate-y perhaps an exception to
allow single line in this case is worthwhile. I think there was discussion of new syntax for this
case too, something like "inputs ?= invoker.inputs" maybe.
In both cases, I think it's worthwhile to get formatting turned on, and then go back and special
case these if we decide it's worthwhile.
R=brettw@chromium.org
BUG=348474
Review URL: https://codereview.chromium.org/766573003
Cr-Original-Commit-Position: refs/heads/master@{#306305}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b199254f481c5db36d56e83fce40594b06d2b81f
2014-12-02 03:25:20 +03:00
|
|
|
host_executable =
|
|
|
|
get_label_info(host_tool, "root_out_dir") + "/" +
|
|
|
|
get_label_info(host_tool, "name") + _host_executable_suffix
|
2014-06-12 23:35:55 +04:00
|
|
|
|
2014-08-29 00:24:32 +04:00
|
|
|
# Add the executable itself as an input.
|
|
|
|
inputs += [ host_executable ]
|
|
|
|
|
2015-09-03 18:58:41 +03:00
|
|
|
deps += [ host_tool ]
|
2014-06-12 23:35:55 +04:00
|
|
|
|
|
|
|
# The script takes as arguments the binary to run, and then the arguments
|
|
|
|
# to pass it.
|
gn format //build
A starting point for doing all of src, and adding a PRESUBMIT.
Includes https://codereview.chromium.org/772663002/ and https://codereview.chromium.org/770053002/.
I haven't pushed new binaries yet.
Generated via:
> cd build
> git ls-files *.gn *.gni | sed -e "s/^/@..\\\\out\\\\Debug\\\\gn format --in-place /" >x.bat && x.bat
The only things that I don't love in the current output are:
1. Turning
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--android-sdk-tools", rebased_android_sdk_build_tools,
"--dex-path", rebased_output,
]
into:
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--android-sdk-tools",
rebased_android_sdk_build_tools,
"--dex-path",
rebased_output,
]
The heuristic for this isn't trivial though, and it also affects e.g. '-Xclang' in cflags, as well
as assignments to temporaries that are later assigned to args.
2. Turning single line
if (defined(invoker.inputs)) { inputs = invoker.inputs }
into
if (defined(invoker.inputs)) {
inputs = invoker.inputs
}
This could be argued to be an improvement, but as it's very boilerplate-y perhaps an exception to
allow single line in this case is worthwhile. I think there was discussion of new syntax for this
case too, something like "inputs ?= invoker.inputs" maybe.
In both cases, I think it's worthwhile to get formatting turned on, and then go back and special
case these if we decide it's worthwhile.
R=brettw@chromium.org
BUG=348474
Review URL: https://codereview.chromium.org/766573003
Cr-Original-Commit-Position: refs/heads/master@{#306305}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b199254f481c5db36d56e83fce40594b06d2b81f
2014-12-02 03:25:20 +03:00
|
|
|
args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args
|
2014-06-12 23:35:55 +04:00
|
|
|
}
|
|
|
|
}
|