-
Notifications
You must be signed in to change notification settings - Fork 37.7k
tidy: add include-what-you-use #24831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Concept ACK |
It might be good to add some developer notes docs on this if it moves forward. |
Concept ACK. |
Concept ACK and thanks for working on this! I've used IWYU on other projects and it was nice once you got it set up. I think ideally it would be easy to run IWYU locally, but getting it working on CI is useful, and should make it easier to run locally as well. |
Concept ACK |
src/compat/stdin.cpp
Outdated
@@ -3,18 +3,18 @@ | |||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||
|
|||
#if defined(HAVE_CONFIG_H) | |||
#include <config/bitcoin-config.h> | |||
#include <config/bitcoin-config.h> // IWYU pragma: keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? (I mean the include)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? (I mean the include)
In this case, the include isn't actually needed. Although in other cases we'll likely use the same pragma on this same include to suppress IWYU output, given we aren't building for all configurations (I think that's ok). I'm removing it now.
Add missing includes. Swap C headers for their C++ counterparts. Remove pointless / unmaintainable include comments. This is even more the case when we are actually using IWYU, as if anyone wants to see the comments they can just get IWYU to generate them.
2f7817d
to
9b0a13a
Compare
Concept ACK. Awesome! |
review ACK 9b0a13a |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 9b0a13a reviewed changes and run CI output in https://cirrus-ci.com/task/4750910332076032
Going to merge this so that ppl can start experimenting with this and also use it in more places. Hopefully this will help us reduce compile time by nuking useless includes and reduce review burden by automating the review discussions on which headers to include/remove. If there are any issues, it should be trivial to disable in CI by editing |
@@ -37,6 +37,8 @@ fi | |||
if [ "${RUN_TIDY}" = "true" ]; then | |||
export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST/src/" | |||
CI_EXEC run-clang-tidy "${MAKEJOBS}" | |||
export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST/" | |||
CI_EXEC "python3 ${BASE_SCRATCH_DIR}/iwyu/include-what-you-use/iwyu_tool.py src/compat src/init -p . ${MAKEJOBS} -- -Xiwyu --cxx17ns -Xiwyu --mapping_file=${BASE_BUILD_DIR}/bitcoin-$HOST/contrib/devtools/iwyu/bitcoin.core.imp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is setting the return code to non-zero if it fails?
Based on the passing test in https://cirrus-ci.com/task/4869683827441664?logs=ci#L6712 it does not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #26763.
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:
The include "fixing" commits of this PR:
//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:TODO:
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.