blob: c2840292316819a526ecfc1c796a8f2d66d5b401 [file] [log] [blame]
# Copyright 2022 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.
# Define configuration data that can be aggregated and then made available to
# other packages at runtime via the `config-data` package.
#
# NOTE: This mechanism is deprecated, see RFC-0182:
# https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0182_deprecate_config-data
#
# NOTE: This template specifically defines a config_data entry for inclusion
# with the platform Assembly Input Bundles.
#
# NOTE: It CAN ONLY be used as a dependency of a platform AIB. It CANNOT be
# used as a dependency of any binary, package, or group.
#
# Params:
#
# for_pkg (required)
# [string] The name of the package this is configuration for.
#
# outputs (optional)
# [list of one path] This must be a relative path (no leading `/`). It can use
# placeholders based on $sources; see copy() and `gn help source_expansion`.
# If not provided, the outputs will be named by processing the sources
# with the {{source_file_part}} template. Applying this template to
# "config/mycfg.config" produces "mycfg.config". If supplied the list must
# contain exactly one path pattern.
#
# sources (required)
# [list of files] List of files in the source tree or build that become
# $outputs. See copy() for details.
#
# As normal:
# testonly
#
# NOTE: Visibility is restricted to `//bundles/assembly/*`, and cannot be
# overridden.
template("config_data_for_assembly") {
assert(
defined(invoker.for_pkg),
"The package the config data is for must be defined with 'for_pkg = <package name>'")
if (defined(invoker.outputs)) {
_config_data_outputs = invoker.outputs
} else {
_config_data_outputs = [ "{{source_file_part}}" ]
}
assert(_config_data_outputs != [] &&
_config_data_outputs - [ _config_data_outputs[0] ] == [],
"Exactly one output pattern required.")
if (string_replace(target_out_dir, "vendor/google", "") != target_out_dir) {
import("//vendor/google/build/config_data_for_pkg_allowlist.gni")
} else {
import("//build/config_data_for_pkg_allowlist.gni")
}
assert(config_data_for_pkg_allowlist == [] ||
config_data_for_pkg_allowlist + [ invoker.for_pkg ] -
[ invoker.for_pkg ] != config_data_for_pkg_allowlist,
"${invoker.for_pkg} is not an allowed value for for_pkg")
# Create the set of config_data entries
config_data_entries = []
foreach(source, invoker.sources) {
foreach(target, process_file_template([ source ], _config_data_outputs)) {
config_data_entries += [
{
package_name = invoker.for_pkg
source = rebase_path(source, root_build_dir)
destination = target
},
]
}
}
generated_file(target_name) {
forward_variables_from(invoker, [ "testonly" ])
assert(
!defined(invoker.deps),
"The config_data_for_assembly() template does not support dependencies")
assert(
!defined(invoker.data_deps),
"The config_data_for_assembly() template does not support dependencies")
assert(
!defined(invoker.public_deps),
"The config_data_for_assembly() template does not support dependencies")
assert(!defined(invoker.visibility),
"The config_data_for_assembly() template sets its own visibility")
# The generated file that describes the files to add to config_data
outputs = [ "${target_out_dir}/${target_name}/config_data_entry.json" ]
output_conversion = "json"
contents = config_data_entries
# The targets created by this template can only be used with assembly input
# bundles.
visibility = [ "//bundles/assembly/*" ]
}
}