blob: ad59c988900671bdcbafe462b9e8bf3e3464edfc [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/host_tool_action.gni")
# Run the FIDL compiler for a fidl_library().
#
# This is not really meant for general use. It's used by FIDL support
# modules (see $zx/public/gn/fidl.gni for details).
#
# Parameters
#
# deps
# Required: List of exactly one fidl_library() target label.
# Type: list(label_no_toolchain)
#
# args
# Required: Arguments for `fidlc` to generate the desired outputs.
# Type: list(string)
#
# outputs
# Required: Files that `fidlc` will generate when given $args.
# Type: list(file)
#
# tool
# Optional: Label of the host_tool() to run.
# Type: label_no_toolchain
# Default: "$zx/tools/fidl:fidlc"
#
template("fidlc") {
if (current_toolchain == default_toolchain) {
fidlc_target = target_name
fidl_deps = invoker.deps
fidlc_outputs = invoker.outputs
fidl_library = fidl_deps[0]
assert(fidl_deps == [ fidl_library ],
"fidlc() must list exactly one fidl_library() target in `deps`")
fidl_label_dir = get_label_info(fidl_library, "dir")
fidl_label_name = get_label_info(fidl_library, "name")
# TODO(mcgrathr): temporary until everything is renamed with . names
fidl_name = string_replace(fidl_label_name, "-", ".")
# fidl_library() generates a response file of all the input arguments.
fidl_gen_dir = get_label_info(fidl_library, "target_gen_dir")
fidl_target_name = get_label_info(fidl_library, "name")
files_rspfile = "$fidl_gen_dir/$fidl_target_name.rsp"
files_rspfile_target =
"$fidl_label_dir:_fidl_library.files.$fidl_label_name.rsp"
# Next, combine that into a response file for the whole command.
# At the same time, produce a depfile listing all the input files.
fidlc_rspfile = "$target_out_dir/$fidlc_target.rsp"
fidlc_depfile = "$target_out_dir/$fidlc_target.d"
action("_fidlc.rsp.$target_name") {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":$fidlc_target" ]
deps = [
files_rspfile_target,
]
sources = [
files_rspfile,
]
outputs = [
fidlc_rspfile,
fidlc_depfile,
]
script = "$zx/public/gn/fidl/gen-fidlc-rsp.sh"
args = rebase_path(outputs + [ fidlc_outputs[0] ] + sources,
root_build_dir) +
[
"--name",
fidl_name,
] + invoker.args
}
host_tool_action(fidlc_target) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
if (defined(invoker.tool)) {
tool = invoker.tool
} else {
tool = "$zx/tools/fidl:fidlc"
}
outputs = fidlc_outputs
deps = [
":_fidlc.rsp.$target_name",
]
sources = [
fidlc_rspfile,
]
depfile = fidlc_depfile
args = [ "@" + rebase_path(fidlc_rspfile, root_build_dir) ]
metadata = {
generated_sources = rebase_path(outputs, root_build_dir)
}
}
} else {
group(target_name) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
public_deps = [
":$target_name($default_toolchain)",
]
not_needed(invoker, "*")
}
}
}