Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES)

Combine the definitions of $(FIND_SOURCE_FILES) and $(LIB_H) to speed up the Makefile, as these are the two main expensive $(shell) commands that we execute unconditionally. When see what was in $(FOUND_SOURCE_FILES) that wasn't in $(LIB_H) via the ad-hoc test of: $(error $(filter-out $(LIB_H),$(filter %.h,$(ALL_SOURCE_FILES)))) $(error $(filter-out $(ALL_SOURCE_FILES),$(filter %.h,$(LIB_H)))) We'll get, respectively: Makefile:850: *** t/helper/test-tool.h. Stop. Makefile:850: *** . Stop. I.e. we only had a discrepancy when it came to t/helper/test-tool.h. In terms of correctness this was broken before, but now works: $ make t/helper/test-tool.hco HDR t/helper/test-tool.h This speeds things up a lot: $ git -c hyperfine.hook.setup= hyperfine -L rev HEAD~1,HEAD~0 -s 'make NO_TCLTK=Y' 'make -j1 NO_TCLTK=Y' --warmup 10 -M 10 Benchmark 1: make -j1 NO_TCLTK=Y' in 'HEAD~1 Time (mean ± σ): 159.9 ms ± 6.8 ms [User: 137.2 ms, System: 28.0 ms] Range (min … max): 154.6 ms … 175.9 ms 10 runs Benchmark 2: make -j1 NO_TCLTK=Y' in 'HEAD~0 Time (mean ± σ): 100.0 ms ± 1.3 ms [User: 84.2 ms, System: 20.2 ms] Range (min … max): 98.8 ms … 102.8 ms 10 runs Summary 'make -j1 NO_TCLTK=Y' in 'HEAD~0' ran 1.60 ± 0.07 times faster than 'make -j1 NO_TCLTK=Y' in 'HEAD~1' Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 3, 2022 at 17:04 UTC f4c6a526a13ad23b941d574e83980a0e81dea38f
1 file changed +26 -28
Makefile
+26 -28
@@ -833,12 +833,33 @@ GENERATED_H += hook-list.h
833 .PHONY: generated-hdrs
834 generated-hdrs: $(GENERATED_H)
835
836 -LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
836 +## Exhaustive lists of our source files, either dynamically generated,
837 +## or hardcoded.
838 +SOURCES_CMD = ( \
839 + git ls-files \
840 + '*.[hcS]' \
841 + '*.sh' \
842 + ':!*[tp][0-9][0-9][0-9][0-9]*' \
843 + ':!contrib' \
844 + 2>/dev/null || \
845 $(FIND) . \
838 - -name .git -prune -o \
839 - -name t -prune -o \
840 - -name Documentation -prune -o \
841 - -name '*.h' -print)))
846 + \( -name .git -type d -prune \) \
847 + -o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
848 + -o \( -name contrib -type d -prune \) \
849 + -o \( -name build -type d -prune \) \
850 + -o \( -name 'trash*' -type d -prune \) \
851 + -o \( -name '*.[hcS]' -type f -print \) \
852 + -o \( -name '*.sh' -type f -print \) \
853 + | sed -e 's|^\./||' \
854 + )
855 +FOUND_SOURCE_FILES := $(shell $(SOURCES_CMD))
856 +
857 +FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
858 +FOUND_H_SOURCES = $(filter %.h,$(FOUND_SOURCE_FILES))
859 +
860 +COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
861 +
862 +LIB_H = $(FOUND_H_SOURCES)
863
864 LIB_OBJS += abspath.o
865 LIB_OBJS += add-interactive.o
@@ -2789,26 +2810,6 @@ perl/build/man/man3/Git.3pm: perl/Git.pm
2810 $(QUIET_GEN)mkdir -p $(dir $@) && \
2811 pod2man $< $@
2812
2792 -FIND_SOURCE_FILES = ( \
2793 - git ls-files \
2794 - '*.[hcS]' \
2795 - '*.sh' \
2796 - ':!*[tp][0-9][0-9][0-9][0-9]*' \
2797 - ':!contrib' \
2798 - 2>/dev/null || \
2799 - $(FIND) . \
2800 - \( -name .git -type d -prune \) \
2801 - -o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
2802 - -o \( -name contrib -type d -prune \) \
2803 - -o \( -name build -type d -prune \) \
2804 - -o \( -name 'trash*' -type d -prune \) \
2805 - -o \( -name '*.[hcS]' -type f -print \) \
2806 - -o \( -name '*.sh' -type f -print \) \
2807 - | sed -e 's|^\./||' \
2808 - )
2809 -
2810 -FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
2811 -
2813 $(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
2814 $(QUIET_GEN)$(RM) $@+ && \
2815 echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \
@@ -3018,9 +3019,6 @@ check: $(GENERATED_H)
3019 exit 1; \
3020 fi
3021
3021 -FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
3022 -COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
3023 -
3022 %.cocci.patch: %.cocci $(COCCI_SOURCES)
3023 $(QUIET_SPATCH) \
3024 if test $(SPATCH_BATCH_SIZE) = 0; then \