blob: aaec1c5c7b568059875bf8fba8e0263a5a10d5c7 [file] [log] [blame] [edit]
# 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.
import("//build/components.gni")
import("//build/components/fuchsia_package_archive.gni")
import("//sdk/ctf/build/internal/ctf.gni")
# Defines a Fuchsia package containing a test
#
# An equivalent to fuchsia_test_package, but ensures dependencies and
# test_components are allowed in CTF.
#
# Example:
# ```
# ctf_fuchsia_test_package("my-test-package") {
# plasa_element = "fidl/fuchsia.ui.composition/Flatland"
# package_name = "my-test-package"
# test_components = [ ":my-test-component" ]
# }
# ```
#
# Parameters
#
# plasa_element (optional)
# The ID of the plasa element that is tested by this test.
# See the documentation in ctf_test.gni
#
# release_in_ctf (optional)
# If set, this test is released in CTF. Defaults to true.
# Type: bool
#
# enable_ctf_test_realms (optional)
# If set, this test will have access to CTF test realms at runtime.
# See //sdk/ctf/test_realm/BUILD.gn for instructions.
# Defaults to false.
# Type: bool
#
# subpackages (optional)
# Subpackages should not be used for the interface under test.
# See fuchsia_package() for details.
template("ctf_fuchsia_test_package") {
if (!defined(invoker.release_in_ctf)) {
invoker.release_in_ctf = true
}
if (!defined(invoker.package_name)) {
invoker.package_name = target_name
}
if (!defined(invoker.enable_ctf_test_realms)) {
invoker.enable_ctf_test_realms = false
}
# cts_version is nonempty when building for release.
# Rename the package when building for release so that when it's downloaded
# as a prebuilt and added to the build the prebuilt package name doesn't
# conflict with the name of the package from HEAD.
if (cts_version != "") {
invoker.package_name += "_$cts_version"
}
not_needed(invoker, [ "enable_ctf_test_realms" ])
not_needed(invoker, [ "plasa_element" ])
not_needed(invoker, [ "release_in_ctf" ])
if (current_toolchain == default_toolchain) {
main_target_name = target_name
ctf_element_target = target_name + "_verify_deps"
ctf_element(ctf_element_target) {
deps_to_verify = []
if (defined(invoker.deps)) {
deps_to_verify += invoker.deps
}
if (defined(invoker.test_components)) {
deps_to_verify += invoker.test_components
}
invoker_label = get_label_info(main_target_name, "label_no_toolchain")
}
write_file_target = target_name + "_ctf_file"
write_ctf_file(write_file_target) {
}
fuchsia_test_package_target = target_name + "_pkg"
fuchsia_test_package(fuchsia_test_package_target) {
forward_variables_from(invoker, "*", [ "subpackages" ])
subpackages = []
if (defined(invoker.subpackages)) {
subpackages = invoker.subpackages
}
# Don't include test realm subpackages if we're building for release,
# otherwise the test's deps would be bundled with the test in CIPD.
if (cts_version == "" && invoker.enable_ctf_test_realms) {
import("//sdk/ctf/build/ctf_test_realms.gni")
subpackages += ctf_test_realms
}
}
if (invoker.release_in_ctf) {
_test_components = invoker.test_components
_manifest_name = get_target_outputs(_test_components[0])
_manifest_name = get_path_info(_manifest_name[0], "file")
ctf_test_release_archive_target = "${target_name}_release_archive"
ctf_test_release_archive(ctf_test_release_archive_target) {
package = ":$fuchsia_test_package_target"
package_name = invoker.package_name
archive_name = main_target_name
component_name = _manifest_name
if (defined(invoker.test_specs)) {
_test_specs = invoker.test_specs
log_settings = _test_specs.log_settings
}
plasa_element = ""
if (defined(invoker.plasa_element)) {
plasa_element = invoker.plasa_element
}
}
}
group(main_target_name) {
testonly = true
deps = [
":$ctf_element_target",
":$fuchsia_test_package_target",
":$write_file_target",
]
if (invoker.release_in_ctf) {
deps += [ ":$ctf_test_release_archive_target" ]
}
}
} else {
group(target_name) {
testonly = true
deps = []
}
not_needed(invoker, "*")
}
}