compiledb
compiledb is a Python tool designed for generating Clang's JSON Compilation Database files, primarily for GNU make-based build systems. It targets large codebases that do not use CMake, which typically generates its own compilation database. The library is currently at version 0.10.7 and is actively maintained, with releases occurring as needed rather than on a strict schedule.
Common errors
-
FileNotFoundError
cause `compiledb` cannot locate source files or other build artifacts referenced in the `make` output, often due to an incorrect working directory or issues during path resolution.fixEnsure that `compiledb` is run from the correct build directory. If `make` commands change directories, consider using `compiledb --build-dir <path>` or `compiledb --parse` with a log that has absolute paths. -
Failed to parse build command [Details: (<class 'bashlex.errors.ParsingError'>) unexpected token ...]
cause `compiledb` uses the `bashlex` library to parse shell commands from `make` output. This error indicates that `bashlex` encountered unexpected syntax, often from highly complex, non-standard, or malformed shell commands within your `Makefile`.fixExamine the `make` output around the indicated line number for unusual shell constructs. Try to simplify the `Makefile` command that causes the error or, if possible, use `make -Bnwk` to generate a log and manually clean up problematic lines before using `compiledb --parse`. -
Different results betweent "compiledb make" and "make | compiledb"
cause The behavior of piping `make` output to `compiledb` might differ from `compiledb` directly wrapping `make`. This is often due to differences in how shell redirects and environment variables are handled, or `make` changing its behavior when its output is not a TTY.fixPrefer using `compiledb make` as it's the intended wrapper behavior. If direct parsing is necessary, ensure `make -Bnwk` is used to produce a verbose, non-building log, and be aware that some build systems might behave differently when their output is redirected.
Warnings
- gotcha When dealing with recursive `make` patterns or complex AOSP verbose logs, `compile_commands.json` can sometimes be empty even after a successful build process.
- gotcha Parsing errors can occur with complex `make` output, especially when commands involve quoted macros, non-standard directory changes within `make`, or unconventional shell syntax.
- gotcha On Windows, backslashes in include paths within the `make` output may not be processed correctly by `compiledb`, leading to invalid paths in `compile_commands.json`.
- gotcha For VS Code users, `compiledb` might not group `-D` (defines) and `-I` (include paths) options consistently. VS Code's C/C++ extension prefers these options to be grouped, which can affect IntelliSense accuracy.
Install
-
pip install compiledb
Quickstart
# Assuming you have a Makefile in the current directory # This command will execute 'make' and generate 'compile_commands.json' compiledb make # To skip the actual build and only generate the database from make's dry run: # compiledb -n make # To parse an existing build log file: # make -Bnwk > build.log # compiledb --parse build.log