Trick-17 / clang-build

Clang-based cross platform build system written in Python
https://clang-build.readthedocs.io
MIT License
8 stars 3 forks source link

Output compilation database (compile_commands.json) #109

Closed GPMueller closed 3 years ago

GPMueller commented 4 years ago

Since we generate the compile commands, we can easily write them into a compilation database.

From the clang documentation:

[
  { "directory": "/home/user/llvm/build",
    "command": "/usr/bin/clang++ -Irelative -DSOMEDEF=\"With spaces, quotes and \\-es.\" -c -o file.o file.cc",
    "file": "file.cc" },
  ...
]

where

This should improve the IDE experience, I believe it will for example help VS Code find includes and definitions, etc.

GPMueller commented 4 years ago

An issue implementing this in clang-build is the fact that we try to only generate as little info as actually needed. When a target is built the compile commands could be saved, but in a second build the target would not be in the build list and the compile commands would no longer be in the file.

It seems we would have to implement a more database-like behaviour, for example by reading in the file, updating the resulting dict and then saving again (instead of just overwriting every time). The question is: when should any entry from the database be removed and/or when should it be cleared entirely?