Introduce a tsl_cc_test() to replace tf_cc_test()

The only purpose of this macros over the native cc_test is to reintroduce the
protobuf library on tests targets when it is disabled from the TSL libraries.

PiperOrigin-RevId: 480786829
This commit is contained in:
Mehdi Amini 2022-10-12 20:36:31 -07:00 committed by TensorFlower Gardener
parent 162524ed44
commit a5e551065c
3 changed files with 169 additions and 41 deletions

View File

@ -8,8 +8,6 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
load("//tensorflow:tensorflow.default.bzl", "get_compatible_with_portable")
load(
"//tensorflow:tensorflow.bzl",
"tf_cc_test",
"tf_cc_tests",
"tf_copts",
)
load(
@ -23,6 +21,7 @@ load(
"tf_resource_deps",
"tf_testing_deps",
"tf_windows_aware_platform_deps",
"tsl_cc_test",
"tsl_protobuf_deps",
)
load(
@ -97,7 +96,7 @@ cc_library(
],
)
tf_cc_test(
tsl_cc_test(
name = "denormal_test",
size = "small",
srcs = ["denormal_test.cc"],
@ -853,7 +852,7 @@ cc_library(
alwayslink = 1,
)
tf_cc_tests(
tsl_cc_test(
name = "stacktrace_handler_test",
size = "small",
srcs = [
@ -1104,7 +1103,7 @@ cc_library(
] + tf_windows_aware_platform_deps("stacktrace"),
)
tf_cc_test(
tsl_cc_test(
name = "stacktrace_test",
size = "small",
srcs = [
@ -1144,7 +1143,7 @@ cc_library(
] + tf_fingerprint_deps(),
)
tf_cc_test(
tsl_cc_test(
name = "fingerprint_test",
size = "small",
srcs = ["fingerprint_test.cc"],
@ -1187,7 +1186,7 @@ cc_library(
compatible_with = get_compatible_with_portable(),
)
tf_cc_test(
tsl_cc_test(
name = "ctstring_test",
size = "small",
srcs = ["ctstring_test.cc"],
@ -1198,7 +1197,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "hash_test",
size = "small",
srcs = ["hash_test.cc"],
@ -1211,7 +1210,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "path_test",
size = "small",
srcs = ["path_test.cc"],
@ -1222,7 +1221,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "random_test",
srcs = ["random_test.cc"],
deps = [
@ -1233,7 +1232,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "tstring_test",
size = "small",
srcs = ["tstring_test.cc"],
@ -1265,7 +1264,7 @@ cc_library(
alwayslink = 1,
)
tf_cc_test(
tsl_cc_test(
name = "status_test",
size = "small",
srcs = ["status_test.cc"],
@ -1280,7 +1279,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "statusor_test",
size = "small",
srcs = ["statusor_test.cc"],
@ -1294,7 +1293,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "status_matchers_test",
size = "small",
srcs = ["status_matchers_test.cc"],
@ -1346,7 +1345,7 @@ cc_library(
] + tf_platform_deps("unbounded_work_queue"),
)
tf_cc_test(
tsl_cc_test(
name = "unbounded_work_queue_test",
srcs = ["unbounded_work_queue_test.cc"],
deps = [
@ -1403,7 +1402,7 @@ cc_library(
],
)
tf_cc_test(
tsl_cc_test(
name = "subprocess_test",
size = "small",
srcs = ["subprocess_test.cc"],
@ -1424,7 +1423,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "errors_test",
size = "small",
srcs = ["errors_test.cc"],
@ -1435,7 +1434,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "intrusive_ptr_test",
size = "small",
srcs = [
@ -1449,7 +1448,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "numa_test",
size = "small",
srcs = ["numa_test.cc"],
@ -1466,7 +1465,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "setround_test",
size = "small",
srcs = ["setround_test.cc"],
@ -1483,7 +1482,7 @@ tf_cc_test(
],
)
tf_cc_test(
tsl_cc_test(
name = "refcount_test",
size = "small",
srcs = [
@ -1498,22 +1497,38 @@ tf_cc_test(
],
)
tf_cc_tests(
name = "low_level_library_tests",
tsl_cc_test(
name = "integral_types_test",
size = "small",
srcs = [
"integral_types_test.cc",
"logging_test.cc",
"mutex_test.cc",
"net_test.cc",
"port_test.cc",
"scanner_test.cc",
"str_util_test.cc",
"strcat_test.cc",
"stringpiece_test.cc",
"stringprintf_test.cc",
],
create_named_test_suite = True,
deps = [
":test",
":test_main",
":types",
],
)
tsl_cc_test(
name = "logging_test",
size = "small",
srcs = [
"logging_test.cc",
],
deps = [
":logging",
":test",
":test_main",
],
)
tsl_cc_test(
name = "mutex_test",
size = "small",
srcs = [
"mutex_test.cc",
],
deps = [
":env",
":env_impl",
@ -1530,16 +1545,108 @@ tf_cc_tests(
":test",
":test_main",
":types",
"//tensorflow/core:protos_all_cc",
"//third_party/eigen3",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/types:optional",
"@zlib",
],
)
tf_cc_test(
tsl_cc_test(
name = "net_test",
size = "small",
srcs = [
"net_test.cc",
],
deps = [
":logging",
":net",
":test",
":test_main",
],
)
tsl_cc_test(
name = "port_test",
size = "small",
srcs = [
"port_test.cc",
],
deps = [
":env",
":env_impl",
":env_time",
":mutex",
":platform_port",
":test",
":test_main",
],
)
tsl_cc_test(
name = "scanner_test",
size = "small",
srcs = [
"scanner_test.cc",
],
deps = [
":scanner",
":test",
":test_main",
],
)
tsl_cc_test(
name = "str_util_test",
size = "small",
srcs = [
"str_util_test.cc",
],
deps = [
":str_util",
":test",
":test_main",
],
)
tsl_cc_test(
name = "strcat_test",
size = "small",
srcs = [
"strcat_test.cc",
],
deps = [
":strcat",
":stringprintf",
":test",
":test_main",
":types",
],
)
tsl_cc_test(
name = "stringpiece_test",
size = "small",
srcs = [
"stringpiece_test.cc",
],
deps = [
":stringpiece",
":test",
":test_main",
],
)
tsl_cc_test(
name = "stringprintf_test",
size = "small",
srcs = [
"stringprintf_test.cc",
],
deps = [
":stringprintf",
":test",
":test_main",
],
)
tsl_cc_test(
name = "numbers_test",
size = "small",
srcs = [

View File

@ -44,6 +44,7 @@ load(
_tf_testing_deps = "tf_testing_deps",
_tf_tpu_dependencies = "tf_tpu_dependencies",
_tf_windows_aware_platform_deps = "tf_windows_aware_platform_deps",
_tsl_cc_test = "tsl_cc_test",
_tsl_protobuf_deps = "tsl_protobuf_deps",
)
@ -90,3 +91,4 @@ tf_windows_aware_platform_deps = _tf_windows_aware_platform_deps
tf_tpu_dependencies = _tf_tpu_dependencies
tf_dtensor_tpu_dependencies = _tf_dtensor_tpu_dependencies
tsl_protobuf_deps = _tsl_protobuf_deps
tsl_cc_test = _tsl_cc_test

View File

@ -276,7 +276,7 @@ def cc_proto_library(
name = header_only_name,
deps = [
"@com_google_protobuf//:protobuf_headers",
] + header_only_deps + if_static([impl_name]),
] + header_only_deps + if_tsl_link_protobuf([impl_name]),
hdrs = gen_hdrs,
**kwargs
)
@ -807,6 +807,25 @@ def tf_protobuf_deps():
def tsl_protobuf_deps():
return if_tsl_link_protobuf([clean_dep("@com_google_protobuf//:protobuf")], [clean_dep("@com_google_protobuf//:protobuf_headers")])
# When tsl_link_protobuf is false, we need to add the protobuf library
# back into our binaries explicitly.
def tsl_cc_test(
name,
deps = [],
**kwargs):
native.cc_test(
name = name,
deps = deps + if_tsl_link_protobuf(
[],
[
clean_dep("@com_google_protobuf//:protobuf"),
"//tensorflow/tsl/protobuf:error_codes_proto_impl_cc_impl",
"//tensorflow/tsl/protobuf:histogram_proto_cc_impl",
],
),
**kwargs
)
def tf_portable_proto_lib():
return ["//tensorflow/core:protos_all_cc_impl"]