blob: 5c1b148a9a30345e0397cbbc04a6c5bab56ffe50 [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/assembly/package_manifests_list.gni")
import("//build/dist/distribution_manifest.gni")
import("//build/dist/resource.gni")
import("//build/images/args.gni")
import("//build/info/info.gni")
import("//build/zbi/kernel_cmdline.gni")
# Generates an Image Assembly Config to be consumed by the Image Assembler.
#
# Arguments
# output_path (required)
# [path] Product config output location
#
# kernel_image (required)
# [label] Kernel to add to the ZBI.
#
# base_packages (optional)
# [list of labels] The packages to include in the base package set.
#
# cache_packages (optional)
# [list of labels] The packages to cache in the images.
#
# bootfs_labels (optional)
# [list of labels] The objects installed on the bootfs partition of the
# generated ZBI.
#
# bootfs_package_labels (optional)
# [list of labels] The packages installed on the bootfs partition of the
# generated ZBI as meta.fars and content-id'd blobs.
#
# extra_base_deps (optional)
# [list of labels] The packages whose files should be added to the Base
# Package.
#
# boot_args (optional)
# [list of strings] Boot arguments to add to the devmgr_config.
#
# cmdline (optional)
# [list of strings] Kernel command line arguments to add to the ZBI.
#
# cmdline_deps (optional)
# [list of labels] Dependencies with metadata including additional kernel
# command arguments to add to the ZBI.
#
template("generated_image_assembly_config") {
assert(defined(invoker.output_path), "Need to define output_path")
assert(defined(invoker.kernel_image), "Need to define kernel_image")
# Set the defaults for several arguments.
base_packages = []
if (defined(invoker.base_packages)) {
base_packages += invoker.base_packages
}
cache_packages = []
if (defined(invoker.cache_packages)) {
cache_packages += invoker.cache_packages
}
bootfs_labels = []
if (defined(invoker.bootfs_labels)) {
bootfs_labels += invoker.bootfs_labels
}
bootfs_package_labels = []
if (defined(invoker.bootfs_package_labels)) {
bootfs_package_labels += invoker.bootfs_package_labels
}
extra_base_deps = []
if (defined(invoker.extra_base_deps)) {
extra_base_deps += invoker.extra_base_deps
}
boot_args = []
if (defined(invoker.boot_args)) {
boot_args += invoker.boot_args
}
# Labels used in this file.
labels = {
base_package_list = "${target_name}_package_manifest_list.base"
cache_package_list = "${target_name}_package_manifest_list.cache"
bootfs_package_list = "${target_name}_bootfs_package_list"
extra_base_list = "${target_name}_package_manifest_list.extra_base"
extra_base_deps_list =
"${target_name}_package_manifest_list.extra_base_deps"
kernel_image_metadata = "${target_name}_kernel_image_metadata"
kernel_cmdline_args = "${target_name}_kernel_cmdline_args"
bootfs_entries_metadata = "${target_name}_bootfs_entries_metadata"
boot_args = "${target_name}_boot_args"
}
# Files produced by targets in this file.
files = {
base_package_list = "$target_out_dir/package_lists/${target_name}_base"
cache_package_list = "$target_out_dir/package_lists/${target_name}_cache"
extra_base_list = "$target_out_dir/package_lists/${target_name}_extra_base"
bootfs_package_list = "$target_out_dir/package_lists/${target_name}_bootfs"
extra_base_deps_list =
"$target_out_dir/package_lists/${target_name}_extra_base_deps"
kernel_image_metadata =
"$target_out_dir/${target_name}_kernel_image.gn_meta.json"
kernel_cmdline_args =
"$target_out_dir/${target_name}_kernel_cmdline_args.json"
bootfs_entries_metadata =
"$target_out_dir/${target_name}_bootfs_entries.gn_meta.json"
boot_args = "$target_out_dir/${target_name}_boot_args"
}
# Construct a list of Base packages to add to the image assembly config.
package_manifests_list(labels.base_package_list) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
filename = files.base_package_list
deps = base_packages
}
# Construct a list of Cache packages to add to the image assembly config.
package_manifests_list(labels.cache_package_list) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
filename = files.cache_package_list
deps = cache_packages
}
# Construct a list of extra packages whose files should be added to the Base Package.
package_manifests_list(labels.extra_base_list) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
filename = files.extra_base_list
deps = extra_base_deps
}
# Find all the extra system dependencies in the Base packages list.
# This list mentions several extra packages to add to the Base Package.
generated_file(labels.extra_base_deps_list) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
data_keys = [ "system_image_extra_package_manifest" ]
walk_keys = [ "system_image_extra_package_manifest_barrier" ]
outputs = [ files.extra_base_deps_list ]
output_conversion = "json"
deps = base_packages
}
# Create a list of boot arguments to add to devmgr_config.
generated_file(labels.boot_args) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
outputs = [ files.boot_args ]
output_conversion = "json"
contents = boot_args
}
# Find the kernel image metadata, which includes the location of the assembled kernel ZBI.
generated_file(labels.kernel_image_metadata) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
data_keys = [ "images" ]
outputs = [ files.kernel_image_metadata ]
output_conversion = "json"
deps = [ invoker.kernel_image ]
}
# Accumulate the list of cmdline dependencies by first taking the
# directly-specified arguments, creating a new metadata target, and adding it
# to the list of all metadata targets, then second walking the metadata to
# construct the final list.
cmdline_deps = []
if (defined(invoker.cmdline)) {
kernel_cmdline("${target_name}_extra_cmdline") {
args = invoker.cmdline
}
cmdline_deps += [ ":${target_name}_extra_cmdline" ]
}
if (defined(invoker.cmdline_deps)) {
cmdline_deps += invoker.cmdline_deps
}
generated_file(labels.kernel_cmdline_args) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
data_keys = [ "zbi_config_entry" ]
walk_keys = [ "zbi_input_barrier" ]
outputs = [ files.kernel_cmdline_args ]
output_conversion = "json"
deps = cmdline_deps
}
# Find all the files to add to BootFS.
distribution_manifest(labels.bootfs_entries_metadata) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
outputs = [ files.bootfs_entries_metadata ]
deps = bootfs_labels
}
# Construct a list of bootfs packages to add to the image assembly config.
# Ignores any fuchsia_driver_packages and fuchsia_shell_packages
package_manifests_list(labels.bootfs_package_list) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
filename = files.bootfs_package_list
deps = bootfs_package_labels
}
action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
script = "//build/assembly/scripts/generated_image_assembly_config.py"
outputs = [ invoker.output_path ]
inputs = [
build_info_files.minimum_utc_stamp,
files.base_package_list,
files.cache_package_list,
files.extra_base_list,
files.extra_base_deps_list,
files.kernel_image_metadata,
files.kernel_cmdline_args,
files.boot_args,
files.bootfs_entries_metadata,
files.bootfs_package_list,
]
deps = [
":${labels.base_package_list}",
":${labels.boot_args}",
":${labels.bootfs_entries_metadata}",
":${labels.bootfs_package_list}",
":${labels.cache_package_list}",
":${labels.extra_base_deps_list}",
":${labels.extra_base_list}",
":${labels.kernel_cmdline_args}",
":${labels.kernel_image_metadata}",
"//build/info:latest-commit-date",
]
args = [
"--base-packages-list",
rebase_path(files.base_package_list, root_build_dir),
"--cache-packages-list",
rebase_path(files.cache_package_list, root_build_dir),
"--extra-files-packages-list",
rebase_path(files.extra_base_list, root_build_dir),
"--extra-deps-files-packages-list",
rebase_path(files.extra_base_deps_list, root_build_dir),
"--kernel-image-metadata",
rebase_path(files.kernel_image_metadata, root_build_dir),
"--kernel-cmdline",
rebase_path(files.kernel_cmdline_args, root_build_dir),
"--kernel-clock-backstop",
rebase_path(build_info_files.minimum_utc_stamp, root_build_dir),
"--boot-args",
rebase_path(files.boot_args, root_build_dir),
"--bootfs-entries",
rebase_path(files.bootfs_entries_metadata, root_build_dir),
"--bootfs-packages-list",
rebase_path(files.bootfs_package_list, root_build_dir),
"--output",
rebase_path(invoker.output_path, root_build_dir),
]
metadata = {
# We insert these barriers to prevent the dependencies from including
# files "higher up" in the dependency chain.
package_barrier = []
config_package_barrier = []
distribution_entries_barrier = []
}
}
}