# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//llvm:lit_test.bzl", "lit_test", "package_path")
package(
default_visibility = ["//visibility:public"],
features = ["layering_check"],
)
licenses(["notice"])
cc_library(
name = "include_cleaner",
srcs = glob([
"lib/*.h",
"lib/*.cpp",
]),
hdrs = glob(["include/clang-include-cleaner/*.h"]),
includes = ["include/"],
deps = [
"//clang:ast",
"//clang:basic",
"//clang:format",
"//clang:frontend",
"//clang:lex",
"//clang:tooling_core",
"//clang:tooling_inclusions",
"//llvm:Support",
],
)
cc_library(
name = "include_cleaner_internal",
hdrs = glob(["lib/*.h"]),
includes = ["lib/"],
visibility = [":__subpackages__"],
deps = [
":include_cleaner",
"//clang:ast",
"//clang:basic",
"//clang:frontend",
"//clang:lex",
"//clang:tooling_inclusions",
"//llvm:Support",
],
)
cc_binary(
name = "clang-include-cleaner",
srcs = glob([
"tool/*.cpp",
]),
deps = [
":include_cleaner",
":include_cleaner_internal",
"//clang:frontend",
"//clang:lex",
"//clang:tooling",
"//llvm:Support",
],
)
cc_test(
name = "unittests",
srcs = glob(["unittests/*.cpp"]),
deps = [
":include_cleaner",
":include_cleaner_internal",
"//clang:ast",
"//clang:basic",
"//clang:format",
"//clang:frontend",
"//clang:lex",
"//clang:serialization",
"//clang:testing",
"//clang:tooling",
"//clang:tooling_inclusions",
"//llvm:Support",
"//llvm:TestingAnnotations",
"//third-party/unittest:gmock",
"//third-party/unittest:gtest",
],
)
LLVM_LIT_PATH_FUNCTION = " " + \
"# Allow generated file to be relocatable.\n" + \
"from pathlib import Path\n" + \
"def path(p):\n" + \
" p = Path(p)\n" + \
" if p.exists: return str(p.resolve())\n" + \
" if not p: return ''\n" + \
" return str((Path(__file__).parent / p).resolve())\n"
LIT_SITE_CFG_IN_HEADER = "# Autogenerated, do not edit." + LLVM_LIT_PATH_FUNCTION
expand_template(
name = "lit_site_cfg_py",
testonly = True,
out = "test/lit.site.cfg.py",
substitutions = {
"@CMAKE_CURRENT_BINARY_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD") + "/test",
"@CMAKE_CURRENT_SOURCE_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD") + "/test",
"@CURRENT_TOOLS_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD"),
"@LIT_SITE_CFG_IN_HEADER@": LIT_SITE_CFG_IN_HEADER,
"@LLVM_LIBS_DIR@": package_path("//llvm:BUILD"),
"@LLVM_LIT_TOOLS_DIR@": package_path("//llvm:BUILD"),
"@LLVM_TOOLS_DIR@": package_path("//llvm:BUILD"),
"@TARGET_TRIPLE@": "",
'"@Python3_EXECUTABLE@"': "sys.executable",
},
template = "test/lit.site.cfg.py.in",
)
[
lit_test(
name = "%s.test" % src,
srcs = [src],
data = glob(["test/Inputs/**/*"]) + [
"test/lit.cfg.py",
"test/lit.site.cfg.py",
":clang-include-cleaner",
"//llvm:FileCheck",
"//llvm:count",
"//llvm:not",
],
args = ["-svv"],
)
for src in glob(["test/*.cpp"])
]