77# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88#
99# ==-------------------------------------------------------------------------==#
10+ """A helper script to run clang-tidy linter in GitHub actions
1011
11- import argparse
12- import os
13- import subprocess
14- import sys
15- from typing import List , Optional
16-
17- """
1812This script is run by GitHub actions to ensure that the code in PR's conform to
1913the coding style of LLVM. The canonical source of this script is in the LLVM
2014source tree under llvm/utils/git.
2317https://llvm.org/docs/CodingStandards.html
2418"""
2519
20+ import argparse
21+ import os
22+ import subprocess
23+ from typing import List , Optional
24+
2625
2726class LintArgs :
2827 start_rev : str = None
@@ -54,7 +53,7 @@ def __init__(self, args: argparse.Namespace = None) -> None:
5453def get_instructions (cpp_files : List [str ]) -> str :
5554 files_str = " " .join (cpp_files )
5655 return f"""
57- git diff -U0 origin/main..HEAD -- { files_str } |
56+ git diff -U0 origin/main... HEAD -- { files_str } |
5857python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \\
5958 -path build -p1 -quiet"""
6059
@@ -87,8 +86,8 @@ def clean_clang_tidy_output(output: str) -> Optional[str]:
8786 return None
8887
8988
89+ # TODO: Add more rules when enabling other projects to use clang-tidy in CI.
9090def should_lint_file (filepath : str ) -> bool :
91- # For add other paths/files to this function
9291 return filepath .startswith ("clang-tools-extra/clang-tidy/" )
9392
9493
@@ -106,16 +105,6 @@ def filter_changed_files(changed_files: List[str]) -> List[str]:
106105 return filtered_files
107106
108107
109- def has_clang_tidy (clang_tidy_binary : str ) -> bool :
110- cmd = [clang_tidy_binary , "--version" ]
111- proc = None
112- try :
113- proc = subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
114- except :
115- return False
116- return proc .returncode == 0
117-
118-
119108def create_comment_text (warning : str , cpp_files : List [str ]) -> str :
120109 instructions = get_instructions (cpp_files )
121110 return f"""
@@ -181,7 +170,7 @@ def run_clang_tidy(changed_files: List[str], args: LintArgs) -> Optional[str]:
181170 "git" ,
182171 "diff" ,
183172 "-U0" ,
184- f"{ args .start_rev } ..{ args .end_rev } " ,
173+ f"{ args .start_rev } ... { args .end_rev } " ,
185174 "--" ,
186175 ] + changed_files
187176
@@ -315,11 +304,6 @@ def run_linter(changed_files: List[str], args: LintArgs) -> tuple[bool, Optional
315304 if args .verbose :
316305 print (f"got changed files: { changed_files } " )
317306
318- # Check for clang-tidy tool
319- if not has_clang_tidy (args .clang_tidy_binary ):
320- print ("Couldn't find C/C++ code linter: clang-tidy" )
321- sys .exit (1 )
322-
323307 if args .verbose :
324308 print ("running linter clang-tidy" )
325309
0 commit comments