Skip to content

Commit 74ce508

Browse files
authored
[bazel] Add missing clang/unittests targets (#150491)
Mostly just adding tests that are in clang/unittests/CMakeLists.txt, but there a couple other cleanups here: * Add `directory_watcher` targets in clang so we can add tests for it * Add some library targets (e.g. `dataflow_testing_support`) for downstream use (e.g. unit tests outside of LLVM that use these headers in tests) * Remove `rename_tests_tooling_hdrs` which has been unused since `rename_tests` itself was deleted The InterpreterTest target added here passes on our internal CI, but fails when I run it w/ bazel for some reason: ``` [ RUN ] InterpreterTest.InstantiateTemplate JIT session error: Symbols not found: [ __clang_Interpreter_SetValueWithAlloc, _ZnwmPv26__clang_Interpreter_NewTag ] Failure value returned from cantFail wrapped call Failed to materialize symbols: { (main, { __orc_init_func.incr_module_133, $.incr_module_133.__inits.0 }) } ``` I'd like to figure out what's going on, but for now I just excluded it w/ a test filter
1 parent 763f425 commit 74ce508

File tree

2 files changed

+268
-32
lines changed

2 files changed

+268
-32
lines changed

utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,29 @@ cc_library(
18911891
],
18921892
)
18931893

1894+
cc_library(
1895+
name = "directory_watcher",
1896+
srcs = glob([
1897+
"lib/DirectoryWatcher/*.cpp",
1898+
"lib/DirectoryWatcher/*.h",
1899+
]) + select({
1900+
"@platforms//os:windows": glob(["lib/DirectoryWatcher/windows/*.cpp"]),
1901+
"@platforms//os:macos": glob(["lib/DirectoryWatcher/mac/*.cpp"]),
1902+
"@platforms//os:linux": glob(["lib/DirectoryWatcher/linux/*.cpp"]),
1903+
"//conditions:default": glob(["lib/DirectoryWatcher/default/*.cpp"]),
1904+
}),
1905+
hdrs = glob([
1906+
"include/clang/DirectoryWatcher/*.h",
1907+
]),
1908+
includes = [
1909+
"include",
1910+
"lib/DirectoryWatcher",
1911+
],
1912+
deps = [
1913+
"//llvm:Support",
1914+
],
1915+
)
1916+
18941917
cc_library(
18951918
name = "install_api",
18961919
srcs = glob([

utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel

Lines changed: 245 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# See https://llvm.org/LICENSE.txt for license information.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
package(
6-
default_visibility = ["//visibility:public"],
7-
)
5+
package(default_visibility = ["//visibility:public"])
86

97
licenses(["notice"])
108

@@ -96,6 +94,37 @@ cc_test(
9694
],
9795
)
9896

97+
cc_library(
98+
name = "dataflow_testing_support",
99+
testonly = 1,
100+
srcs = ["Analysis/FlowSensitive/TestingSupport.cpp"],
101+
hdrs = ["Analysis/FlowSensitive/TestingSupport.h"],
102+
deps = [
103+
"//clang:analysis",
104+
"//clang:ast",
105+
"//clang:ast_matchers",
106+
"//clang:basic",
107+
"//clang:lex",
108+
"//clang:serialization",
109+
"//clang:tooling",
110+
"//llvm:Support",
111+
"//llvm:TestingAnnotations",
112+
"//third-party/unittest:gtest",
113+
],
114+
)
115+
116+
cc_library(
117+
name = "dataflow_solver_test",
118+
testonly = 1,
119+
hdrs = ["Analysis/FlowSensitive/SolverTest.h"],
120+
deps = [
121+
":dataflow_testing_support",
122+
"//clang:analysis",
123+
"//third-party/unittest:gmock",
124+
"//third-party/unittest:gtest",
125+
],
126+
)
127+
99128
cc_test(
100129
name = "analysis_tests",
101130
size = "small",
@@ -205,18 +234,17 @@ cc_test(
205234
[
206235
"Format/*.cpp",
207236
"Format/*.h",
208-
"Tooling/*.h",
209237
],
210238
allow_empty = False,
211239
),
212240
copts = ["$(STACK_FRAME_UNLIMITED)"],
213241
features = ["-layering_check"], # #include "../../lib/Format/TokenAnalyzer.h"
214242
shard_count = 20,
215243
deps = [
244+
":tooling_tests_hdrs",
216245
"//clang:basic",
217246
"//clang:format",
218247
"//clang:frontend",
219-
"//clang:rewrite",
220248
"//clang:tooling_core",
221249
"//llvm:Support",
222250
"//third-party/unittest:gmock",
@@ -280,28 +308,6 @@ cc_test(
280308
],
281309
)
282310

283-
# A library to carefully expose the tooling headers using the include prefix
284-
# expected by the `rename_tests`.
285-
cc_library(
286-
name = "rename_tests_tooling_hdrs",
287-
testonly = 1,
288-
hdrs = glob(
289-
["Tooling/*.h"],
290-
allow_empty = False,
291-
),
292-
include_prefix = "unittests",
293-
deps = [
294-
"//clang:ast",
295-
"//clang:basic",
296-
"//clang:frontend",
297-
"//clang:rewrite",
298-
"//clang:tooling",
299-
"//clang:tooling_core",
300-
"//llvm:Support",
301-
"//third-party/unittest:gtest",
302-
],
303-
)
304-
305311
cc_test(
306312
name = "rewrite_tests",
307313
size = "small",
@@ -349,12 +355,12 @@ cc_library(
349355
allow_empty = False,
350356
),
351357
deps = [
358+
"//clang:analysis",
352359
"//clang:ast_matchers",
353360
"//clang:crosstu",
354361
"//clang:frontend",
355362
"//clang:static_analyzer_core",
356363
"//clang:static_analyzer_frontend",
357-
"//clang:testing",
358364
"//clang:tooling",
359365
"//third-party/unittest:gtest",
360366
],
@@ -389,18 +395,35 @@ cc_test(
389395
],
390396
)
391397

398+
cc_library(
399+
name = "tooling_tests_hdrs",
400+
testonly = 1,
401+
hdrs = glob(
402+
["Tooling/*.h"],
403+
allow_empty = False,
404+
),
405+
deps = [
406+
"//clang:ast",
407+
"//clang:basic",
408+
"//clang:frontend",
409+
"//clang:rewrite",
410+
"//clang:tooling",
411+
"//clang:tooling_core",
412+
"//llvm:Support",
413+
"//third-party/unittest:gtest",
414+
],
415+
)
416+
392417
cc_test(
393418
name = "tooling_tests",
394419
size = "medium",
395420
srcs = glob(
396-
[
397-
"Tooling/*.cpp",
398-
"Tooling/*.h",
399-
],
421+
["Tooling/*.cpp"],
400422
allow_empty = False,
401423
),
402424
shard_count = 20,
403425
deps = [
426+
":tooling_tests_hdrs",
404427
"//clang:ast",
405428
"//clang:ast_matchers",
406429
"//clang:basic",
@@ -528,3 +551,193 @@ cc_test(
528551
"//third-party/unittest:gtest_main",
529552
],
530553
)
554+
555+
cc_test(
556+
name = "crosstu_tests",
557+
size = "small",
558+
srcs = glob(
559+
["CrossTU/*.cpp"],
560+
allow_empty = False,
561+
),
562+
deps = [
563+
"//clang:ast",
564+
"//clang:crosstu",
565+
"//clang:frontend",
566+
"//clang:tooling",
567+
"//llvm:Support",
568+
"//third-party/unittest:gtest",
569+
"//third-party/unittest:gtest_main",
570+
],
571+
)
572+
573+
cc_test(
574+
name = "driver_tests",
575+
size = "small",
576+
srcs = glob(
577+
[
578+
"Driver/*.cpp",
579+
"Driver/*.h",
580+
],
581+
allow_empty = False,
582+
exclude = [
583+
"Driver/GCCVersionTest.cpp", # Includes private headers
584+
],
585+
),
586+
deps = [
587+
"//clang:basic",
588+
"//clang:driver",
589+
"//clang:frontend",
590+
"//llvm:FrontendDebug",
591+
"//llvm:MC",
592+
"//llvm:Support",
593+
"//llvm:TargetParser",
594+
"//third-party/unittest:gmock",
595+
"//third-party/unittest:gtest",
596+
"//third-party/unittest:gtest_main",
597+
],
598+
)
599+
600+
cc_test(
601+
name = "parse_tests",
602+
size = "small",
603+
srcs = glob(
604+
["Parse/*.cpp"],
605+
allow_empty = False,
606+
),
607+
deps = [
608+
"//clang:ast",
609+
"//clang:basic",
610+
"//clang:lex",
611+
"//clang:parse",
612+
"//third-party/unittest:gtest",
613+
"//third-party/unittest:gtest_main",
614+
],
615+
)
616+
617+
cc_test(
618+
name = "directory_watcher_tests",
619+
size = "small",
620+
srcs = glob(
621+
["DirectoryWatcher/*.cpp"],
622+
allow_empty = False,
623+
),
624+
deps = [
625+
"//clang:directory_watcher",
626+
"//llvm:Support",
627+
"//llvm:TestingSupport",
628+
"//third-party/unittest:gtest",
629+
"//third-party/unittest:gtest_main",
630+
],
631+
)
632+
633+
cc_test(
634+
name = "index_tests",
635+
size = "small",
636+
srcs = glob(
637+
["Index/*.cpp"],
638+
allow_empty = False,
639+
),
640+
deps = [
641+
"//clang:ast",
642+
"//clang:basic",
643+
"//clang:frontend",
644+
"//clang:index",
645+
"//clang:lex",
646+
"//clang:tooling",
647+
"//llvm:Support",
648+
"//third-party/unittest:gmock",
649+
"//third-party/unittest:gtest",
650+
"//third-party/unittest:gtest_main",
651+
],
652+
)
653+
654+
cc_test(
655+
name = "install_api_tests",
656+
size = "small",
657+
srcs = glob(
658+
["InstallAPI/*.cpp"],
659+
allow_empty = False,
660+
),
661+
deps = [
662+
"//clang:install_api",
663+
"//llvm:Support",
664+
"//llvm:TestingSupport",
665+
"//third-party/unittest:gtest",
666+
"//third-party/unittest:gtest_main",
667+
],
668+
)
669+
670+
cc_test(
671+
name = "interpreter_tests",
672+
size = "small",
673+
srcs = glob(
674+
[
675+
"Interpreter/*.cpp",
676+
"Interpreter/*.h",
677+
],
678+
allow_empty = False,
679+
),
680+
args = [
681+
# TODO: some tests fail with: "JIT session error: Symbols not found:
682+
# [ _ZnwmPv26__clang_Interpreter_NewTag, __clang_Interpreter_SetValueWithAlloc ]
683+
"--gtest_filter=-InterpreterTest.*",
684+
],
685+
deps = [
686+
"//clang:ast",
687+
"//clang:basic",
688+
"//clang:codegen",
689+
"//clang:frontend",
690+
"//clang:interpreter",
691+
"//clang:lex",
692+
"//clang:parse",
693+
"//clang:sema",
694+
"//llvm:LineEditor",
695+
"//llvm:MC",
696+
"//llvm:OrcJIT",
697+
"//llvm:OrcShared",
698+
"//llvm:Support",
699+
"//llvm:TargetParser",
700+
"//llvm:TestingSupport",
701+
"//llvm:ir_headers",
702+
"//third-party/unittest:gmock",
703+
"//third-party/unittest:gtest",
704+
"//third-party/unittest:gtest_main",
705+
],
706+
)
707+
708+
cc_test(
709+
name = "serialization_tests",
710+
size = "small",
711+
srcs = glob(
712+
["Serialization/*.cpp"],
713+
allow_empty = False,
714+
),
715+
deps = [
716+
"//clang:ast_matchers",
717+
"//clang:basic",
718+
"//clang:frontend",
719+
"//clang:lex",
720+
"//clang:parse",
721+
"//clang:serialization",
722+
"//clang:tooling",
723+
"//llvm:Support",
724+
"//third-party/unittest:gtest",
725+
"//third-party/unittest:gtest_main",
726+
],
727+
)
728+
729+
cc_test(
730+
name = "support_tests",
731+
size = "small",
732+
srcs = glob(
733+
["Support/*.cpp"],
734+
allow_empty = False,
735+
),
736+
deps = [
737+
"//clang:frontend",
738+
"//clang:lex",
739+
"//llvm:Support",
740+
"//third-party/unittest:gtest",
741+
"//third-party/unittest:gtest_main",
742+
],
743+
)

0 commit comments

Comments
 (0)