From 72189081cae8b729422860b195bf2cad625b7eb4 Mon Sep 17 00:00:00 2001 From: pizzud Date: Thu, 27 Feb 2025 11:48:34 -0800 Subject: [PATCH] googletest: Add testonly alias of :gtest for testonly cc_libraries to use. While a testonly library can certainly depend on a non-testonly library, gtest itself is logically testonly, but is not tagged as such for historical reasons. Having a testonly target allows gradual migrations towards a testonly-only world. PiperOrigin-RevId: 731807655 Change-Id: Ie16f17fb74b80bb6200767a3ac5bafa424162146 --- BUILD.bazel | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/BUILD.bazel b/BUILD.bazel index 0306468e7f..53501454ce 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -83,6 +83,10 @@ cc_library( ) # Google Test including Google Mock + +# For an actual test, use `gtest` and also `gtest_main` if you depend on gtest's +# main(). For a library, use `gtest_for_library` instead if the library can be +# testonly. cc_library( name = "gtest", srcs = glob( @@ -167,6 +171,16 @@ cc_library( }), ) +# `gtest`, but testonly. See guidance on `gtest` for when to use this. +alias( + name = "gtest_for_library", + actual = ":gtest", + testonly = True, +) + +# Implements main() for tests using gtest. Prefer to depend on `gtest` as well +# to ensure compliance with the layering_check Bazel feature where only the +# direct hdrs values are available. cc_library( name = "gtest_main", srcs = ["googlemock/src/gmock_main.cc"],