Googletest export

Improve Bazel build files.

New target gtest_prod allows access to the FRIEND_TEST macro without depending on the entirety of GTest in production executables. Additionally, duplicate config_setting rules were removed and formatting was adjusted.

PiperOrigin-RevId: 220279205
This commit is contained in:
krzysio 2018-11-06 10:37:19 -05:00 committed by Gennadiy Civil
parent 529c2c6f4a
commit 105579a6e4
3 changed files with 56 additions and 117 deletions

View File

@ -38,12 +38,7 @@ licenses(["notice"])
config_setting( config_setting(
name = "windows", name = "windows",
values = {"cpu": "x64_windows"}, constraint_values = ["@bazel_tools//platforms:windows"],
)
config_setting(
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
) )
config_setting( config_setting(
@ -51,6 +46,13 @@ config_setting(
values = {"define": "absl=1"}, values = {"define": "absl=1"},
) )
# Library that defines the FRIEND_TEST macro.
cc_library(
name = "gtest_prod",
hdrs = ["googletest/include/gtest/gtest_prod.h"],
includes = ["googletest/include"],
)
# Google Test including Google Mock # Google Test including Google Mock
cc_library( cc_library(
name = "gtest", name = "gtest",
@ -73,21 +75,14 @@ cc_library(
"googletest/include/gtest/*.h", "googletest/include/gtest/*.h",
"googlemock/include/gmock/*.h", "googlemock/include/gmock/*.h",
]), ]),
copts = select( copts = select({
{
":windows": [], ":windows": [],
":windows_msvc": [],
"//conditions:default": ["-pthread"], "//conditions:default": ["-pthread"],
}, }),
), defines = select({
defines = select( ":has_absl": ["GTEST_HAS_ABSL=1"],
{
":has_absl": [
"GTEST_HAS_ABSL=1",
],
"//conditions:default": [], "//conditions:default": [],
}, }),
),
includes = [ includes = [
"googlemock", "googlemock",
"googlemock/include", "googlemock/include",
@ -96,13 +91,9 @@ cc_library(
], ],
linkopts = select({ linkopts = select({
":windows": [], ":windows": [],
":windows_msvc": [], "//conditions:default": ["-pthread"],
"//conditions:default": [
"-pthread",
],
}), }),
deps = select( deps = select({
{
":has_absl": [ ":has_absl": [
"@com_google_absl//absl/debugging:failure_signal_handler", "@com_google_absl//absl/debugging:failure_signal_handler",
"@com_google_absl//absl/debugging:stacktrace", "@com_google_absl//absl/debugging:stacktrace",
@ -112,15 +103,12 @@ cc_library(
"@com_google_absl//absl/types:variant", "@com_google_absl//absl/types:variant",
], ],
"//conditions:default": [], "//conditions:default": [],
}, }),
),
) )
cc_library( cc_library(
name = "gtest_main", name = "gtest_main",
srcs = [ srcs = ["googlemock/src/gmock_main.cc"],
"googlemock/src/gmock_main.cc",
],
deps = [":gtest"], deps = [":gtest"],
) )
@ -174,7 +162,5 @@ cc_test(
name = "sample10_unittest", name = "sample10_unittest",
size = "small", size = "small",
srcs = ["googletest/samples/sample10_unittest.cc"], srcs = ["googletest/samples/sample10_unittest.cc"],
deps = [ deps = [":gtest"],
":gtest",
],
) )

View File

@ -34,28 +34,19 @@
licenses(["notice"]) licenses(["notice"])
""" gmock own tests """ # Tests for GMock itself
cc_test( cc_test(
name = "gmock_all_test", name = "gmock_all_test",
size = "small", size = "small",
srcs = glob( srcs = glob(include = ["gmock-*.cc"]),
include = [
"gmock-*.cc",
],
),
linkopts = select({ linkopts = select({
"//:windows": [], "//:windows": [],
"//:windows_msvc": [], "//conditions:default": ["-pthread"],
"//conditions:default": [
"-pthread",
],
}), }),
deps = ["//:gtest"], deps = ["//:gtest"],
) )
# Py tests # Python tests
py_library( py_library(
name = "gmock_test_utils", name = "gmock_test_utils",
testonly = 1, testonly = 1,
@ -66,9 +57,7 @@ cc_binary(
name = "gmock_leak_test_", name = "gmock_leak_test_",
testonly = 1, testonly = 1,
srcs = ["gmock_leak_test_.cc"], srcs = ["gmock_leak_test_.cc"],
deps = [ deps = ["//:gtest_main"],
"//:gtest_main",
],
) )
py_test( py_test(
@ -89,17 +78,13 @@ cc_test(
"gmock_link_test.cc", "gmock_link_test.cc",
"gmock_link_test.h", "gmock_link_test.h",
], ],
deps = [ deps = ["//:gtest_main"],
"//:gtest_main",
],
) )
cc_binary( cc_binary(
name = "gmock_output_test_", name = "gmock_output_test_",
srcs = ["gmock_output_test_.cc"], srcs = ["gmock_output_test_.cc"],
deps = [ deps = ["//:gtest"],
"//:gtest",
],
) )
py_test( py_test(
@ -117,7 +102,5 @@ cc_test(
name = "gmock_test", name = "gmock_test",
size = "small", size = "small",
srcs = ["gmock_test.cc"], srcs = ["gmock_test.cc"],
deps = [ deps = ["//:gtest_main"],
"//:gtest_main",
],
) )

View File

@ -34,21 +34,6 @@
licenses(["notice"]) licenses(["notice"])
config_setting(
name = "windows",
values = {"cpu": "x64_windows"},
)
config_setting(
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
)
config_setting(
name = "has_absl",
values = {"define": "absl=1"},
)
#on windows exclude gtest-tuple.h #on windows exclude gtest-tuple.h
cc_test( cc_test(
name = "gtest_all_test", name = "gtest_all_test",
@ -83,16 +68,13 @@ cc_test(
"googletest-throw-on-failure-test_.cc", "googletest-throw-on-failure-test_.cc",
"googletest-param-test-invalid-name1-test_.cc", "googletest-param-test-invalid-name1-test_.cc",
"googletest-param-test-invalid-name2-test_.cc", "googletest-param-test-invalid-name2-test_.cc",
], ],
) + select({ ) + select({
"//:windows": [], "//:windows": [],
"//:windows_msvc": [],
"//conditions:default": [], "//conditions:default": [],
}), }),
copts = select({ copts = select({
"//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"], "//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
"//:windows_msvc": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
"//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"], "//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"],
}), }),
includes = [ includes = [
@ -103,15 +85,11 @@ cc_test(
], ],
linkopts = select({ linkopts = select({
"//:windows": [], "//:windows": [],
"//:windows_msvc": [], "//conditions:default": ["-pthread"],
"//conditions:default": [
"-pthread",
],
}), }),
deps = ["//:gtest_main"], deps = ["//:gtest_main"],
) )
# Tests death tests. # Tests death tests.
cc_test( cc_test(
name = "googletest-death-test-test", name = "googletest-death-test-test",
@ -196,13 +174,12 @@ cc_binary(
deps = ["//:gtest"], deps = ["//:gtest"],
) )
py_test( py_test(
name = "googletest-output-test", name = "googletest-output-test",
size = "small", size = "small",
srcs = ["googletest-output-test.py"], srcs = ["googletest-output-test.py"],
args = select({ args = select({
":has_absl": [], "//:has_absl": [],
"//conditions:default": ["--no_stacktrace_support"], "//conditions:default": ["--no_stacktrace_support"],
}), }),
data = [ data = [
@ -257,7 +234,6 @@ py_test(
deps = [":gtest_test_utils"], deps = [":gtest_test_utils"],
) )
cc_binary( cc_binary(
name = "googletest-break-on-failure-unittest_", name = "googletest-break-on-failure-unittest_",
testonly = 1, testonly = 1,
@ -265,8 +241,6 @@ cc_binary(
deps = ["//:gtest"], deps = ["//:gtest"],
) )
py_test( py_test(
name = "googletest-break-on-failure-unittest", name = "googletest-break-on-failure-unittest",
size = "small", size = "small",
@ -275,7 +249,6 @@ py_test(
deps = [":gtest_test_utils"], deps = [":gtest_test_utils"],
) )
cc_test( cc_test(
name = "gtest_assert_by_exception_test", name = "gtest_assert_by_exception_test",
size = "small", size = "small",
@ -283,8 +256,6 @@ cc_test(
deps = ["//:gtest"], deps = ["//:gtest"],
) )
cc_binary( cc_binary(
name = "googletest-throw-on-failure-test_", name = "googletest-throw-on-failure-test_",
testonly = 1, testonly = 1,
@ -300,7 +271,6 @@ py_test(
deps = [":gtest_test_utils"], deps = [":gtest_test_utils"],
) )
cc_binary( cc_binary(
name = "googletest-list-tests-unittest_", name = "googletest-list-tests-unittest_",
testonly = 1, testonly = 1,
@ -378,7 +348,7 @@ py_test(
"gtest_xml_test_utils.py", "gtest_xml_test_utils.py",
], ],
args = select({ args = select({
":has_absl": [], "//:has_absl": [],
"//conditions:default": ["--no_stacktrace_support"], "//conditions:default": ["--no_stacktrace_support"],
}), }),
data = [ data = [
@ -449,7 +419,6 @@ py_test(
deps = [":gtest_test_utils"], deps = [":gtest_test_utils"],
) )
py_test( py_test(
name = "googletest-json-outfiles-test", name = "googletest-json-outfiles-test",
size = "small", size = "small",
@ -471,18 +440,19 @@ py_test(
"googletest-json-output-unittest.py", "googletest-json-output-unittest.py",
"gtest_json_test_utils.py", "gtest_json_test_utils.py",
], ],
args = select({
"//:has_absl": [],
"//conditions:default": ["--no_stacktrace_support"],
}),
data = [ data = [
# We invoke gtest_no_test_unittest to verify the JSON output # We invoke gtest_no_test_unittest to verify the JSON output
# when the test program contains no test definition. # when the test program contains no test definition.
":gtest_no_test_unittest", ":gtest_no_test_unittest",
":gtest_xml_output_unittest_", ":gtest_xml_output_unittest_",
], ],
args = select({
":has_absl": [],
"//conditions:default": ["--no_stacktrace_support"],
}),
deps = [":gtest_test_utils"], deps = [":gtest_test_utils"],
) )
# Verifies interaction of death tests and exceptions. # Verifies interaction of death tests and exceptions.
cc_test( cc_test(
name = "googletest-death-test_ex_catch_test", name = "googletest-death-test_ex_catch_test",