blob: 290b8e5090b7ea2db6360f7a6f861250fb663777 [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:
#
# product_configs (optional)
# Paths to one or more JSON files containing the product policy.
#
# sources (optional)
# Paths to one or more JSON files containing config values.
#
# build_type (optional)
# String enum (eng, userdebug, user) that chooses additional configs to
# merge in depending on the build type. If not provided, then no additional
# config will be included, and the caller is responsible for adding the
# platform configs.
#
# dest (optional)
# If specified, the packaged path for the generated binary config file.
# Default: "data/${target_name}"
template("component_config") {
_sources = []
if (defined(invoker.sources)) {
_sources += invoker.sources
}
if (defined(invoker.build_type)) {
if (invoker.build_type == "eng") {
_sources += [
"//src/security/policy/component_manager_policy.json5",
"//src/security/policy/component_manager_policy_eng.json5",
]
} else if (invoker.build_type == "userdebug") {
_sources +=
[ "//src/security/policy/component_manager_policy_userdebug.json5" ]
} else if (invoker.build_type == "user") {
_sources +=
[ "//src/security/policy/component_manager_policy_user.json5" ]
} else {
assert(false, "build_type must be one of 'eng', 'userdebug', or 'user'")
}
_sources += [
"//src/security/policy/component_manager_policy_base.json5",
"//src/security/policy/component_manager_policy_build_type_base.json5",
"//src/sys/component_manager/configs/bootfs_config.json5",
]
}
_product_configs = []
if (defined(invoker.product_configs)) {
_product_configs += invoker.product_configs
}
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 = _sources + _product_configs
outputs = [ output ]
args = [ "--output" ] + rebase_path(outputs, root_build_dir)
foreach(source, _sources) {
args += [
"--input",
rebase_path(source, root_build_dir),
]
}
foreach(product, _product_configs) {
args += [
"--product",
rebase_path(product, 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}" ]
}
}
}