An open API service indexing awesome lists of open source software.

https://github.com/mlabbe/cleanup-compdb

Postprocess and clean up compile_commands.json
https://github.com/mlabbe/cleanup-compdb

Last synced: 4 months ago
JSON representation

Postprocess and clean up compile_commands.json

Awesome Lists containing this project

README

          

# Compilation Database Cleanup #

Postprocess and clean up your `compilation_commands.json`, as generated from your build tool. Does the following:

- Append to the compile arguments, useful for suppressing additional warnings
- Converts relative paths into absolute paths for increased readability
- Removes problematic `cmd /C` prefix in commands on Windows, which confuses clangd
- Strip linker commands and phony targets which are not real compilation commands
- Increases readability with unix-style slashes on all platforms (clangd on Windows accepts this)

## Rationale ##

Compilation databases are useful for getting an editor to preview compile errors or provide semantic context while adhering to a specific mode of compilation. Intutitively, the best way to generate them is to have your existing build tooling generate them so the compile commands match how the project is actually being built.

However, in practice, the set of arguments that produces the most timely error messages can vary from the final compilation settings. For instance, it can be annoying that an unused function is generating a warning in the editor. However, it is useful during compilation time, so adding `-Wno-unused-function` to the compilation database configures an editor to prevent this warning, while continuing to generate it at compile time.

Further afield, cleanup-compdb can be used to provide compatibility to clangd for [unity builds](https://en.wikipedia.org/wiki/Unity_build). This [blog post](https://www.frogtoss.com/labs/clangd-with-unity-builds.html) proposes a solution to this problem.

## Changelog ##

release | what's new | date
--------|-----------------------------|---------
0.0.1 | initial | jan 2023
0.2.1 | better error handling | apr 2025

## Usage ##

`cd` to your project root, and:

`ninja -t compdb | cleanup-compdb > compile_commands.json`

## Project Status ##

Tested and working with Ninja 1.10 through 1.12 over three years on Linux, Windows and MacOS. In continued use by the author.

Recommended for public use.

# Copyright and Credit #

Copyright © 2022-2025 [Frogtoss Games](http://www.frogtoss.com), Inc.
File [LICENSE](LICENSE) covers all files in this repo.

Compilation Database Cleanup by Michael Labbe

[json_compilation_db crate](https://github.com/rizsotto/json_compilation_db) by László Nagy