Acquire compile_commands.json for the build targets

Hi, I’m working on running static analysis tools on MongoDB, but the tools I want to use, clang-tidy & Clang Static Analyzer, accepts compile_commands.json. I’m struggling to get such a json due to the scons build system this project uses.

Do you have any recommendations on how to create the compile_commands.json using scons?

I’ve found the pinetr2e/scons-compiledb: SCons support for compile_commands.json generation (github.com) tool, but I could not get it working.
I also tried the CodeChecker’s build logger functionality to LD_PRELOAD some hooks for the exec-like function catching any compiler invocation that the scons build system triggers - without success.

Hi -

You can build a compile_commands.json for MongoDB on all branches back to and including v3.2 by running scons compiledb or scons compile_commands.json, the former being an Alias for the latter.

The implementation you linked to is actually derived from our original implementation: GitHub - pinetr2e/scons-compiledb: SCons support for compile_commands.json genearation

Our implementation is built in to the MongoDB sources, and lives in mongo/compilation_db.py at master · mongodb/mongo · GitHub, and a more or less identical version wih some improvements has been merged into SCons itself as of SCons 4.0: scons/compilation_db.py at master · SCons/scons · GitHub

I’d be interested to know more about what you are planning to do with clang-tidy and the MongoDB sources. We started running clang-tidy as part of MongoDB v4.4 development, but with a rather small set of checks. We have been gradually expanding the set of those checks as we identify specific checks that we find useful. On the master branch right now, the list of enabled checks is:

  • bugprone-unused-raii
  • bugprone-use-after-move
  • readability-const-return-type
  • readability-avoid-const-params-in-decls

Thanks,
Andrew

1 Like

Awesome! I’m gonna test it as soon as I have time.

I’m working on developing static analysis checks and MongoDB seemed to be large and mature enough to have a look at the reports of my experimental check. I’m just diffing the reports to see what changes.

You might be interested in our open-source tool enabling us to do so. Have a look at CodeChecker! Let us know if you find it useful.

1 Like