tidy: add include-what-you-use #24831

pull fanquake wants to merge 3 commits into bitcoin:master from fanquake:include_what_you_use changing 16 files +40 −14
  1. fanquake commented at 10:32 am on April 12, 2022: member

    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.

  2. jonatack commented at 10:36 am on April 12, 2022: contributor
    Concept ACK
  3. jonatack commented at 10:38 am on April 12, 2022: contributor
    It might be good to add some developer notes docs on this if it moves forward.
  4. DrahtBot added the label Build system on Apr 12, 2022
  5. DrahtBot added the label Scripts and tools on Apr 12, 2022
  6. DrahtBot added the label Utils/log/libs on Apr 12, 2022
  7. hebasto commented at 1:04 pm on April 12, 2022: member
    Concept ACK.
  8. ryanofsky commented at 4:10 pm on April 12, 2022: contributor
    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.
  9. laanwj commented at 2:23 pm on April 13, 2022: member
    Concept ACK
  10. in src/compat/stdin.cpp:6 in 2f7817d0e8 outdated
    2@@ -3,18 +3,18 @@
    3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
    4 
    5 #if defined(HAVE_CONFIG_H)
    6-#include <config/bitcoin-config.h>
    7+#include <config/bitcoin-config.h> // IWYU pragma: keep
    


    maflcko commented at 11:52 am on April 15, 2022:
    why is this needed? (I mean the include)

    fanquake commented at 12:54 pm on April 20, 2022:

    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.

  11. maflcko approved
  12. refactor: fix includes in src/compat
    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.
    c79ad935f0
  13. refactor: fix includes in src/init 74cd038e30
  14. fanquake renamed this:
    [POC] tidy: add include-what-you-use
    tidy: add include-what-you-use
    on Apr 20, 2022
  15. tidy: Add include-what-you-use 9b0a13a289
  16. fanquake force-pushed on Apr 20, 2022
  17. jamesob commented at 1:42 pm on April 20, 2022: member
    Concept ACK. Awesome!
  18. maflcko commented at 2:11 pm on April 20, 2022: member
    review ACK 9b0a13a2891641a3d12e525cee8ddddb1aa1bc73
  19. maflcko approved
  20. maflcko removed the label Build system on Apr 20, 2022
  21. maflcko removed the label Utils/log/libs on Apr 20, 2022
  22. maflcko removed the label Scripts and tools on Apr 20, 2022
  23. maflcko added the label Refactoring on Apr 20, 2022
  24. fanquake marked this as ready for review on Apr 20, 2022
  25. DrahtBot commented at 5:14 pm on April 20, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    No conflicts as of last run.

  26. jonatack commented at 5:41 pm on April 21, 2022: contributor
    ACK 9b0a13a2891641a3d12e525cee8ddddb1aa1bc73 reviewed changes and run CI output in https://cirrus-ci.com/task/4750910332076032
  27. maflcko commented at 8:03 am on April 28, 2022: member

    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 ci/test/06_script_b.sh.

  28. maflcko merged this on Apr 28, 2022
  29. maflcko closed this on Apr 28, 2022

  30. fanquake deleted the branch on Apr 28, 2022
  31. in ci/test/06_script_b.sh:41 in 9b0a13a289
    36@@ -37,6 +37,8 @@ fi
    37 if [ "${RUN_TIDY}" = "true" ]; then
    38   export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST/src/"
    39   CI_EXEC run-clang-tidy "${MAKEJOBS}"
    40+  export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST/"
    41+  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"
    


    maflcko commented at 2:01 pm on April 29, 2022:

    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?


    hebasto commented at 6:17 pm on December 28, 2022:
    See #26763.
  32. sidhujag referenced this in commit 70e8e03e1d on Apr 29, 2022
  33. bitcoin locked this on Dec 28, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me