{"thread":{"id":"60437","subject":"Constant recompilation when GENERATE_COMPILATION_DATABASE is set","startedAt":"2023-10-27T11:45:31Z","lastAt":"2023-10-27T19:36:40Z","messageCount":3,"participants":["brian m. carlson","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"483974","messageId":"ZTui2NcJ3Ax_PIGO@tapette.crustytoothpaste.net","threadId":"60437","inReplyTo":null,"subject":"Constant recompilation when GENERATE_COMPILATION_DATABASE is set","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2023-10-27T11:45:28Z","receivedAt":"2023-10-27T11:45:31Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"I typically use clangd with Git for the nice language server protocol\n(LSP) support.  I noticed that when GENERATE_COMPILATION_DATABASE is set\n(which is used so clangd can find the proper flags), `make` rebuilds all\nof the files every time, even if I do it back to back.  This persists\neven after a `git clean -dxf`.\n\nObviously, this is not great, since it means the turnaround time to\ncompile changes is slower.  Unfortunately, I'm not a huge expert in make\nand I'm unsure what the right solution is here.  I'd appreciate anyone's\nthoughts on how to improve this.\n\nThis is on a Debian sid (unstable) amd64 system with the following\nconfiguration.  The version of clang in use is Debian's 16.0.6.\n\n----\nNO_OPENSSL=1\nDC_SHA1=1\nNETTLE_SHA256=1\nDEVELOPER=1\nNO_SVN_TESTS=1\nNO_PYTHON=1\nUSE_ASCIIDOCTOR=1\nUSE_ASCIIDOCTOR_MANPAGE=1\nCC=clang\nGENERATE_COMPILATION_DATABASE=yes\nCSPRNG_METHOD=getrandom getentropy\n----\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"483994","messageId":"76c5f401-0b29-b19a-8424-5bca5df2252e@gmail.com","threadId":"60437","inReplyTo":"ZTui2NcJ3Ax_PIGO@tapette.crustytoothpaste.net","subject":"Re: Constant recompilation when GENERATE_COMPILATION_DATABASE is set","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2023-10-27T15:41:23Z","receivedAt":"2023-10-27T15:41:27Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi brian,\n\nLe 2023-10-27 à 07:45, brian m. carlson a écrit :\n> I typically use clangd with Git for the nice language server protocol\n> (LSP) support.  I noticed that when GENERATE_COMPILATION_DATABASE is set\n> (which is used so clangd can find the proper flags), `make` rebuilds all\n> of the files every time, even if I do it back to back.  This persists\n> even after a `git clean -dxf`.\n> \n> Obviously, this is not great, since it means the turnaround time to\n> compile changes is slower.  Unfortunately, I'm not a huge expert in make\n> and I'm unsure what the right solution is here.  I'd appreciate anyone's\n> thoughts on how to improve this.\n> \n> This is on a Debian sid (unstable) amd64 system with the following\n> configuration.  The version of clang in use is Debian's 16.0.6.\n> \n> ----\n> NO_OPENSSL=1\n> DC_SHA1=1\n> NETTLE_SHA256=1\n> DEVELOPER=1\n> NO_SVN_TESTS=1\n> NO_PYTHON=1\n> USE_ASCIIDOCTOR=1\n> USE_ASCIIDOCTOR_MANPAGE=1\n> CC=clang\n> GENERATE_COMPILATION_DATABASE=yes\n> CSPRNG_METHOD=getrandom getentropy\n> ----\n> \n\nIndeed, with GENERATE_COMPILATION_DATABASE=yes and CC=clang I can reproduce with:\n\nmake clean\nmake -j\nmake -j # this rebuilds everything\nmake -j # this does not rebuild anything\n\nso the second 'make' invocation is buggy, but not subsequent ones.\n\nI took a look at the 'make -d' output and we can see it is the dependency on \nthe 'compile_commands' directory that is the culprit, on the second invocation\nit is newer than the the first object file that makes checks.\n\nThis makes sense since each time we compile an object we put the JSON fragment in \ncompile_commands, so the directory is updated each time an object is built, so\nclearly its modification date will be newer than the one of the first object built.\n\nOne way to fix this is to use the same trick that is used for the '.depend' directories\ncreated to hold the Makefile dependencies: \n\ndiff --git a/Makefile b/Makefile\nindex 5776309365..f6f7255dd1 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -2701,7 +2701,7 @@ endif\n compdb_dir = compile_commands\n \n ifeq ($(GENERATE_COMPILATION_DATABASE),yes)\n-missing_compdb_dir = $(compdb_dir)\n+missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir))\n $(missing_compdb_dir):\n \t@mkdir -p $@\n \nThat is, we define missing_compdb_dir to 'compile_commands' only if the directory\nis not yet created.\n\nI'll try to send a proper patch for this.\n\nThanks for the report,\n\nPhilippe.\n"},{"id":"484002","messageId":"ZTwRRHhHxGt1nwL9@tapette.crustytoothpaste.net","threadId":"60437","inReplyTo":"76c5f401-0b29-b19a-8424-5bca5df2252e@gmail.com","subject":"Re: Constant recompilation when GENERATE_COMPILATION_DATABASE is set","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2023-10-27T19:36:36Z","receivedAt":"2023-10-27T19:36:40Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2023-10-27 at 15:41:23, Philippe Blain wrote:\n> One way to fix this is to use the same trick that is used for the '.depend' directories\n> created to hold the Makefile dependencies: \n> \n> diff --git a/Makefile b/Makefile\n> index 5776309365..f6f7255dd1 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -2701,7 +2701,7 @@ endif\n>  compdb_dir = compile_commands\n>  \n>  ifeq ($(GENERATE_COMPILATION_DATABASE),yes)\n> -missing_compdb_dir = $(compdb_dir)\n> +missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir))\n>  $(missing_compdb_dir):\n>  \t@mkdir -p $@\n>  \n> That is, we define missing_compdb_dir to 'compile_commands' only if the directory\n> is not yet created.\n\nI can confirm that this solves my problem very nicely.  Thanks for such\na fast response.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"}]}