| # 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. |
| |
| import("//build/components/fuchsia_test_package.gni") |
| import("//build/components/fuchsia_unittest_component.gni") |
| import("//build/components/fuchsia_unittest_package.gni") |
| import("//build/config/fuchsia_cxx_version.gni") |
| import("//build/cpp/sdk_cpp_unittest_component.gni") |
| |
| # Defines an SDK package that contains a component per C++ version to execute |
| # a C++ test against a specific C++ version. |
| # |
| # See: https://fuchsia.dev/fuchsia-src/development/components/build |
| # |
| # This template is a useful shortcut for defining classic unit tests for target |
| # devices. Pure unit tests don't require any special capabilities, so their |
| # component manifest can be generated by the template if a manifest is not |
| # specified. |
| # |
| # Example: |
| # ``` |
| # sdk_test("rot13_encoder_decoder_test") { |
| # sources = [ "rot13_encoder_decoder_test.cc" ] |
| # testonly = true |
| # } |
| # |
| # sdk_cpp_unittest_package("rot13-test") { |
| # sdk_cpp_test_deps = [ ":rot13_encoder_decoder_test" ] |
| # } |
| # ``` |
| # |
| # The above will generate a manifest and create a test with the launch URL: |
| # fuchsia-pkg://fuchsia.com/rot13-test#meta/rot13-test.cm |
| # |
| # Parameters |
| # |
| # * component_name_prefix |
| # - Optional: The prefix of the component name, which will have |
| # `-cxx${cxx_version}` appended to it. |
| # - Type: string |
| # - Default: target_name |
| # |
| # * sdk_cpp_test_deps |
| # - Required: A list of labels of sdk_cpp_test() targets to include in the |
| # package. |
| # - Type: list(label_no_toolchain) |
| # |
| # * deps |
| # - As for fuchsia_unittest_component(). Use these only for deps that are |
| # not sdk_cpp_test() targets, and $sdk_cpp_test_deps only for deps that |
| # are sdk_cpp_test() targets. |
| # |
| # * data_deps |
| # - As for fuchsia_unittest_component(). Use these only for deps that are |
| # not sdk_cpp_test() targets, and $sdk_cpp_test_deps only for deps that |
| # are sdk_cpp_test() targets. |
| # |
| # * cxx_versions |
| # - Optional: Compile the C++ tests against these C++ versions. |
| # - Type: list(int) |
| # - Default: fuchsia_sdk_cxx_supported_versions |
| # |
| # See sdk_cpp_unittest_component() and fuchsia_test_package() for other |
| # parameters. |
| # |
| template("sdk_cpp_unittest_package") { |
| _component_target = "_sdk_cpp_unittest_package.${target_name}.component" |
| sdk_cpp_unittest_component(_component_target) { |
| forward_variables_from(invoker, "*", [ "package_name" ]) |
| visibility = [ ":*" ] |
| } |
| |
| fuchsia_test_package(target_name) { |
| test_specs = { |
| } |
| forward_variables_from(invoker, "*") |
| test_specs.build_rule = "sdk_cpp_unittest_package" |
| test_specs.has_generated_manifest = !defined(invoker.manifest) |
| |
| test_components = [] |
| foreach(cxx_version, invoker.cxx_versions) { |
| test_components += [ ":${_component_target}-cxx${cxx_version}" ] |
| } |
| } |
| } |
| |
| set_defaults("sdk_cpp_unittest_package") { |
| cxx_versions = fuchsia_sdk_cxx_supported_versions |
| } |