Skip to content

Commit 76e9b2a

Browse files
authored
[libc][bazel] Introduce libc_test_library macros. (#130355)
Use it instead of libc_support_library macros for all helper libraries that are used for unit tests. See #130327 for the rationale why we want to do this. With this change, we can additionally ensure that no testonly library will end up being a dependency of production libraries.
1 parent b256302 commit 76e9b2a

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
# LLVM libc unittest library.
66

7-
load("//libc:libc_build_rules.bzl", "libc_support_library")
7+
load("//libc/test:libc_test_rules.bzl", "libc_test_library")
88

99
package(default_visibility = ["//visibility:public"])
1010

1111
licenses(["notice"])
1212

13-
libc_support_library(
13+
libc_test_library(
1414
name = "test_logger",
1515
srcs = ["TestLogger.cpp"],
1616
hdrs = ["TestLogger.h"],
@@ -29,7 +29,7 @@ libc_support_library(
2929
],
3030
)
3131

32-
libc_support_library(
32+
libc_test_library(
3333
name = "LibcUnitTest",
3434
srcs = [
3535
"BazelFilePath.cpp",
@@ -73,7 +73,7 @@ libc_support_library(
7373
],
7474
)
7575

76-
libc_support_library(
76+
libc_test_library(
7777
name = "fp_test_helpers",
7878
srcs = [
7979
"FEnvSafeTest.cpp",
@@ -108,7 +108,7 @@ libc_support_library(
108108
],
109109
)
110110

111-
libc_support_library(
111+
libc_test_library(
112112
name = "memory_matcher",
113113
srcs = [
114114
"MemoryMatcher.cpp",
@@ -127,7 +127,7 @@ libc_support_library(
127127
],
128128
)
129129

130-
libc_support_library(
130+
libc_test_library(
131131
name = "printf_matcher",
132132
srcs = [
133133
"PrintfMatcher.cpp",
@@ -144,7 +144,7 @@ libc_support_library(
144144
],
145145
)
146146

147-
libc_support_library(
147+
libc_test_library(
148148
name = "string_utils",
149149
hdrs = [
150150
"StringUtils.h",

utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,21 @@ def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], local_
4444
linkstatic = 1,
4545
**kwargs
4646
)
47+
48+
def libc_test_library(name, copts = [], local_defines = [], **kwargs):
49+
"""Add target for library used in libc tests.
50+
51+
Args:
52+
name: Library target name.
53+
copts: See cc_library.copts.
54+
local_defines: See cc_library.local_defines.
55+
**kwargs: Other attributes relevant to cc_library (e.g. "deps").
56+
"""
57+
native.cc_library(
58+
name = name,
59+
testonly = True,
60+
copts = copts + libc_common_copts(),
61+
local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
62+
linkstatic = 1,
63+
**kwargs
64+
)

utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
# Tests for LLVM libc stdlib.h functions.
66

7-
load("//libc:libc_build_rules.bzl", "libc_support_library")
8-
load("//libc/test:libc_test_rules.bzl", "libc_test")
7+
load("//libc/test:libc_test_rules.bzl", "libc_test", "libc_test_library")
98

109
package(default_visibility = ["//visibility:public"])
1110

@@ -29,7 +28,7 @@ libc_test(
2928
libc_function_deps = ["//libc:llabs"],
3029
)
3130

32-
libc_support_library(
31+
libc_test_library(
3332
name = "div_test_helper",
3433
hdrs = ["DivTest.h"],
3534
deps = ["//libc/test/UnitTest:LibcUnitTest"],
@@ -65,7 +64,7 @@ libc_test(
6564
],
6665
)
6766

68-
libc_support_library(
67+
libc_test_library(
6968
name = "atoi_test_helper",
7069
hdrs = ["AtoiTest.h"],
7170
deps = [
@@ -110,7 +109,7 @@ libc_test(
110109
deps = ["//libc:types_size_t"],
111110
)
112111

113-
libc_support_library(
112+
libc_test_library(
114113
name = "qsort_test_helper",
115114
hdrs = ["SortingTest.h"],
116115
deps = [
@@ -148,7 +147,7 @@ libc_test(
148147
deps = ["//libc:types_size_t"],
149148
)
150149

151-
libc_support_library(
150+
libc_test_library(
152151
name = "strfrom_test_helper",
153152
hdrs = ["StrfromTest.h"],
154153
deps = [
@@ -179,7 +178,7 @@ libc_test(
179178
deps = [":strfrom_test_helper"],
180179
)
181180

182-
libc_support_library(
181+
libc_test_library(
183182
name = "strtol_test_helper",
184183
hdrs = ["StrtolTest.h"],
185184
deps = [

utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
# Tests for LLVM libc string.h functions.
66

7-
load("//libc:libc_build_rules.bzl", "libc_support_library")
8-
load("//libc/test:libc_test_rules.bzl", "libc_test")
7+
load("//libc/test:libc_test_rules.bzl", "libc_test", "libc_test_library")
98

109
package(default_visibility = ["//visibility:public"])
1110

@@ -43,7 +42,7 @@ libc_test(
4342
],
4443
)
4544

46-
libc_support_library(
45+
libc_test_library(
4746
name = "strchr_test_helper",
4847
hdrs = ["StrchrTest.h"],
4948
deps = ["//libc/test/UnitTest:LibcUnitTest"],
@@ -115,7 +114,7 @@ libc_test(
115114
],
116115
)
117116

118-
libc_support_library(
117+
libc_test_library(
119118
name = "memory_check_utils",
120119
hdrs = ["memory_utils/memory_check_utils.h"],
121120
deps = [
@@ -127,7 +126,7 @@ libc_support_library(
127126
],
128127
)
129128

130-
libc_support_library(
129+
libc_test_library(
131130
name = "protected_pages",
132131
hdrs = ["memory_utils/protected_pages.h"],
133132
deps = [

utils/bazel/llvm-project-overlay/libc/test/src/strings/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
# Tests for LLVM libc strings.h functions.
66

7-
load("//libc:libc_build_rules.bzl", "libc_support_library")
87
load("//libc/test:libc_test_rules.bzl", "libc_test")
98

109
package(default_visibility = ["//visibility:public"])

utils/bazel/llvm-project-overlay/libc/utils/MPCWrapper/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# A wrapper library over MPC for use with LLVM libc math unittests.
66

7-
load("//libc:libc_build_rules.bzl", "libc_support_library")
7+
load("//libc/test:libc_test_rules.bzl", "libc_test_library")
88

99
package(default_visibility = ["//visibility:public"])
1010

@@ -26,7 +26,7 @@ cc_library(
2626
),
2727
)
2828

29-
libc_support_library(
29+
libc_test_library(
3030
name = "mpc_wrapper",
3131
srcs = ["MPCUtils.cpp"],
3232
hdrs = ["MPCUtils.h"],

utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# A wrapper library over MPFR for use with LLVM libc math unittests.
66

7-
load("//libc:libc_build_rules.bzl", "libc_support_library")
7+
load("//libc/test:libc_test_rules.bzl", "libc_test_library")
88

99
package(default_visibility = ["//visibility:public"])
1010

@@ -26,7 +26,7 @@ cc_library(
2626
),
2727
)
2828

29-
libc_support_library(
29+
libc_test_library(
3030
name = "mp_common",
3131
srcs = ["MPCommon.cpp"],
3232
hdrs = ["MPCommon.h"],
@@ -52,7 +52,7 @@ libc_support_library(
5252
],
5353
)
5454

55-
libc_support_library(
55+
libc_test_library(
5656
name = "mpfr_wrapper",
5757
srcs = ["MPFRUtils.cpp"],
5858
hdrs = ["MPFRUtils.h"],

0 commit comments

Comments
 (0)