浏览代码

Fix things up to make running clang-tidy easier. (#2246)

run_clang_tidy.py (the clang-tools-extras version) is parallel so should be feasible to work with. I'm trying to codify this mainly because finding out the right invocation can be difficult.

This fixes some loading of re2 and proto that's started to become an issue.

It's hard to see actual issues because of the identifier length warning being turned off in #2244, and just general issue creep. There may be more fixes to do but this should still be an improvement.
Jon Ross-Perkins 3 年之前
父节点
当前提交
11a138b467
共有 3 个文件被更改,包括 50 次插入0 次删除
  1. 4 0
      compile_flags.txt
  2. 4 0
      scripts/create_compdb.py
  3. 42 0
      scripts/run_clang_tidy.py

+ 4 - 0
compile_flags.txt

@@ -70,6 +70,10 @@ bazel-execroot/external/com_google_googletest
 -iquote
 bazel-bin/external/com_google_googletest
 -iquote
+bazel-execroot/external/com_googlesource_code_re2
+-iquote
+bazel-bin/external/com_googlesource_code_re2
+-iquote
 bazel-execroot/external/bazel_tools
 -iquote
 bazel-bin/external/bazel_tools

+ 4 - 0
scripts/create_compdb.py

@@ -97,6 +97,7 @@ print(
 )
 
 # Now collect the generated file labels.
+# cc_proto_library generates files, but they aren't seen with "generated file".
 generated_file_labels = subprocess.run(
     [
         bazel,
@@ -106,6 +107,8 @@ generated_file_labels = subprocess.run(
         (
             'filter(".*\\.(h|cpp|cc|c|cxx|def|inc)$",'
             'kind("generated file", deps(//...)))'
+            " union "
+            'kind("cc_proto_library", deps(//...))'
         ),
     ],
     check=True,
@@ -132,6 +135,7 @@ subprocess.run(
         "@llvm-project//llvm:LICENSE.TXT",
         "@com_google_absl//:LICENSE",
         "@com_google_googletest//:LICENSE",
+        "@com_googlesource_code_re2//:LICENSE",
         "@com_github_google_benchmark//:benchmark",
     ]
 )

+ 42 - 0
scripts/run_clang_tidy.py

@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+
+"""Runs clang-tidy over all Carbon files.
+"""
+
+__copyright__ = """
+Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+Exceptions. See /LICENSE for license information.
+SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+"""
+
+import os
+import subprocess
+import sys
+
+from pathlib import Path
+
+
+def main() -> None:
+    # Set the repo root as the working directory.
+    os.chdir(Path(__file__).parent.parent)
+    # Ensure create_compdb has been run.
+    subprocess.check_call(["./scripts/create_compdb.py"])
+
+    args = sys.argv[1:]
+    if not args or args[0] == "--fix":
+        args.append("^(?!.*/(bazel-|third_party)).*$")
+
+    # Run clang-tidy from clang-tools-extra.
+    exit(
+        subprocess.call(
+            [
+                "./bazel-execroot/external/llvm-project/clang-tools-extra/"
+                "clang-tidy/tool/run-clang-tidy.py",
+            ]
+            + args
+        )
+    )
+
+
+if __name__ == "__main__":
+    main()