I'm trying to run cppcheck on a list of files and I have a compilation
database, which I want to use, so cppcheck picks up compiler flags.
I know about the --project option. The problem here is that when used
it will check all files from the database instead of just the files I
specified. There is --file-filter to filter the files from the
database, but it accepts only one string.
So cppcheck --project=compilation_database.json
--filter-filter=my/file.cpp works. But something like cppcheck
--project=compilation_database.json --filter-filter=my/first/file.cpp,
my/second/file.cpp or cppcheck --project=compilation_database.json
--filter-filter=my/first/file.cpp --filter-filter=my/second/file.cpp
does not.
What can I do to use the compilation database, but analyze a bunch of
specified files?
I think it's fine too, but it doesn't work. As I wrote, I tested the different variants and all oft them don't work.
Can you add support for it? (I would still prefer a mode though, were I just use cppcheck "normally", but it looks up the files in the compilation database. That's what clang-tidy is doing afaik)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes. it is not implemented now. but if somebody implements it and sends a pull request I will accept the idea.
if you need to filter files today and can't wait for the implementation.. I don't know what you can do.. filter the compile database maybe. or execute cppcheck multiple times..
Would you also be up to other solutions:
- Using compilation base just for loopup (-> So add another flag, where one can add a compilation databse just for loopup)
- Use other proposed syntax above
- Modify one of the other options or add a new one to give a list of filenames (rather than a list of filter expressions) -> Maybe --file-list? I'm not sure if I understand the documentation right, but you can specify a file with a list of filenames or directly specify the filesnames in the command, right? This sounds almost like the needed functionality, just that it is ignored for compilation database currently I believe
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm trying to run cppcheck on a list of files and I have a compilation
database, which I want to use, so cppcheck picks up compiler flags.
I know about the
--project
option. The problem here is that when usedit will check all files from the database instead of just the files I
specified. There is
--file-filter
to filter the files from thedatabase, but it accepts only one string.
So
cppcheck --project=compilation_database.json --filter-filter=my/file.cpp
works. But something likecppcheck --project=compilation_database.json --filter-filter=my/first/file.cpp, my/second/file.cpp
orcppcheck --project=compilation_database.json --filter-filter=my/first/file.cpp --filter-filter=my/second/file.cpp
does not.
What can I do to use the compilation database, but analyze a bunch of
specified files?
Thanks
Leon
I think your suggestion to use
--file-filter
multiple times is acceptable.I think it's fine too, but it doesn't work. As I wrote, I tested the different variants and all oft them don't work.
Can you add support for it? (I would still prefer a mode though, were I just use cppcheck "normally", but it looks up the files in the compilation database. That's what clang-tidy is doing afaik)
yes. it is not implemented now. but if somebody implements it and sends a pull request I will accept the idea.
if you need to filter files today and can't wait for the implementation.. I don't know what you can do.. filter the compile database maybe. or execute cppcheck multiple times..
cppcheck --project=compilation_database.json --filter-filter=my/first/file.cpp
cppcheck --project=compilation_database.json --filter-filter=my/second/file.cpp
Would you also be up to other solutions:
- Using compilation base just for loopup (-> So add another flag, where one can add a compilation databse just for loopup)
- Use other proposed syntax above
- Modify one of the other options or add a new one to give a list of filenames (rather than a list of filter expressions) -> Maybe --file-list? I'm not sure if I understand the documentation right, but you can specify a file with a list of filenames or directly specify the filesnames in the command, right? This sounds almost like the needed functionality, just that it is ignored for compilation database currently I believe
Implemented the discussed approach. After some thinking I like passing multiple --file-fillters as well:
https://github.com/danmar/cppcheck/pull/3479