blob: cb0d268e32db021765583af964286f2122630faf [file] [log] [blame]
# 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_fuchsia_package.gni")
import("//build/testing/test_spec.gni")
# Wraps a `fuchsia_test_package()` in a `BUILD.bazel` file.
# Use this template to make a `fuchsia_test_package()` target in a `BUILD.bazel`
# file be available in the GN build. Depending on the GN target will ensure
# that the corresponding Bazel target is built.
#
# Example:
# BUILD.bazel:
# fuchsia_test_package(
# name = "test_pkg",
# package_name = "example_test_package",
# ...
# )
# BUILD.gn:
# bazel_fuchsia_package("test_pkg") {
# test_package_name = "example_test_package"
# }
#
# Args:
# bazel_target: (optional)
# See: bazel_fuchsia_package.gni
#
# test_package_name: (optional)
# The `package_name` of the wrapped `fuchsia_test_package`.
# Default: target_name
#
# test_component_names: (required)
# The `name`s of components in the wrapped `fuchsia_test_package`.
#
# test_specs: (optional)
# Additional test_specs.
# See: test_spec.gni
#
# bazel_inputs: (optional)
# List of labels to bazel_input_xxx() targets that define
# the set of Ninja-generated inputs that the Bazel build command will
# use. These must be in the dependency tree of
# `//build/bazel:legacy_ninja_build_outputs`. Note that this is only used to
# ensure that said inputs are properly generated by Ninja before this
# action's command is run. The command will be able to see any input
# files exported by the @legacy_ninja_build_outputs Bazel repository,
# as there is no way to restrict them for now.
# Type: list of GN labels.
#
# deps:
# visibility:
# Usual GN meaning.
template("bazel_fuchsia_test_package") {
if (defined(invoker.test_package_name)) {
test_package_name = invoker.test_package_name
} else {
test_package_name = target_name
}
assert(defined(invoker.test_component_names),
"Must define `test_component_names`")
test_specs = []
foreach(test_component_name, invoker.test_component_names) {
test_spec_target = "${target_name}.${test_component_name}"
# Test metadata for `fx test` / test infra integration
test_spec(test_spec_target) {
if (defined(invoker.test_specs)) {
forward_variables_from(invoker.test_specs, "*")
}
package_url = "fuchsia-pkg://fuchsia.com/${test_package_name}#meta/${test_component_name}.cm"
target = get_label_info(":$test_spec_target", "label_with_toolchain")
package_label = get_label_info(":$target_name", "label_with_toolchain")
package_manifests = rebase_path(
[ "${target_out_dir}/${invoker.target_name}/package_manifest.json" ],
root_build_dir)
build_rule = "bazel_fuchsia_test_package"
}
test_specs += [ ":$test_spec_target" ]
}
bazel_fuchsia_package(target_name) {
forward_variables_from(invoker,
[
"bazel_target",
"deps",
"visibility",
"bazel_inputs",
])
package_name = test_package_name
testonly = true
if (!defined(deps)) {
deps = []
}
deps += test_specs
}
}