As mentioned in #26924 (comment) and #29263 (comment), it is currently not safe to remove bitcoin-config.h
includes from headers because some unrelated file might be depending on it.
See also #26972 for discussion.
Solve this by including the file directly everywhere it’s required, regardless of whether or not it’s already included by another header.
There should be no functional change here, but it will allow us to safely remove includes from headers in the future.
I’m afraid it’s a bit tedious to reproduce these commits, but it’s reasonably straightforward:
Edit: See note below
0# All commands executed from the src/ subdir.
1
2# Collect all tokens from bitcoin-config.h.in
3# Isolate the tokens and remove blank lines
4# Replace newlines with | and remove the last trailing one
5# Collect all files which use these tokens
6# Filter out subprojects (proper forwarding can be verified from Makefiles)
7# Filter out .rc files
8# Save to a text file
9git grep -E -l `grep undef config/bitcoin-config.h.in | cut -d" " -f2 | grep -v '^$' | tr '\n' '|' | sed 's/|$//'` | grep -v -e "^leveldb/" -e "^secp256k1/" -e "^crc32c/" -e "^minisketch/" -e "^Makefile" -e "\.rc$" > files-with-config-include.txt
10
11# Find all files from the above list which don't include bitcoin-config.h
12git grep -L -E "config/bitcoin-config.h" -- `cat files-with-config-include.txt`
13
14# Include them manually with the exception of some files in crypto:
15# crypto/sha256_arm_shani.cpp crypto/sha256_avx2.cpp crypto/sha256_sse41.cpp crypto/sha256_x86_shani.cpp
16# These are exceptions which don't use bitcoin-config.h, rather the Makefile.am adds these cppflags manually.
17
18# Commit changes. This should match the first commit of this PR.
19
20# Use the same search as above to find all files which DON'T use any config tokens
21git grep -E -L `grep undef config/bitcoin-config.h.in | cut -d" " -f2 | grep -v '^$' | tr '\n' '|' | sed 's/|$//'` | grep -v -e "^leveldb/" -e "^secp256k1/" -e "^crc32c/" -e "^minisketch/" -e "^Makefile" -e "\.rc$" > files-without-config-include.txt
22
23# Manually remove the includes and commit changes. This should match the second commit of this PR.
Edit: I’ll keep this old description for posterity, but the manual approach has been replaced with a scripted diff from TheCharlatan