Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
advice-type.h: add a generated list of advice, like hook-list.h
Make the addition of new advice to advice.[ch] simpler and more fool-proof by generating the list of advice enums from Documentation/config/advice.txt, instead of requiring new additions to be hardcoded across the three files (*.c, *.h and *.txt). In subsequent commits we'll also start auto-generating the mapping between enum labels and config keys (in advice.c). I.e. we'll only define these in advice.txt, and not in advice.c. But for now let's get rid of 1/3 of the duplicate places we declare these. This change is only practically possible due to the preceding fixes to "COMPUTE_HEADER_DEPENDENCIES" being extended here with "dep_template". I.e. we had generated headers before this, but for any file that relied on them we needed to manually declare the dependency on the generated header, see my d3fd1a6 (Makefile: correct the dependency graph of hook-list.h, 2021-12-17) for a case where I got that wrong. Unlike this new advice-type.h those cases are easy, each of our current generated headers is used in exactly one place, but this one needs to be added to advice.h, which is in turn included in cache.h. Even if we had the code that needs advice.h manually include it (I tried, and ejecting it from cache.h would probably be worthwhile) maintaining the dependency mapping would be fragile, although we could brute-force check its validity in CI by compiling every *.o file in a "make clean && make <file>.o" loop. But as this change shows we can do better. We have the *.o and *.s files depend on "$(COMMON_GENERATED_H)" under COMPUTE_HEADER_DEPENDENCIES , but only if we haven't compiled it once before. We can thus benefit from the accurate dependencies the compiler generated. This means that e.g. this works: $ git clean -qdxf; make grep.o; git clean -dxf '*.h' '*.o'; make grep.o GIT_VERSION = 2.35.1.475.g534253553cd.dirty * new build flags MKDIR -p .build/dep GEN advice-type.h CC grep.o Removing advice-type.h Removing grep.o CC grep.o I.e. note how we have grep.o over-depend on advice-type.h, but only the first time around. The second time around we looked at the dependency graph in ".build/dep/grep.o.d". Doing the same with e.g. remote.o (which does use the generated header) will end in: Removing advice-type.h Removing remote.o GEN advice-type.h CC remote.o I.e. in that case we do still depend on advice-type.h post-compilation: $ grep -c advice-type.h .build/dep/remote.o.d 2 $ We would need one additional special-case: The advice-type.h header is the only generated header that's included in another header, so for "make hdr-check" we need to have advice.hco depend on advice-type.h. Let's instead just have all *.hco depend on these $(COMMON_GENERATED_H), it will make this less fragile going forward. See cfe853e (hook-list.h: add a generated list of hooks, like config-list.h, 2021-09-26) for similar prior art, including a similar addition to CMakeLists.txt. generate-advice.sh portability notes: the $HT is needed due to e.g. AIX's "sed". Solaris's "sed" and "tr" then don't understand the (non-portable) "[A-Z]" or "A-Z" syntax, so POSIX character classes are being used here. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Loading branch information