| # 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. |
| |
| # Looks just like a generated_file() target but $outputs is like resource(). |
| # |
| # A generated_resource() target is like a resource() target whose $sources |
| # matches the $outputs of a generated_file() target, but rolled into one. |
| # Using $data_deps to this generated_resource() target in each target whose |
| # code uses $outputs at runtime ensures that the files will be present on |
| # the system. The files can have fixed contents given directly in the |
| # target or be generated from metadata collection, as in generated_file(). |
| # |
| # Parameters |
| # |
| # outputs |
| # Required: See resource.gni. |
| # |
| # See generated_file() for other parameters. |
| # |
| template("generated_resource") { |
| generated_file(target_name) { |
| original_target_name = target_name |
| forward_variables_from(invoker, "*", [ "metadata" ]) |
| assert(outputs != [] && outputs == [ outputs[0] ], |
| "generated_resource() requires a single element in `outputs") |
| |
| # Select a place to generate the contents at `gn gen` time. |
| file = "$target_gen_dir/$target_name" |
| if (defined(output_conversion) && output_conversion == "json") { |
| file += ".json" |
| } else { |
| file += ".txt" |
| } |
| |
| # Add metadata to add that file to a filesystem image. |
| metadata = { |
| # Used by the distribution_manifest() template. |
| distribution_entries_barrier = [] |
| distribution_entries = [] |
| |
| # Used by zbi() template. |
| zbi_input_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 |
| zbi_input_barrier += data_deps |
| } |
| |
| distribution_entries += [ |
| { |
| source = rebase_path(file, root_build_dir) |
| destination = outputs[0] |
| label = |
| get_label_info(":$original_target_name", "label_with_toolchain") |
| }, |
| ] |
| } |
| |
| # That static file is the actual output of this target. |
| outputs = [] |
| outputs = [ file ] |
| } |
| } |