| # 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_unittest_component.gni") |
| import("//build/config/fuchsia_cxx_version.gni") |
| |
| # Defines a component for each supported C++ version that launches a test. |
| # |
| # This template is a useful shortcut for defining classic unit tests for target |
| # devices for each supported C++ versions, but (unlike fuchsia_unittest_package) |
| # where you have multiple test targets and want to bundle them in a single test |
| # package. 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_test") { |
| # sources = [ "rot13_encoder_test.cc" ] |
| # testonly = true |
| # } |
| # |
| # sdk_cpp_unittest_component("rot13-encoder-test") { |
| # deps = [ ":rot13_encoder_decoder_test" ] |
| # } |
| # |
| # sdk_test("rot13_decoder_test") { |
| # sources = [ "rot13_decoder_test.cc" ] |
| # testonly = true |
| # } |
| # |
| # sdk_cpp_unittest_component("rot13-decoder-test") { |
| # deps = [ ":rot13_decoder_test" ] |
| # } |
| # |
| # sdk_cpp_unittest_package("rot13-tests") { |
| # sdk_cpp_test_deps = [ |
| # ":rot13-encoder-test", |
| # ":rot13-decoder-test", |
| # ] |
| # } |
| # ``` |
| # |
| # The above will generate multiple targets, each named |
| # `${target_name}-cxx${cxx_version}`. It does not create a target for |
| # `${target_name}`. |
| # See: https://fuchsia.dev/fuchsia-src/development/components/build |
| # |
| # The above will generate a manifest for each test and include all generated in |
| # a single package, which can be run with the launch URLs: |
| # |
| # fuchsia-pkg://fuchsia.com/rot13-tests#meta/rot13-encoder-test.cxx17.cm |
| # fuchsia-pkg://fuchsia.com/rot13-tests#meta/rot13-encoder-test.cxx20.cm |
| # fuchsia-pkg://fuchsia.com/rot13-tests#meta/rot13-decoder-test.cxx17.cm |
| # fuchsia-pkg://fuchsia.com/rot13-tests#meta/rot13-decoder-test.cxx20.cm |
| # |
| # Parameters |
| # |
| # * component_name |
| # - 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 |
| # component. |
| # - 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 fuchsia_unittest_component() for other parameters. |
| # |
| template("sdk_cpp_unittest_component") { |
| foreach(cxx_version, invoker.cxx_versions) { |
| fuchsia_unittest_component("${target_name}-cxx${cxx_version}") { |
| deps = [] |
| |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "component_name", |
| "sdk_cpp_test_deps", |
| ]) |
| |
| if (defined(invoker.component_name)) { |
| component_name = "${invoker.component_name}-cxx${cxx_version}" |
| } |
| |
| foreach(sdk_cpp_test_dep, invoker.sdk_cpp_test_deps) { |
| deps += [ "${sdk_cpp_test_dep}-cxx${cxx_version}" ] |
| } |
| } |
| } |
| } |
| |
| set_defaults("sdk_cpp_unittest_component") { |
| cxx_versions = fuchsia_sdk_cxx_supported_versions |
| } |