Skip to content

Conversation

@HARSHIL2836R
Copy link
Contributor

@HARSHIL2836R HARSHIL2836R commented Aug 12, 2025

Resolves #90772

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Harshil Solanki (HARSHIL2836R)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/153166.diff

1 Files Affected:

  • (modified) clang-tools-extra/docs/clang-tidy/index.rst (+32)
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst
index b7a366e874130..77f876f2b718d 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -41,6 +41,38 @@ parameters file:
 
   $ clang-tidy @parameters_file
 
+Running Clang-Tidy on Multiple Files
+=====================================
+
+For projects with multiple source files, you can use the :program:`run-clang-tidy.py`
+script to run :program:`clang-tidy` over all files in a compilation database in
+parallel. This script is included with clang-tidy and provides a convenient way
+to analyze entire projects efficiently.
+
+The script requires a compilation database (``compile_commands.json``) which can
+be generated by build systems like CMake (using ``-DCMAKE_EXPORT_COMPILE_COMMANDS=ON``)
+or by tools like Bear.
+
+Example invocations:
+
+.. code-block:: console
+
+  # Run clang-tidy on all files in the compilation database
+  $ run-clang-tidy.py
+
+  # Run with specific checks and apply fixes
+  $ run-clang-tidy.py -fix -checks=-*,readability-*
+
+  # Run on specific files/directories with header filtering
+  $ run-clang-tidy.py src/ -header-filter=src/
+
+  # Run with parallel execution (uses all CPU cores by default)
+  $ run-clang-tidy.py -j 4
+
+The script supports most of the same options as :program:`clang-tidy` itself,
+including ``-checks=``, ``-fix``, ``-header-filter=``, and configuration options.
+Run ``run-clang-tidy.py --help`` for a complete list of available options.
+
 :program:`clang-tidy` has its own checks and can also run Clang Static Analyzer
 checks. Each check has a name and the checks to run can be chosen using the
 ``-checks=`` option, which specifies a comma-separated list of positive and

@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2025

@llvm/pr-subscribers-clang-tidy

Author: Harshil Solanki (HARSHIL2836R)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/153166.diff

1 Files Affected:

  • (modified) clang-tools-extra/docs/clang-tidy/index.rst (+32)
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst
index b7a366e874130..77f876f2b718d 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -41,6 +41,38 @@ parameters file:
 
   $ clang-tidy @parameters_file
 
+Running Clang-Tidy on Multiple Files
+=====================================
+
+For projects with multiple source files, you can use the :program:`run-clang-tidy.py`
+script to run :program:`clang-tidy` over all files in a compilation database in
+parallel. This script is included with clang-tidy and provides a convenient way
+to analyze entire projects efficiently.
+
+The script requires a compilation database (``compile_commands.json``) which can
+be generated by build systems like CMake (using ``-DCMAKE_EXPORT_COMPILE_COMMANDS=ON``)
+or by tools like Bear.
+
+Example invocations:
+
+.. code-block:: console
+
+  # Run clang-tidy on all files in the compilation database
+  $ run-clang-tidy.py
+
+  # Run with specific checks and apply fixes
+  $ run-clang-tidy.py -fix -checks=-*,readability-*
+
+  # Run on specific files/directories with header filtering
+  $ run-clang-tidy.py src/ -header-filter=src/
+
+  # Run with parallel execution (uses all CPU cores by default)
+  $ run-clang-tidy.py -j 4
+
+The script supports most of the same options as :program:`clang-tidy` itself,
+including ``-checks=``, ``-fix``, ``-header-filter=``, and configuration options.
+Run ``run-clang-tidy.py --help`` for a complete list of available options.
+
 :program:`clang-tidy` has its own checks and can also run Clang Static Analyzer
 checks. Each check has a name and the checks to run can be chosen using the
 ``-checks=`` option, which specifies a comma-separated list of positive and

@HARSHIL2836R HARSHIL2836R changed the title Merge branch 'main' of https://github.com/llvm/llvm-project [clang-tidy] Add documentation for running Clang-Tidy on multiple files Aug 12, 2025
@HARSHIL2836R HARSHIL2836R changed the title [clang-tidy] Add documentation for running Clang-Tidy on multiple files [clang-tidy] Add documentation for Clang-Tidy Automation Aug 12, 2025
… its limitations and encouraging comprehensive analysis
Copy link
Contributor

@carlosgalvezp carlosgalvezp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a minor last comment! Thanks for improving the docs :)

@vbvictor vbvictor changed the title [clang-tidy] Add documentation for Clang-Tidy Automation [clang-tidy][docs] Add documentation for Clang-Tidy Automation Aug 13, 2025
@HARSHIL2836R
Copy link
Contributor Author

How can I build the file and check if it's correct? I used docutils to convert rst to html but there were some errors

@vbvictor
Copy link
Contributor

How can I build the file and check if it's correct? I used docutils to convert rst to html but there were some errors

You need to have Sphinx and build docs-clang-tools-html target in CMake (possibly using ninja docs-clang-tools-html).
https://clang.llvm.org/extra/clang-tidy/Contributing.html#documenting-your-check

@vbvictor
Copy link
Contributor

You can also look at CI job Test documentation build / Test documentation build (pull_request) that is build for current PR.

@carlosgalvezp
Copy link
Contributor

You need to have Sphinx and build docs-clang-tools-html target in CMake (possibly using ninja docs-clang-tools-html). https://clang.llvm.org/extra/clang-tidy/Contributing.html#documenting-your-check

I believe you also need to enable these CMake flags:

-DLLVM_BUILD_DOCS=ON \
-DLLVM_ENABLE_SPHINX=ON \

Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vbvictor vbvictor merged commit 6127e46 into llvm:main Aug 19, 2025
10 checks passed
@github-actions
Copy link

@HARSHIL2836R Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 19, 2025

LLVM Buildbot has detected a new failure on builder clang-armv8-quick running on linaro-clang-armv8-quick while building clang-tools-extra at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/20436

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clangd Unit Tests :: ./ClangdTests/242/332' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests-Clangd Unit Tests-2597534-242-332.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=332 GTEST_SHARD_INDEX=242 /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests
--

Note: This is test shard 243 of 332.
[==========] Running 4 tests from 4 test suites.
[----------] Global test environment set-up.
[----------] 1 test from CompletionStringTest
[ RUN      ] CompletionStringTest.DocumentationWithAnnotation
[       OK ] CompletionStringTest.DocumentationWithAnnotation (32 ms)
[----------] 1 test from CompletionStringTest (32 ms total)

[----------] 1 test from FuzzyMatch
[ RUN      ] FuzzyMatch.Ranking
[       OK ] FuzzyMatch.Ranking (22 ms)
[----------] 1 test from FuzzyMatch (22 ms total)

[----------] 1 test from CrossFileRenameTests
[ RUN      ] CrossFileRenameTests.WithUpToDateIndex
ASTWorker building file /clangd-test/foo.h version null with command 
[/clangd-test]
clang -xobjective-c++ /clangd-test/foo.h
Driver produced command: cc1 -cc1 -triple armv8a-unknown-linux-gnueabihf -fsyntax-only -disable-free -clear-ast-before-backend -main-file-name foo.h -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature +read-tp-tpidruro -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature +fp16 -target-feature +vfp4 -target-feature +vfp4d16 -target-feature +vfp4d16sp -target-feature +vfp4sp -target-feature +fp-armv8 -target-feature +fp-armv8d16 -target-feature +fp-armv8d16sp -target-feature +fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +sha2 -target-feature +aes -target-feature -fp16fml -target-feature +neon -target-abi aapcs-linux -mfloat-abi hard -debugger-tuning=gdb -fdebug-compilation-dir=/clangd-test -fcoverage-compilation-dir=/clangd-test -resource-dir lib/clang/22 -internal-isystem lib/clang/22/include -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fobjc-runtime=gcc -fobjc-encode-cxx-class-template-spec -fobjc-exceptions -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x objective-c++ /clangd-test/foo.h
Building first preamble for /clangd-test/foo.h version null
not idle after addDocument
UNREACHABLE executed at ../llvm/clang-tools-extra/clangd/unittests/SyncAPI.cpp:22!
#0 0x05165450 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xab5450)
#1 0x05162900 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xab2900)
#2 0x05166420 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0xf0e5d6f0 __default_rt_sa_restorer ./signal/../sysdeps/unix/sysv/linux/arm/sigrestorer.S:80:0
#4 0xf0e4db06 ./csu/../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S:47:0
#5 0xf0e8d292 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0xf0e5c840 gsignal ./signal/../sysdeps/posix/raise.c:27:6

--
exit: -6
--
shard JSON output does not exist: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests-Clangd Unit Tests-2597534-242-332.json
********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang-tidy][docs] run-clang-tidy.py is undocumented in Using clang-tidy

6 participants