| # 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. |
| |
| # Declares host-side test data and makes them available at test runtime. |
| # |
| # It is a requirement that host tests with runtime dependencies express this |
| # by depending on instances of this template. |
| # |
| # Parameters |
| # |
| # * sources |
| # - Required: Sources to serve as host test data. |
| # - Type: list(path) |
| # |
| # * outputs |
| # - Optional: Where to copy the provided sources. If provided, these |
| # locations (and not those of sources) will be declared as runtime |
| # dependencies. |
| # - Type: list(path relative to $root_build_dir) |
| # |
| # * deps |
| # * visibility |
| # - Optional: Usual GN meanings. |
| # |
| template("host_test_data") { |
| assert(defined(invoker.sources), "sources are required") |
| |
| main_target_name = target_name |
| if (defined(invoker.outputs)) { |
| metadata_target_name = "${target_name}_metadata" |
| |
| # The main target that copies test data to the build directory. |
| # It depends on the generated group `group_target_name`, which |
| # carries the `test_runtime_deps` metadata. |
| # The copy rule is the main target so that clients can still |
| # call `get_target_outputs` on it. |
| copy(main_target_name) { |
| testonly = true |
| forward_variables_from(invoker, "*") |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ ":$metadata_target_name" ] |
| } |
| test_data = get_target_outputs(":$main_target_name") |
| } else { |
| metadata_target_name = main_target_name |
| |
| # In this case, all provided sources should lie within the build |
| # directory. |
| foreach(source, invoker.sources) { |
| in_build_dir = |
| get_path_info(rebase_path(source, root_build_dir), "dir") != ".." |
| assert( |
| in_build_dir, |
| "$source must be within the build directory to be declared as test data") |
| } |
| test_data = invoker.sources |
| } |
| |
| # This group exists only to carry the `test_runtime_deps` metadata, which |
| # is aggregated by test_spec(). |
| group(metadata_target_name) { |
| testonly = true |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "visibility", |
| ]) |
| metadata = { |
| test_runtime_deps = test_data |
| } |
| } |
| } |