blob: ab3ae27f21dde079de6822bd75e2b91b91613944 [file] [log] [blame]
# Copyright 2021 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/config/clang/clang.gni")
import("//build/host.gni")
import("//build/rust/config.gni")
# Compile a configuration value file.
#
# Parameters
#
# cm (required)
# Compiled manifest for which the value file should be compiled.
# Type: path
#
# value_file (required)
# A JSON5 file containing the configuration values to be compiled.
# Type: path
#
# deps (optional)
# metadata (optional)
# output_name (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("cvf") {
input_manifest = invoker.cm
value_file = invoker.value_file
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"metadata",
"output_name",
"testonly",
"visibility",
])
if (!defined(output_name)) {
output_name = target_name
}
tool = "//tools/configc"
tool_output_name = "configc"
compiled_output = "${target_out_dir}/${output_name}.cvf"
inputs = [
input_manifest,
value_file,
]
outputs = [ compiled_output ]
args = [
"cvf",
"--cm",
rebase_path(input_manifest, root_build_dir),
"--values",
rebase_path(value_file, root_build_dir),
"--output",
rebase_path(compiled_output, root_build_dir),
]
}
}
# Generate the FIDL client library source files for a configuration declaration.
#
# Parameters
#
# compiled_manifest (required)
# Compiled manifest for which the source files should be generated.
# Type: path
#
# name (required)
# Name for the generated FIDL library.
# Type: string
#
# deps (optional)
# metadata (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("fidl_config_client_lib_source") {
assert(defined(invoker.compiled_manifest),
"the path to a compiled component manifest must be specified")
assert(defined(invoker.name),
"the name of this FIDL library must be specified")
compiled_manifest = invoker.compiled_manifest
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
tool = "//tools/configc"
tool_output_name = "configc"
fidl_format_tool_label = "//tools/fidl/fidlc:fidl-format($host_toolchain)"
fidl_format_tool_path =
get_label_info(fidl_format_tool_label, "root_out_dir") + "/fidl-format"
inputs = [
compiled_manifest,
fidl_format_tool_path,
]
source_file_path = "${target_out_dir}/${target_name}.fidl"
args = [
"fidl",
"--cm",
rebase_path(compiled_manifest, root_build_dir),
"--output",
rebase_path(source_file_path, root_build_dir),
"--library-name",
invoker.name,
"--fidl-format",
rebase_path(fidl_format_tool_path, root_build_dir),
]
if (!defined(deps)) {
deps = []
}
deps += [ "//tools/fidl/fidlc:fidl-format($host_toolchain)" ]
outputs = [ source_file_path ]
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
generated_sources = rebase_path(outputs, root_build_dir)
}
}
}
# Generate the Rust client library source files for a configuration declaration.
#
# Parameters
#
# compiled_manifest (required)
# Compiled manifest for which the source files should be generated.
# Type: path
#
# fidl_library_name (required)
# Name for the internal FIDL library.
# Type: string
#
# deps (optional)
# metadata (optional)
# output_name (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("rust_config_client_lib_source") {
assert(defined(invoker.compiled_manifest),
"the path to a compiled component manifest must be specified")
assert(defined(invoker.fidl_library_name),
"the name of the internal FIDL library must be specified")
compiled_manifest = invoker.compiled_manifest
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"name",
"testonly",
"visibility",
])
tool = "//tools/configc"
tool_output_name = "configc"
inputs = [
compiled_manifest,
"//rustfmt.toml",
"$rustc_prefix/bin/rustfmt",
rustc_version_file,
]
source_file_path = "${target_out_dir}/${target_name}.rs"
args = [
"rust",
"--cm",
rebase_path(compiled_manifest, root_build_dir),
"--output",
rebase_path(source_file_path, root_build_dir),
"--fidl-library-name",
invoker.fidl_library_name,
"--rustfmt",
"$rebased_rustc_prefix/bin/rustfmt",
"--rustfmt-config",
rebase_path("//rustfmt.toml", root_build_dir),
]
outputs = [ source_file_path ]
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
generated_sources = rebase_path(outputs, root_build_dir)
}
}
}
# Generate the C++ client library source files for a configuration declaration.
#
# Parameters
#
# compiled_manifest (required)
# Compiled manifest for which the source files should be generated.
# Type: path
#
# fidl_library_name (required)
# Name for the internal FIDL library.
# Type: string
#
# flavor (required)
# Runner flavor for client library
# Type: string
#
# namespace (optional)
# Namespace used by the C++ library.
# Type: string
#
# deps (optional)
# metadata (optional)
# output_name (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("cpp_config_client_lib_source") {
assert(defined(invoker.compiled_manifest),
"the path to a compiled component manifest must be specified")
assert(defined(invoker.fidl_library_name),
"the name of the internal FIDL library must be specified")
assert(defined(invoker.flavor),
"the flavor of the FIDL library must be specified ('elf' or 'driver')")
if (defined(invoker.namespace)) {
namespace = invoker.namespace
} else {
namespace = target_name
}
compiled_manifest = invoker.compiled_manifest
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"name",
"testonly",
"visibility",
])
tool = "//tools/configc"
tool_output_name = "configc"
inputs = [
compiled_manifest,
"${clang_prefix}/clang-format",
]
cc_source_file_path = "${target_out_dir}/${namespace}.cc"
h_source_file_path = "${target_out_dir}/${namespace}.h"
args = [
"cpp",
"--cm",
rebase_path(compiled_manifest, root_build_dir),
"--h-output",
rebase_path(h_source_file_path, root_build_dir),
"--cc-output",
rebase_path(cc_source_file_path, root_build_dir),
"--namespace",
namespace,
"--fidl-library-name",
invoker.fidl_library_name,
"--clang-format",
"${rebased_clang_prefix}/clang-format",
"--flavor",
invoker.flavor,
]
outputs = [
cc_source_file_path,
h_source_file_path,
]
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
generated_sources = rebase_path(outputs, root_build_dir)
}
}
}
# Validate a package's components' configuration (if any).
#
# Parameters
#
# package_manifest (path)
# Path to the output of the `pm_build()` template.
#
# deps (optional)
# metadata (optional)
# testonly (optional)
# visibility (optional)
# Standard GN meaning.
template("validate_packaged_config") {
assert(defined(invoker.package_manifest), "must provide an input manifest")
_package_manifest = invoker.package_manifest
_meta_far = get_path_info(_package_manifest, "dir") + "/meta.far"
_stamp = "${target_out_dir}/${target_name}.configc.stamp"
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"metadata",
"testonly",
"visibility",
])
tool = "//tools/configc"
tool_output_name = "configc"
inputs = [
_package_manifest,
_meta_far,
]
outputs = [ _stamp ]
args = [
"validate-package",
rebase_path(_package_manifest, root_build_dir),
"--stamp",
rebase_path(_stamp, root_build_dir),
]
}
}
# Dump a component's structured configuration values into human-readable JSON.
#
# Parameters
#
# cm (path)
# Path to the output of the `cm` or `fuchsia_component_manifest` templates.
#
# cvf (path)
# Path to the output of the `cvf` or `fuchsia_structured_config_values` templates.
#
# output (path)
# Path to which to write the human-readable values.
#
# deps (optional)
# metadata (optional)
# testonly (optional)
# visibility (optional)
template("dump_structured_config") {
assert(defined(invoker.cm),
"must define `cm` as a path to a compiled manifest")
assert(defined(invoker.cvf), "must define `cvf` as a path to a values file")
assert(defined(invoker.output),
"must provide an `output` path for dumped json")
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"metadata",
"testonly",
"visibility",
])
tool = "//tools/configc"
tool_output_name = "configc"
inputs = [
invoker.cm,
invoker.cvf,
]
outputs = [ invoker.output ]
args = [
"dump-values",
"--cm",
rebase_path(invoker.cm, root_build_dir),
"--cvf",
rebase_path(invoker.cvf, root_build_dir),
"--output",
rebase_path(invoker.output, root_build_dir),
]
}
}