Skip to content

Commit 46e1d3d

Browse files
authored
[clang-tidy] Add parallel execution by default in 'run-clang-tidy' and 'clang-tidy-diff' (#149739)
Change the default value of `-j` from `1` to `0` in `clang-tidy-diff.py` script to autodetect number of CPU cores to run on. Script `run-clang-tidy.py` already had this behavior by default. Both scripts now also print the number of threads being used to provide better visibility into their execution behavior. Fixes #148624.
1 parent 0a17483 commit 46e1d3d

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def main():
177177
parser.add_argument(
178178
"-j",
179179
type=int,
180-
default=1,
180+
default=0,
181181
help="number of tidy instances to be run in parallel.",
182182
)
183183
parser.add_argument(
@@ -318,6 +318,7 @@ def main():
318318
if max_task_count == 0:
319319
max_task_count = multiprocessing.cpu_count()
320320
max_task_count = min(len(lines_by_file), max_task_count)
321+
print(f"Running clang-tidy in {max_task_count} threads...")
321322

322323
combine_fixes = False
323324
export_fixes_dir = None

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ async def main() -> None:
548548
files = {f for f in files if file_name_re.search(f)}
549549

550550
print(
551-
"Running clang-tidy for",
551+
f"Running clang-tidy in {max_task} threads for",
552552
len(files),
553553
"files out of",
554554
number_files_in_database,

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Improvements to clang-query
9393
Improvements to clang-tidy
9494
--------------------------
9595

96+
- The :program:`run-clang-tidy.py` and :program:`clang-tidy-diff.py` scripts
97+
now run checks in parallel by default using all available hardware threads.
98+
Both scripts display the number of threads being used in their output.
99+
96100
New checks
97101
^^^^^^^^^^
98102

clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// REQUIRES: shell
22
// RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
33
// RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
4-
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
4+
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-JMAX
55
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
66
// RUN: mkdir -p %T/compilation-database-test/
77
// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
88
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
9+
10+
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -j 1 -- -std=c++11 2>&1 | FileCheck %s --check-prefix=CHECK-J1
11+
// CHECK-J1: Running clang-tidy in 1 threads...
912
struct A {
1013
virtual void f() {}
1114
virtual void g() {}
1215
};
16+
// CHECK-JMAX: Running clang-tidy in {{[1-9][0-9]*}} threads...
1317
// CHECK-NOT: warning:
1418
// CHECK-QUIET-NOT: warning:
1519
struct B : public A {

clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
// RUN: echo " modernize-use-auto.MinTypeNameLength: '0'" >> %t/.clang-tidy
99
// RUN: cp "%s" "%t/test.cpp"
1010
// RUN: cd "%t"
11-
// RUN: not %run_clang_tidy "test.cpp"
11+
// RUN: not %run_clang_tidy "test.cpp" 2>&1 | FileCheck %s --check-prefix=CHECK-JMAX
12+
// CHECK-JMAX: Running clang-tidy in {{[1-9][0-9]*}} threads for
13+
14+
// RUN: not %run_clang_tidy -j 1 "test.cpp" 2>&1 | FileCheck %s --check-prefix=CHECK-J1
15+
// CHECK-J1: Running clang-tidy in 1 threads for
1216

1317
int main()
1418
{

0 commit comments

Comments
 (0)