blob: f108db31a7d4d98d417a3d4e0fd5d575ca6505f4 [file] [log] [blame]
# 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: List of source data files 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")
assert(
is_host,
"host_test_data should only be used on host, to fix this, wrap you target with `if (is_host) { ... }`")
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" ]
# If we are in the context of a variant, also perform the copy for the
# base toolchain, as we want both the variant-selected and normal
# versions of the associated test to have its test data available at the
# prescribed relative paths.
if (current_toolchain != toolchain_variant.base) {
deps += [ ":$main_target_name(${toolchain_variant.base})" ]
}
}
test_data = get_target_outputs(":$main_target_name")
} else {
metadata_target_name = main_target_name
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
}
}
}