| # Copyright 2026 The Fuchsia Authors |
| # |
| # Use of this source code is governed by a MIT-style |
| # license that can be found in the LICENSE file or at |
| # https://opensource.org/licenses/MIT |
| |
| # Defines a group of dependencies required only by kernel unit tests. |
| # |
| # This template conditionally forwards `public_deps` only when building in a |
| # kernel switchset in which unit tests are enabled. Otherwise, this evaluates |
| # to an empty group. |
| # |
| # In Rust we cannot always separate out tests from the source under test. |
| # Being in the middle of C++-to-Rust migration, it is also difficult to stamp |
| # out separate testonly rust source targets and have those aggregate only to |
| # the testonly kernel executables. The upshot is that need to be able to have |
| # non-testonly kernels depend on sources that feature compiled-away tests, and |
| # for the dependencies of that test code not to trigger unused dependency |
| # complaints from the compiler. This template addresses this problem by being an |
| # aggregator of such deps. https://fxbug.dev/537843321 tracks rethinking this |
| # setup. |
| # |
| # Parameters |
| # |
| # * public_deps |
| # - Required: Dependencies needed by unit tests. None of these dependencies |
| # may be testonly. |
| # - Type: list(label) |
| # |
| # * testonly |
| # - Disallowed: Production kernel targets must be able to unconditionally |
| # depend on this target. |
| # |
| # * visibility |
| # - Optional: The usual GN meaning. |
| template("kernel_test_deps") { |
| assert(defined(invoker.public_deps), |
| "kernel_test_deps($target_name) must define public_deps") |
| |
| assert(!defined(invoker.testonly), |
| "kernel_test_deps($target_name) must not set testonly") |
| |
| group(target_name) { |
| forward_variables_from(invoker, [ "visibility" ]) |
| |
| if (toolchain_variant.tags + [ "kernel-with-tests" ] - |
| [ "kernel-with-tests" ] != toolchain_variant.tags) { |
| forward_variables_from(invoker, [ "public_deps" ]) |
| } else { |
| not_needed(invoker, [ "public_deps" ]) |
| } |
| } |
| } |