blob: 72ec6bd751d8d18cdc540f9120bae55c26e05ee1 [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("//build/components.gni")
import("//build/dist/distribution_manifest.gni")
import("//build/testing/golden_file.gni")
declare_args() {
# Used by config_package().
# If true, then overrides the value of the sysmgr_golden_warn template
# parameter to true regardless of whether it is specified on a target.
sysmgr_golden_warn_override = false
}
# Define configuration data that can be aggregated into other packages. This is
# primarily used to aggregate configuration files into the config-data package
# that supplies the /config/data namespace.
#
# 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.
#
# See copy() for other parameters.
template("config_data") {
group(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"for_pkg",
"metadata",
"outputs",
"public_deps",
"sources",
"testonly",
"visibility",
])
if (!defined(outputs)) {
outputs = [ "{{source_file_part}}" ]
}
assert(outputs != [] && outputs - [ outputs[0] ] == [],
"Exactly one output pattern required.")
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
config_package_entries = []
foreach(source, sources) {
foreach(target, process_file_template([ source ], outputs)) {
# Config files are usually small, so package them in meta/ so they're
# archived together rather than spread across individual blobs.
# See also: fxbug.dev/37055
config_package_entries += [
{
source = rebase_path(source, root_build_dir)
destination = "meta/data/$for_pkg/$target"
label = get_label_info(":$target_name", "label_with_toolchain")
},
]
}
}
}
}
}
# Produce a configuration package who's content are defined by all config_data
# targets in its dependency chain.
#
# Parameters
#
# sysmgr_golden (optional)
# [path] File to treat as the golden file for this image's sysmgr configuration.
# Fails the build if the configuration generated by this build is different than
# the golden file's contents. To downgrade to a warning, set `sysmgr_golden_warn`.
#
# sysmgr_golden_warn (default: false)
# [boolean] If true, mismatches in the sysmgr golden config are treated as warnings
# rather than errors.
# If the `sysmgr_golden_warn_override` GN arg is true then mismatches
# against the sysmgr golden config are treated as warnings regardless of the
# parameter value specified.
# To apply this override:
# fx set ... --args=sysmgr_golden_warn_override=true
#
# deps (required)
# testonly (optional)
# visibility (optional)
# Usual GN meanings.
template("config_package") {
config_package_entries_target = "${target_name}_config_package_entries"
config_package_entries = "$target_out_dir/$config_package_entries_target"
generated_file(config_package_entries_target) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
visibility = [ ":*" ]
data_keys = [ "config_package_entries" ]
walk_keys = [ "config_package_barrier" ]
outputs = [ config_package_entries ]
output_conversion = "json"
metadata = {
# Don't pick up resources from deps
distribution_entries_barrier = []
}
}
distribution_entries_target = "${target_name}_distribution_entries_file"
distribution_entries_file(distribution_entries_target) {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":*" ]
deps = [ ":$config_package_entries_target" ]
file = config_package_entries
}
validate_sysmgr_config_target = "${target_name}_validate_sysmgr_config"
merged_sysmgr_config = "$target_gen_dir/${target_name}_merged_sysmgr_config"
action(validate_sysmgr_config_target) {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":*" ]
deps = [ ":$config_package_entries_target" ]
script = "//build/tools/validate_sysmgr_config.py"
inputs = [ config_package_entries ]
depfile = "$target_out_dir/$target_name.d"
outputs = [ merged_sysmgr_config ]
args = [
"--config-entries",
rebase_path(config_package_entries, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--merged",
rebase_path(merged_sysmgr_config, root_build_dir),
]
}
if (defined(invoker.sysmgr_golden)) {
golden_file_target = "${target_name}_sysmgr_golden"
golden_file(golden_file_target) {
forward_variables_from(invoker, [ "testonly" ])
deps = [ ":$validate_sysmgr_config_target" ]
visibility = [ ":*" ]
golden = invoker.sysmgr_golden
current = merged_sysmgr_config
warn_on_changes =
(defined(invoker.sysmgr_golden_warn) && invoker.sysmgr_golden_warn) ||
sysmgr_golden_warn_override
}
}
fuchsia_package(target_name) {
forward_variables_from(invoker,
[
"package_name",
"testonly",
"visibility",
])
deps = [
":$distribution_entries_target",
":$validate_sysmgr_config_target",
]
if (defined(golden_file_target)) {
deps += [ ":$golden_file_target" ]
}
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
config_package_barrier = []
}
}
}