summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorborn-in-void <[email protected]>2026-07-08 10:44:07 +0300
committerborn-in-void <[email protected]>2026-07-08 11:11:37 +0300
commita63edbc01b528e58065aa59fefaf17a2f27d8988 (patch)
tree925c9e55f7b876221ea703148bb8837e69344254
parentad607c3561c9a0fa7555589fe2e91ab109e0bf2c (diff)
[clang-tidy] Allow clang-tidy on generated sources.
Adds an opt-in mode for clang-tidy to process generated sources. By default, clang-tidy keeps the current behavior and skips sources from the build root. With `-DTIDY_ALLOW_GENERATED=yes`, the generated `clang_tidy.py` command receives `--allow-generated-sources` and does not skip those files. commit_hash:7d7939f1fd226722c2a6a07a48ea025194897c73
-rw-r--r--build/scripts/clang_tidy.py16
-rw-r--r--build/ymake.core.conf3
2 files changed, 17 insertions, 2 deletions
diff --git a/build/scripts/clang_tidy.py b/build/scripts/clang_tidy.py
index 525518d891e..1e08a7bb688 100644
--- a/build/scripts/clang_tidy.py
+++ b/build/scripts/clang_tidy.py
@@ -43,6 +43,7 @@ def parse_args():
parser.add_argument("--checks", required=False, default="")
parser.add_argument("--header-filter", required=False, default=None)
parser.add_argument("--collect-build-volume", action="store_true")
+ parser.add_argument("--allow-generated-sources", action="store_true")
return parser.parse_known_args()
@@ -104,6 +105,13 @@ def is_generated(testing_src, build_root):
return testing_src.startswith(build_root)
+def source_relative_path(testing_src, source_root, build_root):
+ if is_generated(testing_src, build_root):
+ return os.path.relpath(testing_src, build_root)
+
+ return os.path.relpath(testing_src, source_root)
+
+
def generate_outputs(output_json):
output_obj = os.path.splitext(output_json)[0] + ".o"
open(output_obj, "w").close()
@@ -177,7 +185,7 @@ def main():
clang_tidy_bin = args.clang_tidy_bin
output_json = args.tidy_json
generate_outputs(output_json)
- if is_generated(args.testing_src, args.build_root):
+ if is_generated(args.testing_src, args.build_root) and not args.allow_generated_sources:
return
if args.header_filter is None:
# .pb.h files will be excluded because they are not in source_root
@@ -259,7 +267,11 @@ def main():
build_volume = load_build_volume(statistics_file)
if build_volume is not None:
profile[BUILD_VOLUME_PROFILE_KEY] = build_volume
- testing_src = os.path.relpath(args.testing_src, args.source_root)
+ testing_src = source_relative_path(
+ testing_src=args.testing_src,
+ source_root=args.source_root,
+ build_root=args.build_root,
+ )
tidy_fixes = load_fixes(fixes_file)
with open(output_json, "wt") as afile:
diff --git a/build/ymake.core.conf b/build/ymake.core.conf
index 0dde5d83acd..0fda05cdb61 100644
--- a/build/ymake.core.conf
+++ b/build/ymake.core.conf
@@ -238,6 +238,9 @@ when ($TIDY_ENABLED == "yes") {
}
CPP_ANALYSIS_ARGS+="--collect-build-volume"
+ when ($TIDY_ALLOW_GENERATED == "yes") {
+ CPP_ANALYSIS_ARGS+="--allow-generated-sources"
+ }
when ($TIDY_HEADER_FILTER) {
CPP_ANALYSIS_ARGS+="--header-filter=$TIDY_HEADER_FILTER"