| # Copyright 2025 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. |
| |
| # Pretends to generate the tests.json and makes it available as a build api. |
| # |
| # Parameters: |
| # |
| # pb_test_groups (optional; default = []) |
| # A list of product_bundle_test_group targets. |
| # These targets declare a set of tests and a product bundle to run them on. |
| # The test specs will be modified to point to the product bundle. |
| # |
| template("tests_json") { |
| # Ensure this template is only used in approved locations. |
| # This ensures that they are resolved by gn-gen. |
| # See root_patterns in the //.gn file. |
| _valid_dirs = [ "//:*" ] |
| if (!label_matches(":$target_name", _valid_dirs)) { |
| assert( |
| false, |
| "test_collection can only be used in these directories: $_valid_dirs") |
| } |
| |
| _product_bundle_test_groups = [] |
| if (defined(invoker.pb_test_groups)) { |
| _product_bundle_test_groups += invoker.pb_test_groups |
| } |
| |
| files = { |
| output = "${root_build_dir}/tests.json" |
| product_bundle_test_groups = |
| "${target_out_dir}/${target_name}/product_bundle_test_groups.json" |
| } |
| |
| targets = { |
| product_bundle_test_groups = "${target_name}_product_bundle_test_groups" |
| } |
| |
| generated_file(targets.product_bundle_test_groups) { |
| testonly = true |
| data_keys = [ "pb_test_groups" ] |
| deps = _product_bundle_test_groups |
| outputs = [ files.product_bundle_test_groups ] |
| output_conversion = "json" |
| } |
| |
| action(target_name) { |
| deps = [ ":${targets.product_bundle_test_groups}" ] |
| testonly = true |
| script = "//build/scripts/no_op.sh" |
| outputs = [ files.output ] |
| args = rebase_path(outputs, root_build_dir) |
| metadata = { |
| build_api_modules = [ "tests" ] |
| build_api_client_info = [ "tests=tests.json" ] |
| } |
| } |
| } |