Skip to content

Commit 7218908

Browse files
pizzudcopybara-github
authored andcommitted
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
1 parent 144d335 commit 7218908

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ cc_library(
8383
)
8484

8585
# Google Test including Google Mock
86+
87+
# For an actual test, use `gtest` and also `gtest_main` if you depend on gtest's
88+
# main(). For a library, use `gtest_for_library` instead if the library can be
89+
# testonly.
8690
cc_library(
8791
name = "gtest",
8892
srcs = glob(
@@ -167,6 +171,16 @@ cc_library(
167171
}),
168172
)
169173

174+
# `gtest`, but testonly. See guidance on `gtest` for when to use this.
175+
alias(
176+
name = "gtest_for_library",
177+
actual = ":gtest",
178+
testonly = True,
179+
)
180+
181+
# Implements main() for tests using gtest. Prefer to depend on `gtest` as well
182+
# to ensure compliance with the layering_check Bazel feature where only the
183+
# direct hdrs values are available.
170184
cc_library(
171185
name = "gtest_main",
172186
srcs = ["googlemock/src/gmock_main.cc"],

0 commit comments

Comments
 (0)