This is an archive of the discontinued LLVM Phabricator instance.

Allow clang to write compilation database records
ClosedPublic

Authored by joerg on Nov 25 2016, 2:29 PM.

Details

Summary

When integrating compilation database output into existing build systems, two approaches dominate so far. Ad-hoc implementation of the JSON output rules or using compiler wrappers. This patch adds a new option "-MJ foo.json" which gives a slightly cleaned up compilation record. The output is a fragment, i.e. you still need to add the array markers, but it allows multiple files to be easy merged.

This way the only change in a build system is adding the option with potentially a per-target output file and merging the files with something like (echo '['; cat *.o.json; echo ']' > compilation_database.json or filtering out the trailing comma for strict JSON compliance.

Diff Detail

Repository
rL LLVM

Event Timeline

joerg updated this revision to Diff 79323.Nov 25 2016, 2:29 PM
joerg retitled this revision from to Allow clang to write compilation database records.
joerg updated this object.
joerg added reviewers: klimek, rsmith.
joerg set the repository for this revision to rL LLVM.
joerg added a subscriber: cfe-commits.
joerg updated this revision to Diff 79423.Nov 28 2016, 10:33 AM
joerg removed rL LLVM as the repository for this revision.

Use llvm::yaml::escape.

joerg updated this revision to Diff 79482.Nov 28 2016, 4:55 PM

Move implementation into the Clang class, keep track of the raw_fd_stream. This avoids reopening it on multiple inputs and removes the need for append mode. Short circuit the function when -### is present. Add proper diagnostics on open failure.

Still not completely happy with the place and the associated need for the mutable member.

Adding some folks. One question is whether we can use the additional output stuff doug added at some point for this.

joerg updated this revision to Diff 79997.Dec 1 2016, 4:32 PM
joerg updated this object.
joerg edited edge metadata.
joerg set the repository for this revision to rL LLVM.

Add test case.

It would also be good to append --sysroot=DEFAULT_SYSROOT if DEFAULT_SYSROOT is not empty and there is no explicit --sysroot flag. That way the compilation database can also be consumed by a libclang based too that does not have the same DEFAULT_SYSROOT set.

klimek accepted this revision.Dec 6 2016, 2:09 AM
klimek edited edge metadata.

LG. We can always add more intricate ways later on.

This revision is now accepted and ready to land.Dec 6 2016, 2:09 AM
This revision was automatically updated to reflect the committed changes.