| # 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/dist/fini_manifest.gni") |
| |
| # Define inputs to a dependent zbi() target. |
| # |
| # The target generates a manifest that collects any manifest_lines from its |
| # dependencies' metadata, e.g. contributed by resource() targets. It |
| # contributes metadata that will drive zbi() to use this manifest, as well |
| # as any non-BOOTFS inputs given via $sources and $args. |
| # |
| # resource() targets in the dependencies explicitly contribute to the |
| # manifest. Many other target types such as executable() and |
| # shared_library() that have a $install_path parameter (even if defaulted) |
| # implicitly contribute to the manifest. |
| # |
| # It's not necessary to use an explicit zbi_input() target just to collect |
| # files into the BOOTFS of a zbi(). Use zbi_input() explicitly to get the |
| # manifest file as an explicit build artifact, to apply a target directory |
| # prefix to the manfiest file, or to include other types. |
| # |
| # Parameters |
| # |
| # data_deps, deps |
| # Optional: Dependencies examined for metadata. Any other zbi_input() |
| # or zbi() targets in this dependency graph will flow into any zbi() |
| # target that depends on this one. Any manifest metadata will be collected |
| # here into a manifest file; see manifest_file(). |
| # Type: list(label) |
| # |
| # prefix |
| # Optional: Directory prefix prepended to the target path in each |
| # manifest entry. This is normalized when nonempty so it need not end |
| # with a `/`. |
| # Type: string |
| # Default: "" |
| # |
| # type |
| # Optional: The input type for any $sources or $args, as in the |
| # `--type` switch to the `zbi` tool. See `zbi --help` for the set of |
| # available types. A value of "" uses `zbi --files`. |
| # Type: string |
| # Default: "" |
| # |
| # sources |
| # Optional: Files to put into the ZBI. $type determines what kinds of |
| # files these can be and how their contents are used. If $type is "" |
| # (the default), then these can be manifest files or directories. |
| # Type: list(file) |
| # |
| # args |
| # Optional: Additional arguments to the `zbi` tool. These are switches |
| # that will precede the $sources and the dependee resources aggregated |
| # under "--files" on the `zbi` command line, so they can include e.g. |
| # `--prefix=...` to affect contents of manifest file. The most common use |
| # is "--entry=..." to provide literal contents right in the GN file (e.g. |
| # for `type = "cmdline"`). |
| # |
| # See manifest_file() for additional parameters. The manifest file |
| # produced from those parameters contributes to the BOOTFS (as modified |
| # by $prefix). |
| # |
| template("zbi_input") { |
| manifest_file = "$target_gen_dir/$target_name.fini" |
| |
| fini_manifest(target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "args", |
| "metadata", |
| "sources", |
| "kernel_cmdline_args", |
| ]) |
| |
| metadata = { |
| zbi_input_barrier = [] |
| |
| # Following $args and $sources entries should not be a affected by |
| # previous settings. Reset them now before appending the user-supplied |
| # args (last wins). |
| zbi_input_args = [ |
| "--prefix=", |
| |
| # The implicit type is always --files, and needs to be reset in |
| # case the previous `zbi_input_args` list collected left a |
| # different `--type=...` as the last state. |
| "--files", |
| |
| # Default compression for storage images. |
| "--compressed", |
| ] |
| |
| # This entry is used by assembly, instead of zbi_input_args, as this isn't |
| # in the form of arguments to the zbi tool. |
| if (defined(invoker.kernel_cmdline_args)) { |
| zbi_config_entry = invoker.kernel_cmdline_args |
| } |
| |
| if (defined(invoker.metadata)) { |
| forward_variables_from(invoker.metadata, "*") |
| } |
| |
| # When a zbi() target depends on this zbi_input() target, it includes |
| # other zbi_input() targets in this target's deps, but not data_deps. |
| if (defined(invoker.deps)) { |
| zbi_input_barrier += invoker.deps |
| } |
| |
| # An explicit type applies only to $sources and $args. |
| if (defined(type) && type != "") { |
| zbi_input_args += [ "--type=$type" ] |
| } |
| if (defined(prefix) && prefix != "") { |
| zbi_input_args += [ "--prefix=$prefix" ] |
| } |
| |
| # $args may also contain "--entry=..." payloads directly. |
| if (defined(invoker.args)) { |
| zbi_input_args += invoker.args |
| } |
| |
| if (defined(invoker.sources)) { |
| zbi_input_args += rebase_path(invoker.sources, root_build_dir) |
| } |
| |
| # Always include the manifest generated from the deps here. The |
| # presence of the fini_manifest() target will prevent zbi() |
| # from collecting entries that are redundant with this manifest. |
| zbi_input_args += [ |
| "--files", |
| rebase_path(manifest_file, root_build_dir), |
| ] |
| } |
| } |
| } |