blob: 66c5a660ce29b3aa3b98f0ae3c4a7fef99851989 [file] [log] [blame]
# Copyright 2020 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/compiled_action.gni")
import("//build/dist/resource.gni")
# Generates binary config using FIDL format and .json data values.
#
# Example instantiation:
#
# ```
# component_config("some_config") {
# sources = [ "config.json" ]
# }
# ```
#
# Inputs:
#
# - JSON file(s) with config values.
#
# Outputs:
#
# - Persistent FIDL binary config file.
#
# Parameters:
#
# sources (required)
# Paths to one or more JSON files containing config values.
#
# dest (optional)
# If specified, the packaged path for the generated binary config file.
# Default: "data/${target_name}"
template("component_config") {
assert(defined(invoker.sources), "Parameter source=... is required")
generate_target = "${target_name}_generate"
output = "$target_gen_dir/$target_name"
compiled_action(generate_target) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
visibility = [ ":*" ]
tool = "//tools/component_manager_config:generate_config_bin"
tool_output_name = "generate_config"
inputs = invoker.sources
outputs = [ output ]
args = [ "--output" ] + rebase_path(outputs, root_build_dir)
foreach(source, invoker.sources) {
args += [
"--input",
rebase_path(source, root_build_dir),
]
}
}
resource(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public_deps = [ ":$generate_target" ]
sources = [ output ]
if (defined(invoker.dest)) {
outputs = [ invoker.dest ]
} else {
outputs = [ "data/${target_name}" ]
}
}
}