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(
name = "windows",
values = {"cpu": "x64_windows"},
)
config_setting(
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
constraint_values = ["@bazel_tools//platforms:windows"],
)
config_setting(
@ -51,6 +46,13 @@ config_setting(
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
cc_library(
name = "gtest",
@ -73,21 +75,14 @@ cc_library(
"googletest/include/gtest/*.h",
"googlemock/include/gmock/*.h",
]),
copts = select(
{
":windows": [],
":windows_msvc": [],
"//conditions:default": ["-pthread"],
},
),
defines = select(
{
":has_absl": [
"GTEST_HAS_ABSL=1",
],
"//conditions:default": [],
},
),
copts = select({
":windows": [],
"//conditions:default": ["-pthread"],
}),
defines = select({
":has_absl": ["GTEST_HAS_ABSL=1"],
"//conditions:default": [],
}),
includes = [
"googlemock",
"googlemock/include",
@ -96,31 +91,24 @@ cc_library(
],
linkopts = select({
":windows": [],
":windows_msvc": [],
"//conditions:default": [
"-pthread",
],
"//conditions:default": ["-pthread"],
}),
deps = select({
":has_absl": [
"@com_google_absl//absl/debugging:failure_signal_handler",
"@com_google_absl//absl/debugging:stacktrace",
"@com_google_absl//absl/debugging:symbolize",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:variant",
],
"//conditions:default": [],
}),
deps = select(
{
":has_absl": [
"@com_google_absl//absl/debugging:failure_signal_handler",
"@com_google_absl//absl/debugging:stacktrace",
"@com_google_absl//absl/debugging:symbolize",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:variant",
],
"//conditions:default": [],
},
),
)
cc_library(
name = "gtest_main",
srcs = [
"googlemock/src/gmock_main.cc",
],
srcs = ["googlemock/src/gmock_main.cc"],
deps = [":gtest"],
)
@ -174,7 +162,5 @@ cc_test(
name = "sample10_unittest",
size = "small",
srcs = ["googletest/samples/sample10_unittest.cc"],
deps = [
":gtest",
],
deps = [":gtest"],
)

View File

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

View File

@ -34,21 +34,6 @@
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
cc_test(
name = "gtest_all_test",
@ -73,26 +58,23 @@ cc_test(
"googletest-env-var-test_.cc",
"googletest-filter-unittest_.cc",
"googletest-break-on-failure-unittest_.cc",
"googletest-listener-test.cc",
"googletest-output-test_.cc",
"googletest-list-tests-unittest_.cc",
"googletest-shuffle-test_.cc",
"googletest-uninitialized-test_.cc",
"googletest-death-test_ex_test.cc",
"googletest-param-test-test",
"googletest-throw-on-failure-test_.cc",
"googletest-param-test-invalid-name1-test_.cc",
"googletest-param-test-invalid-name2-test_.cc",
"googletest-listener-test.cc",
"googletest-output-test_.cc",
"googletest-list-tests-unittest_.cc",
"googletest-shuffle-test_.cc",
"googletest-uninitialized-test_.cc",
"googletest-death-test_ex_test.cc",
"googletest-param-test-test",
"googletest-throw-on-failure-test_.cc",
"googletest-param-test-invalid-name1-test_.cc",
"googletest-param-test-invalid-name2-test_.cc",
],
) + select({
"//:windows": [],
"//:windows_msvc": [],
"//conditions:default": [],
}),
copts = select({
"//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
"//:windows_msvc": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
"//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"],
}),
includes = [
@ -103,15 +85,11 @@ cc_test(
],
linkopts = select({
"//:windows": [],
"//:windows_msvc": [],
"//conditions:default": [
"-pthread",
],
"//conditions:default": ["-pthread"],
}),
deps = ["//:gtest_main"],
)
# Tests death tests.
cc_test(
name = "googletest-death-test-test",
@ -196,13 +174,12 @@ cc_binary(
deps = ["//:gtest"],
)
py_test(
name = "googletest-output-test",
size = "small",
srcs = ["googletest-output-test.py"],
args = select({
":has_absl": [],
"//:has_absl": [],
"//conditions:default": ["--no_stacktrace_support"],
}),
data = [
@ -257,7 +234,6 @@ py_test(
deps = [":gtest_test_utils"],
)
cc_binary(
name = "googletest-break-on-failure-unittest_",
testonly = 1,
@ -265,8 +241,6 @@ cc_binary(
deps = ["//:gtest"],
)
py_test(
name = "googletest-break-on-failure-unittest",
size = "small",
@ -275,7 +249,6 @@ py_test(
deps = [":gtest_test_utils"],
)
cc_test(
name = "gtest_assert_by_exception_test",
size = "small",
@ -283,8 +256,6 @@ cc_test(
deps = ["//:gtest"],
)
cc_binary(
name = "googletest-throw-on-failure-test_",
testonly = 1,
@ -300,7 +271,6 @@ py_test(
deps = [":gtest_test_utils"],
)
cc_binary(
name = "googletest-list-tests-unittest_",
testonly = 1,
@ -378,7 +348,7 @@ py_test(
"gtest_xml_test_utils.py",
],
args = select({
":has_absl": [],
"//:has_absl": [],
"//conditions:default": ["--no_stacktrace_support"],
}),
data = [
@ -449,7 +419,6 @@ py_test(
deps = [":gtest_test_utils"],
)
py_test(
name = "googletest-json-outfiles-test",
size = "small",
@ -471,18 +440,19 @@ py_test(
"googletest-json-output-unittest.py",
"gtest_json_test_utils.py",
],
args = select({
"//:has_absl": [],
"//conditions:default": ["--no_stacktrace_support"],
}),
data = [
# We invoke gtest_no_test_unittest to verify the JSON output
# when the test program contains no test definition.
":gtest_no_test_unittest",
":gtest_xml_output_unittest_",
],
args = select({
":has_absl": [],
"//conditions:default": ["--no_stacktrace_support"],
}),
deps = [":gtest_test_utils"],
)
# Verifies interaction of death tests and exceptions.
cc_test(
name = "googletest-death-test_ex_catch_test",