blob: 8040f3f9e814901ba7f329d14c057687c389fcf4 [file] [log] [blame]
# Copyright 2018 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("//build/config/clang/clang.gni")
# This is $root_build_dir in the Zircon GN build.
# **NOTE!** This is not a subdirectory of $root_build_dir because that
# makes GN insist that it understand where all files in there come from.
# We instead require that users (or `fx build`) run ninja in
# $zircon_root_build_dir before running ninja in $root_build_dir.
zircon_root_build_dir = "${root_build_dir}.zircon"
# Zircon tools get added to that directory by the Fuchsia GN build.
# When using to a tool from this directory, add the corresponding dependency on
# `//zircon/public/tool/$tool_name($host_toolchain)`.
zircon_tools_dir =
get_label_info("//zircon/public/tool($host_toolchain)", "root_out_dir")
# Template for running a Zircon host tool as part of the build.
# This is a thin wrapper to define an `action()` target.
#
# Parameters
#
# tool (required)
# [string] The name of the tool, like "mkbootfs".
#
# args (required)
# [list of strings] The arguments to pass the tool.
# The tool runs with `root_build_dir` as its current directory,
# so any file names should be made either absolute or relative
# to `root_build_dir` using `rebase_path()`.
#
# All other parameters are exactly as for `action()`, except
# that `script` is replaced with `tool`.
#
template("zircon_tool_action") {
assert(defined(invoker.tool), "zircon_tool_action() requires `tool`")
assert(defined(invoker.args), "zircon_tool_action() requires `args`")
_dep = "//zircon/public/tool/${invoker.tool}($host_toolchain)"
_tool = "$zircon_tools_dir/${invoker.tool}"
action(target_name) {
inputs = []
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
forward_variables_from(invoker,
"*",
[
"args",
"script",
"tool",
"testonly",
"visibility",
])
script = "//build/gn_run_binary.sh"
inputs += [ _tool ]
args = [
clang_prefix,
rebase_path(_tool, root_build_dir),
] + invoker.args
if (!defined(deps)) {
deps = []
}
deps += [ _dep ]
}
}