| # Copyright 2022 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/bazel/bazel_workspace.gni") |
| import("//build/images/args.gni") |
| import("//build/python/python_action.gni") |
| |
| # Collect a newline-delimited text file of cache packages from the `ffx assembly product` call. |
| # |
| # Arguments: |
| # |
| # assembly_label (GN label) |
| # Label for the assembled_system() invocation to use, e.g. //build/images/fuchsia. |
| # |
| # namespace (string) |
| # The effective namespace used by the system label. |
| # Defaults to the 'name' of the label in 'assembly_label'. |
| # Only applicable for GN/non-Bazel assembly. |
| # |
| # outputs (list of paths) |
| # Usual GN meaning, expects a single file to write to. |
| # |
| # testonly |
| # visibility |
| template("cache_packages_from_product_assembler") { |
| assert( |
| defined(invoker.assembly_label), |
| "must define a `assembly_label` argument which points to an assembled_system() invocation") |
| assert(defined(invoker.outputs), "must define `outputs`") |
| assert(!use_bazel_images_only || !defined(invoker.namespace), |
| "`namespace` is not allowed for `use_bazel_images_only`") |
| |
| _assembly_target_name = get_label_info(invoker.assembly_label, "name") |
| _assembly_dir = get_label_info(invoker.assembly_label, "dir") |
| _assembly_namespace = _assembly_target_name |
| if (defined(invoker.namespace)) { |
| _assembly_namespace = invoker.namespace |
| } |
| |
| if (use_bazel_images_only) { |
| _assembly_gen_dir = get_label_info(invoker.assembly_label, "target_gen_dir") |
| _assembly_manifest = "${_assembly_gen_dir}/${_assembly_target_name}_product_assembly/image_assembly.json" |
| _assembly_dep = "${_assembly_dir}:${_assembly_namespace}_product_assembly" |
| } else { |
| _assembly_out_dir = get_label_info(invoker.assembly_label, "target_out_dir") |
| _assembly_manifest = |
| "${_assembly_out_dir}/${_assembly_target_name}/image_assembly.json" |
| _assembly_dep = "${_assembly_dir}:${_assembly_namespace}.product_assembler" |
| } |
| |
| python_action(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "outputs", |
| "testonly", |
| "visibility", |
| ]) |
| binary_label = |
| "//build/assembly/scripts:cache_packages_from_product_assembler" |
| args = [ |
| "--assembly-manifest", |
| rebase_path(_assembly_manifest, root_build_dir), |
| "--output", |
| rebase_path(outputs[0], root_build_dir), |
| ] |
| if (use_bazel_images_only) { |
| args += [ |
| "--rebase", |
| rebase_path(bazel_execroot, root_build_dir), |
| ] |
| } |
| inputs = [ _assembly_manifest ] |
| deps = [ _assembly_dep ] |
| } |
| } |