This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Attempt to merge runtimes and projects compilation databases
Needs ReviewPublic

Authored by jhuber6 on Apr 3 2023, 6:33 AM.

Details

Summary

When building a project in a runtime mode, the compilation database is a
separate CMake invocation. So its compile_commands.json file will be
placed elsewhere in the runtimes/runtime-bins directory. This is
somewhat annoying for ongoing development when a runtimes build is
necessary. This patch adds some CMake magic to merge the two files.

Diff Detail

Event Timeline

jhuber6 created this revision.Apr 3 2023, 6:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 6:33 AM
jhuber6 requested review of this revision.Apr 3 2023, 6:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 6:33 AM

Unfortunately this does not work in every case I'd like. When the main CMake gets updated it will overwrite the compile_commands.json without touching the one in runtimes/. I can't make the command depend on the main compile_commands.json because it would create a circular dependency as it is the file we are writing to. Let me know if there's a hook I can use to get past that.

jdoerfert added inline comments.Apr 3 2023, 11:00 AM
llvm/utils/concat-compile-commands.py
19

JSON

21

Is it really created below?

jhuber6 updated this revision to Diff 510561.Apr 3 2023, 11:02 AM

Fix help message that wasn't updated correctly.

Thanks for the patch. This is very useful! Though I am not good at CMake to review this...

jhuber6 updated this revision to Diff 510672.Apr 3 2023, 7:55 PM

Fix leftover print. I'm still wondering if there's a good way to get the CMake to properly keep this updated. Basically, some way to make the dependency of the command depend on compile_commnads.json but not when we write it. Maybe a really hacky way to do it would be to cancel the command if the input is too new.

I wonder if clang is not built yet, what will be used (as for compiler) in the runtimes compilation database?

I wonder if clang is not built yet, what will be used (as for compiler) in the runtimes compilation database?

I thought the whole point of the runtimes build was to manually set the compiler to the newly built clang and re-run CMake in a separate directory. The main problem I had with this patch was the I can't detect changes to the base compile_commnads because we write to it when we update it. I'm not sure if there's a good way to tell CMake "This should be updated if anyone but this function changes the file".

This works now? What are the leftover problems?

This works now? What are the leftover problems?

As I mentioned above. If someone changes something in CMake it will regenerate the compile_commands.json list. So ideally we'd put a dependency on that file for this action so we auto-merge them. The problem is that this dependency will then fire on the merging itself because we modify the file. So, in its current state this patch will merge the files automatically once at build time, but then won't do it with successive builds.