There seems to be a lot of time wasted on discussing what headers to include and what headers not to include, so it would be nice to just have a tool that does that for us. iwyu
is probably the closest to what I am looking for, but it is not straightforward to set up (see instructions below for Ubuntu). Let me know if the workflow could be simplified, so that is actually easily usable (maybe also on different distros).
iwyu makes a lot of changes, so it’s best to run it manually and selectively on individual source files, rather than in some automated place like a travis script.
To install on Ubuntu/Debian: apt install iwyu
.
0sudo apt install libclang-dev
1cd ~/src
2git clone github:include-what-you-use/include-what-you-use.git iwyu
3cd iwyu
4git checkout clang_3.8
5mkdir build && cd build
6cmake -DIWYU_LLVM_ROOT_PATH=/usr/lib/llvm-3.8 ..
7make
8sudo cp -aiv ~/src/iwyu/build/include-what-you-use /usr/lib/llvm-3.8/bin/
Steps to run:
0cd ~/src/bitcoin/src
1make
2rm -v interface/libbitcoin_util_a-chain.o # run iwyu on interface/chain.cpp
3make -k CXX="iwyu -std=c++17" 2>&1 | tee /tmp/iwyu
4~/src/iwyu/fix_includes.py < /tmp/iwyu
Taken from #11878 (comment)