| # 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/sdk/sdk_atom.gni") |
| import("//build/sdk/sdk_noop_atom.gni") |
| import("config.gni") |
| |
| # Copies product bundle metadata files to an SDK. |
| # |
| # Parameters |
| # |
| # category (required) |
| # Publication level of the metadata set in SDK. |
| # See //build/sdk/sdk_atom.gni. |
| |
| template("sdk_copy_product_bundle") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| |
| file_base = "product_bundle" |
| sdk_atom_id = "sdk://${file_base}/${target_name}" |
| if (product_bundle_paths == []) { |
| # Don't generate a product bundle if product_bundle_paths is empty. |
| sdk_noop_atom(target_name) { |
| id = sdk_atom_id |
| category = invoker.category |
| type = "product_bundle" |
| } |
| } else { |
| # Used to make sure the product exists in the product bundle paths provided. |
| occured = false |
| |
| product_bundle_files = [] |
| product_bundle_path = "" |
| meta_dest = "${file_base}/${target_name}.json" |
| |
| # Find the product bundle that matches the product. The value of 'name' |
| # in the product bundle data must match the product name. |
| foreach(path, product_bundle_paths) { |
| # Reset the json and product_bundle_data values after every iteration. |
| json = { |
| } |
| product_bundle_data = { |
| } |
| json = read_file(path, "json") |
| product_bundle_data = json.data |
| |
| product_bundle_name = product_bundle_data.name |
| if (product_bundle_name == target_name) { |
| occured = true |
| product_bundle_path = path |
| product_bundle_files += [ |
| { |
| source = path |
| dest = meta_dest |
| }, |
| ] |
| } |
| } |
| assert(occured, "${target_name} is missing a product bundle") |
| |
| sdk_atom(target_name) { |
| forward_variables_from(invoker, [ "category" ]) |
| |
| id = sdk_atom_id |
| meta = { |
| schema = "product_bundle-6320eef1" |
| dest = meta_dest |
| source = product_bundle_path |
| type = "product_bundle" |
| } |
| files = product_bundle_files |
| } |
| } |
| } |