We recently added a clang-tidy
job to the CI, which generates a compilation database. We can leverage that now existing database to begin running include-what-you-use over the codebase.
This PR demonstrates using a mapping_file to indicate fixups / includes that may differ from IWYU suggestions. In this case, I’ve added some fixups for glibc includes that I’ve upstreamed changes for:
0# Fixups / upstreamed changes
1[
2 { include: [ "<bits/termios-c_lflag.h>", private, "<termios.h>", public ] },
3 { include: [ "<bits/termios-struct.h>", private, "<termios.h>", public ] },
4 { include: [ "<bits/termios-tcflow.h>", private, "<termios.h>", public ] },
5]
The include “fixing” commits of this PR:
- Adds missing includes.
- Swaps C headers for their C++ counterparts.
- Removes the pointless / unmaintainable
//for abc, xyz
comments. When using IWYU, if anyone wants to see / generate those comments, to see why something is included, it is trivial to do so (IWYU outputs them by default). i.e:
0// The full include-list for compat/stdin.cpp:
1#include <compat/stdin.h>
2#include <poll.h> // for poll, pollfd, POLLIN
3#include <termios.h> // for tcgetattr, tcsetattr
4#include <unistd.h> // for isatty, STDIN_FILENO
TODO:
- Qt mapping_file. There is one in the IWYU repo, but it’s for Qt 5.11. Needs testing.
- Boost mapping_file. There is one in the IWYU repo, but it’s for Boost 1.75. Needs testing.
I’m not suggesting we turn this on the for entire codebase, or immediately go-nuts refactoring all includes. However I think our dependency includes are now slim enough, and our CI infrastructure in place such that we can start doing this in some capacity, and just automate away include fixups / refactorings etc.