| # 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. |
| |
| # Declare a data file to be accessible at runtime on the target device. |
| # |
| # A resource() target looks just like a copy() target but $outputs are |
| # relative target paths. Using $data_deps to this resource() target in |
| # each target whose code uses $outputs at runtime ensures that the files |
| # will be present on the system. |
| # |
| # If the file is not in the source tree, it should be generated by another |
| # target in the build listed in $deps. If that would be a generated_file() |
| # target, then use generated_resource() instead of resource(). |
| # |
| # Parameters |
| # |
| # data_deps |
| # Optional: Additional dependencies for the runtime image. These are |
| # included in the image if this target is, but are not related to the |
| # $sources list. |
| # Type: list(label) |
| # |
| # deps |
| # Optional: Targets that produce $sources. Any files listed in |
| # $sources that are produced by the build should be produced by a |
| # target listed here. This is the only thing that guarantees those |
| # files will have been built by the time the image is being packed. |
| # Targets reached only via this $deps list will *not* contribute their |
| # own contents to the image directly. For that, list them in $data_deps. |
| # Targets listed here are used only to produce the $sources files. |
| # Type: list(label) |
| # |
| # outputs |
| # Required: List of one runtime path. This must be a relative path (no |
| # leading `/`). It can use placeholders based on $sources; see copy() |
| # and `gn help source_expansion`. When this resource() target is in |
| # the dependency graph of a zbi() target, then this is the path within |
| # the BOOTFS, which appears at /boot in the namespace of early-boot and |
| # standalone Zircon processes. |
| # Type: list(path) |
| # |
| # sources |
| # Required: List of files in the source tree or build that become $outputs. |
| # See copy() for details. |
| # Type: list(file) |
| # |
| # See copy() for other parameters. |
| # |
| template("resource") { |
| group(target_name) { |
| original_target_name = target_name |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "metadata", |
| "outputs", |
| "sources", |
| ]) |
| metadata = { |
| # Used by the distribution_manifest template. |
| distribution_entries_barrier = [] |
| distribution_entries = [] |
| |
| migrated_zbi_barrier = [] |
| |
| if (defined(invoker.metadata)) { |
| forward_variables_from(invoker.metadata, "*") |
| } |
| |
| # Stop *_manifest() and zbi_test() from picking up files or |
| # zbi_input() items from the deps, but let them reach the data_deps. |
| if (defined(data_deps)) { |
| distribution_entries_barrier += data_deps |
| migrated_zbi_barrier += data_deps |
| } |
| |
| foreach(source, invoker.sources) { |
| foreach(target, process_file_template([ source ], invoker.outputs)) { |
| assert(rebase_path(target, "foo") != target, |
| "`outputs` in resource() cannot start with /") |
| distribution_entries += [ |
| { |
| source = rebase_path(source, root_build_dir) |
| destination = target |
| label = get_label_info(":$original_target_name", |
| "label_with_toolchain") |
| }, |
| ] |
| } |
| } |
| } |
| } |
| } |