1

I am having trouble getting clang-tidy to read my compilation-database. If I try:

clang-tidy --config-file ./.clang-tidy -checks=* -p ./target

or

clang-tidy --config-file ./.clang-tidy -checks=* -p ./target/compile-commands.json

I get

Error: no input files specified.
USAGE: clang-tidy [options] <source0> [... <sourceN>]
...

But according to the --help -p is the way to specify the path to it. It only seems to work if I specify individual files as in:

clang-tidy --config-file ./.clang-tidy -checks=* path/to/file.cpp
Bruce Adams
  • 4,953
  • 4
  • 48
  • 111

2 Answers2

2

When you say, "according to the --help -p is the way to specify the path to it", I think you're referring to this passage from the Clang-Tidy page:

-p <build-path> is used to read a compile command database.

        For example, it can be a CMake build directory in which a file named
        compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
        CMake option to get this output). When no build path is specified,
        a search for compile_commands.json will be attempted through all
        parent paths of the first input file . See:
        https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
        example of setting up Clang Tooling on a source tree.

As it says, -p helps clang-tidy find the compilation database, which tells clang-tidy how to compile the listed source files, but it does not actually specify what files to analyze. (In general, the database can say how to compile many things, but you might only want to analyze a subset.)

To specify what to analyze, you have to list all of the file names on the command line after the options. There is, perhaps unfortunately, no way to ask clang-tidy to analyze everything in the compilation database.

Scott McPeak
  • 8,803
  • 2
  • 40
  • 79
  • 1
    "There is, perhaps unfortunately, no way to ask clang-tidy to analyze everything in the compilation database." was the information I was looking for. – Bruce Adams Feb 04 '23 at 14:07
  • 1
    I basically ended up with: SOURCE=$(find src -name \*.cpp) clang-tidy -p ./target/compile-commands.json ${SOURCE} – Bruce Adams Feb 04 '23 at 14:08
0
USAGE: clang-tidy [options] <source0> [... <sourceN>]

You specified the options, you did not give <source0>.

What is the advantage of using --config-file ./.clang-tidy -checks=* -p? You set checks in .clang-tidy and immediately reset them with -checks=* -p.

.clang-tidy is a deafault config file, --config-file ./.clang-tidy can be omitted.

clang-tidy  -checks=* -p ./target  path/to/file.cpp
            ^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^
                   options              source0
273K
  • 29,503
  • 10
  • 41
  • 64