]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Makefile: avoid constant rebuilds with compilation database
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 9 May 2025 21:12:02 +0000 (21:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 May 2025 21:50:20 +0000 (14:50 -0700)
Many contributors to software use a Language Server Protocol
implementation to allow their editor to learn structural information
about the code they write and provide additional features, such as
jumping to the declaration or definition of a function or type.  In C,
the usual implementation is clangd, which requires compiling with clang.

Because C and C++ projects lack a standard file system layout and build
system, unlike languages such as Rust and Go, clangd requires a
compilation database to be generated by the clang compiler in order to
pass the proper compilation flags and discover all of the files
necessary to make the LSP work.  This is done by setting
GENERATE_COMPILATION_DATABASE to "yes".

However, when that's enabled and the user runs "make" a second time,
all of the files are re-compiled, which is inconvenient for contributors
to Git, since it makes small changes or rebases recompile the entirety
of the codebase.  This happens because the directory holding the
compilation database is updated anytime an object is built, so its
modification date will always be newer than the first object built.

To solve this, use the same trick we do just above for the .depend
directory and filter the compilation database directory out if it
already exists, which avoids making it a target to be built.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Helped-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile

index 97e8385b6643b963c54affb3ae621fc93fad28b5..ee36e700e8862c7783310158ae5de402ef2b54ac 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2757,7 +2757,7 @@ endif
 compdb_dir = compile_commands
 
 ifeq ($(GENERATE_COMPILATION_DATABASE),yes)
-missing_compdb_dir = $(compdb_dir)
+missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir))
 $(missing_compdb_dir):
        @mkdir -p $@