[llvm] [clang-tidy] Fix bazel build after #131804 (lazy style). (PR #159289)

Ingo Müller via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 02:00:57 PDT 2025


ingomueller-net wrote:

The following are some changes I did locally that create a `custom` check enabled by a flag. However, it does not build yet because it cannot find the headers of `clang-query`, which would need more work.

```patch
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
index f779be14ee46..ea48231bf981 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
@@ -15,6 +15,21 @@ package(
 
 licenses(["notice"])
 
+# Include query-based custom checks in clang-tidy. Usage:
+#   $ bazel build -- at llvm-project//clang-tools-extra/clang-tidy:enable_query_based_custom_checks=true //...
+#   $ bazel build -- at llvm-project//clang-tools-extra/clang-tidy:enable_query_based_custom_checks=false //...
+bool_flag(
+    name = "enable_query_based_custom_checks",
+    build_setting_default = True,
+)
+
+config_setting(
+    name = "query_based_custom_checks_enabled",
+    flag_values = {
+        ":enable_query_based_custom_checks": "true",
+    },
+)
+
 # Include static analyzer checks in clang-tidy. Usage:
 #   $ bazel build -- at llvm-project//clang-tools-extra/clang-tidy:enable_static_analyzer=true //...
 #   $ bazel build -- at llvm-project//clang-tools-extra/clang-tidy:enable_static_analyzer=false //...
@@ -40,6 +55,13 @@ expand_template(
         "//conditions:default": {
             "#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER": "#define CLANG_TIDY_ENABLE_STATIC_ANALYZER 0",
         },
+    }) | select({
+        ":query_based_custom_checks_enabled": {
+            "#cmakedefine01 CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS": "#define CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS 1",
+        },
+        "//conditions:default": {
+            "#cmakedefine01 CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS": "#define CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS 0",
+        },
     }),
     template = "clang-tidy-config.h.cmake",
     visibility = ["//visibility:private"],
@@ -209,6 +231,15 @@ clang_tidy_library(
     deps = [":lib"],
 )
 
+clang_tidy_library(
+    name = "custom",
+    deps = [
+        ":lib",
+        ":utils",
+        "//clang:ast_matchers_dynamic",
+    ],
+)
+
 clang_tidy_library(
     name = "darwin",
     deps = [":lib"],
@@ -359,6 +390,9 @@ CHECKS = [
 ] + select({
     ":static_analyzer_enabled": [":mpi"],
     "//conditions:default": [],
+}) + select({
+    ":query_based_custom_checks_enabled": [":custom"],
+    "//conditions:default": [],
 })
 
 cc_library(
```

https://github.com/llvm/llvm-project/pull/159289


More information about the llvm-commits mailing list