Menu

Use compilation database for manually specified files

2021-10-03
2021-10-04
  • Leon De Andrade

    Leon De Andrade - 2021-10-03

    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 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?

    Thanks

    Leon

     
  • Daniel Marjamäki

    I think your suggestion to use --file-filter multiple times is acceptable.

     
  • Leon De Andrade

    Leon De Andrade - 2021-10-04

    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)

     
    • Daniel Marjamäki

      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

       
  • Leon De Andrade

    Leon De Andrade - 2021-10-04

    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

     
  • Leon De Andrade

    Leon De Andrade - 2021-10-04

    Implemented the discussed approach. After some thinking I like passing multiple --file-fillters as well:
    https://github.com/danmar/cppcheck/pull/3479

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.