git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/1] Makefile: use `git ls-files` to list header files, if possible

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 4, 2019, 13:47 UTC
Message-ID
<cb253bd0cf2896cf31516079a89ec2dab21032cf.1551707225.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.130.v2.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In d85b0dff72 (Makefile: use `find` to determine static header dependencies, 2014-08-25), we switched from a static list of header files to a dynamically-generated one, asking `find` to enumerate them.

Back in those days, we did not use `$(LIB_H)` by default, and many a `make` implementation seems smart enough not to run that `find` command in that case, so it was deemed okay to run `find` for special targets requiring this macro.

However, as of ebb7baf02f (Makefile: add a hdr-check target, 2018-09-19), $(LIB_H) is part of a global rule and therefore must be expanded. Meaning: this `find` command has to be run upon every `make` invocation. In the presence of many a worktree, this can tax the developers' patience quite a bit.

Even in the absence of worktrees or other untracked files and directories, the cost of I/O to generate that list of header files is simply a lot larger than a simple `git ls-files` call.

Therefore, just like in 335339758c (Makefile: ask "ls-files" to list source files if available, 2011-10-18), we now prefer to use `git ls-files` to enumerate the header files to enumerating them via `find`, falling back to the latter if the former failed (which would be the case e.g. in a worktree that was extracted from a source .tar file rather than from a clone of Git's sources).

This has one notable consequence: we no longer include `command-list.h` in `LIB_H`, as it is a generated file, not a tracked one, but that is easily worked around. Of the three sites that use `LIB_H`, two (`LOCALIZED_C` and `CHK_HDRS`) already handle generated headers separately. In the third, the computed-dependency fallback, we can just add in a reference to $(GENERATED_H).

Likewise, we no longer include not-yet-tracked header files in `LIB_H`.

Given the speed improvements, these consequences seem a comparably small price to pay.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index c5240942f2..0c4712cb48 100644
--- a/Makefile
+++ b/Makefile
@@ -841,7 +841,8 @@ VCSSVN_LIB = vcs-svn/lib.a
 
 GENERATED_H += command-list.h
 
-LIB_H = $(shell $(FIND) . \
+LIB_H := $(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
+	$(FIND) . \
 	-name .git -prune -o \
 	-name t -prune -o \
 	-name Documentation -prune -o \
@@ -2363,7 +2364,7 @@ else
 # should _not_ be included here, since they are necessary even when
 # building an object for the first time.
 
-$(OBJECTS): $(LIB_H)
+$(OBJECTS): $(LIB_H) $(GENERATED_H)
 endif
 
 exec-cmd.sp exec-cmd.s exec-cmd.o: GIT-PREFIX
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Ramsay Jones
Message 28 of 31 in “Avoid calling find in the Makefile, if possible”
  1. 0/1 Avoid calling find in the Makefile, if possibleJohannes Schindelin via GitGitGadget, Mar 1, 2019
  2. 1/1 Makefile: use `git ls-files` to list header files, if possibleJohannes Schindelin via GitGitGadget, Mar 1, 2019
  3. Jeff KingMar 1, 2019
  4. Jeff KingMar 1, 2019
  5. Jeff KingMar 1, 2019
  6. Johannes SchindelinMar 2, 2019
  7. Jeff KingMar 3, 2019
  8. Johannes SchindelinMar 2, 2019
  9. Jeff KingMar 3, 2019
  10. Johannes SchindelinMar 2, 2019
  11. Jeff KingMar 3, 2019
  12. Ramsay JonesMar 3, 2019
  13. Johannes SchindelinMar 4, 2019
  14. Ramsay JonesMar 4, 2019
  15. Jeff KingMar 4, 2019
  16. Johannes SchindelinMar 4, 2019
  17. Jeff KingMar 4, 2019
  18. Junio C HamanoMar 5, 2019
  19. Johannes SchindelinMar 5, 2019
  20. Junio C HamanoMar 5, 2019
  21. Jeff KingMar 5, 2019
  22. Ramsay JonesMar 6, 2019
  23. Jeff KingMar 6, 2019
  24. Junio C HamanoMar 6, 2019
  25. compat/bswap: add include header guardsJeff King, Mar 6, 2019
  26. Junio C HamanoMar 6, 2019
  27. 0/1 Avoid calling find in the Makefile, if possibleJohannes Schindelin via GitGitGadget, Mar 4, 2019
  28. 1/1 Makefile: use `git ls-files` to list header files, if possibleJohannes Schindelin via GitGitGadget, Mar 4, 2019
  29. Ramsay JonesMar 4, 2019
  30. Ramsay JonesMar 4, 2019
  31. Jeff KingMar 4, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.