Debian Codegraph @

utils/bazel/llvm-project-overlay/clang-tools-extra/include-cleaner/BUILD.bazel

raw
1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5 load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
6 load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
7 load("//llvm:lit_test.bzl", "lit_test", "package_path")
8
9 package(
10 default_visibility = ["//visibility:public"],
11 features = ["layering_check"],
12 )
13
14 licenses(["notice"])
15
16 cc_library(
17 name = "include_cleaner",
18 srcs = glob([
19 "lib/*.h",
20 "lib/*.cpp",
21 ]),
22 hdrs = glob(["include/clang-include-cleaner/*.h"]),
23 includes = ["include/"],
24 deps = [
25 "//clang:ast",
26 "//clang:basic",
27 "//clang:format",
28 "//clang:frontend",
29 "//clang:lex",
30 "//clang:tooling_core",
31 "//clang:tooling_inclusions",
32 "//llvm:Support",
33 ],
34 )
35
36 cc_library(
37 name = "include_cleaner_internal",
38 hdrs = glob(["lib/*.h"]),
39 includes = ["lib/"],
40 visibility = [":__subpackages__"],
41 deps = [
42 ":include_cleaner",
43 "//clang:ast",
44 "//clang:basic",
45 "//clang:frontend",
46 "//clang:lex",
47 "//clang:tooling_inclusions",
48 "//llvm:Support",
49 ],
50 )
51
52 cc_binary(
53 name = "clang-include-cleaner",
54 srcs = glob([
55 "tool/*.cpp",
56 ]),
57 deps = [
58 ":include_cleaner",
59 ":include_cleaner_internal",
60 "//clang:frontend",
61 "//clang:lex",
62 "//clang:tooling",
63 "//llvm:Support",
64 ],
65 )
66
67 cc_test(
68 name = "unittests",
69 srcs = glob(["unittests/*.cpp"]),
70 deps = [
71 ":include_cleaner",
72 ":include_cleaner_internal",
73 "//clang:ast",
74 "//clang:basic",
75 "//clang:format",
76 "//clang:frontend",
77 "//clang:lex",
78 "//clang:serialization",
79 "//clang:testing",
80 "//clang:tooling",
81 "//clang:tooling_inclusions",
82 "//llvm:Support",
83 "//llvm:TestingAnnotations",
84 "//third-party/unittest:gmock",
85 "//third-party/unittest:gtest",
86 ],
87 )
88
89 LLVM_LIT_PATH_FUNCTION = " " + \
90 "# Allow generated file to be relocatable.\n" + \
91 "from pathlib import Path\n" + \
92 "def path(p):\n" + \
93 " p = Path(p)\n" + \
94 " if p.exists: return str(p.resolve())\n" + \
95 " if not p: return ''\n" + \
96 " return str((Path(__file__).parent / p).resolve())\n"
97
98 LIT_SITE_CFG_IN_HEADER = "# Autogenerated, do not edit." + LLVM_LIT_PATH_FUNCTION
99
100 expand_template(
101 name = "lit_site_cfg_py",
102 testonly = True,
103 out = "test/lit.site.cfg.py",
104 substitutions = {
105 "@CMAKE_CURRENT_BINARY_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD") + "/test",
106 "@CMAKE_CURRENT_SOURCE_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD") + "/test",
107 "@CURRENT_TOOLS_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD"),
108 "@LIT_SITE_CFG_IN_HEADER@": LIT_SITE_CFG_IN_HEADER,
109 "@LLVM_LIBS_DIR@": package_path("//llvm:BUILD"),
110 "@LLVM_LIT_TOOLS_DIR@": package_path("//llvm:BUILD"),
111 "@LLVM_TOOLS_DIR@": package_path("//llvm:BUILD"),
112 "@TARGET_TRIPLE@": "",
113 '"@Python3_EXECUTABLE@"': "sys.executable",
114 },
115 template = "test/lit.site.cfg.py.in",
116 )
117
118 [
119 lit_test(
120 name = "%s.test" % src,
121 srcs = [src],
122 args = ["-svv"],
123 data = glob(["test/Inputs/**/*"]) + [
124 "test/lit.cfg.py",
125 "test/lit.site.cfg.py",
126 ":clang-include-cleaner",
127 "//llvm:FileCheck",
128 "//llvm:count",
129 "//llvm:not",
130 ],
131 )
132 for src in glob(["test/*.cpp"])
133 ]