blob: bef9ad7ed4d59b8036d9661af89bd85a45b4869e [file] [log] [blame]
# Copyright 2019 The Fuchsia 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("$zx/public/gn/toolchain/select_toolchain.gni")
template("_host_tool_action_target") {
action_target = 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")
# Dispatch to a host toolchain to get the tool built.
select_toolchain("_tool.$action_target") {
visibility = [
":$action_target",
":_rspfile.$action_target",
]
environment_label = "$zx/public/gn/toolchain:host"
cpu = host_cpu
os = host_os
deps = [
invoker.tool,
]
}
# The response file generated by host_tool() gives the files used (like
# the executable itself), then "--", then the arguments that make up the
# command line prefix to invoke the tool. host_tool_action.sh consumes that.
rspfile = "$target_gen_dir/$target_name._host_tool_action.rsp"
generated_file("_rspfile.$action_target") {
deps = [
":_tool.$action_target",
]
outputs = [
rspfile,
]
data_keys = [ "host_tool_rspfile" ]
walk_keys = [ "host_tool_barrier" ]
}
target(invoker._target_type, action_target) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"inputs",
"outputs",
"public_deps",
"sources",
"testonly",
"visibility",
])
if (!defined(deps)) {
deps = []
}
if (!defined(inputs)) {
inputs = []
}
deps += [
":_rspfile.$action_target",
":_tool.$action_target",
]
inputs += [ rspfile ]
depfile = "$target_out_dir/$target_name._host_tool_action.d"
if (defined(invoker.depfile)) {
orig_depfile = rebase_path(invoker.depfile, root_build_dir)
} else {
orig_depfile = "-"
}
script = "$zx/public/gn/host_tool_action.sh"
args = rebase_path([
rspfile,
outputs[0],
depfile,
],
root_build_dir) + [ orig_depfile ] + invoker.args
metadata = {
# Never follow the deps to find link outputs from invoker.tool.
# TODO: Maybe should still follow invoker.deps?
link_barrier = []
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
}
}
}
template("host_tool_action") {
_host_tool_action_target(target_name) {
_target_type = "action"
forward_variables_from(invoker, "*")
}
}
template("host_tool_action_foreach") {
_host_tool_action_target(target_name) {
_target_type = "action_foreach"
forward_variables_from(invoker, "*")
}
}