7
7
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
8
#
9
9
# ==-------------------------------------------------------------------------==#
10
+ """A helper script to run clang-tidy linter in GitHub actions
10
11
11
- import argparse
12
- import os
13
- import subprocess
14
- import sys
15
- from typing import List , Optional
16
-
17
- """
18
12
This script is run by GitHub actions to ensure that the code in PR's conform to
19
13
the coding style of LLVM. The canonical source of this script is in the LLVM
20
14
source tree under llvm/utils/git.
23
17
https://llvm.org/docs/CodingStandards.html
24
18
"""
25
19
20
+ import argparse
21
+ import os
22
+ import subprocess
23
+ from typing import List , Optional
24
+
26
25
27
26
class LintArgs :
28
27
start_rev : str = None
@@ -54,7 +53,7 @@ def __init__(self, args: argparse.Namespace = None) -> None:
54
53
def get_instructions (cpp_files : List [str ]) -> str :
55
54
files_str = " " .join (cpp_files )
56
55
return f"""
57
- git diff -U0 origin/main..HEAD -- { files_str } |
56
+ git diff -U0 origin/main... HEAD -- { files_str } |
58
57
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \\
59
58
-path build -p1 -quiet"""
60
59
@@ -87,8 +86,8 @@ def clean_clang_tidy_output(output: str) -> Optional[str]:
87
86
return None
88
87
89
88
89
+ # TODO: Add more rules when enabling other projects to use clang-tidy in CI.
90
90
def should_lint_file (filepath : str ) -> bool :
91
- # For add other paths/files to this function
92
91
return filepath .startswith ("clang-tools-extra/clang-tidy/" )
93
92
94
93
@@ -106,16 +105,6 @@ def filter_changed_files(changed_files: List[str]) -> List[str]:
106
105
return filtered_files
107
106
108
107
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
-
119
108
def create_comment_text (warning : str , cpp_files : List [str ]) -> str :
120
109
instructions = get_instructions (cpp_files )
121
110
return f"""
@@ -181,7 +170,7 @@ def run_clang_tidy(changed_files: List[str], args: LintArgs) -> Optional[str]:
181
170
"git" ,
182
171
"diff" ,
183
172
"-U0" ,
184
- f"{ args .start_rev } ..{ args .end_rev } " ,
173
+ f"{ args .start_rev } ... { args .end_rev } " ,
185
174
"--" ,
186
175
] + changed_files
187
176
@@ -315,11 +304,6 @@ def run_linter(changed_files: List[str], args: LintArgs) -> tuple[bool, Optional
315
304
if args .verbose :
316
305
print (f"got changed files: { changed_files } " )
317
306
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
-
323
307
if args .verbose :
324
308
print ("running linter clang-tidy" )
325
309
0 commit comments