git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/4] contrib: add iwyu script

From
Garrit Franke <garrit@slashdev.space>
Date
Apr 5, 2022, 11:45 UTC
Message-ID
<20220405114505.24389-2-garrit@slashdev.space>
In-Reply-To
<20220331194436.58005-1-garrit@slashdev.space>
add include-what-you-use helper.
Signed-off-by: Garrit Franke <garrit@slashdev.space>
---
 contrib/iwyu/README  | 33 +++++++++++++++++++++++++++++++++
 contrib/iwyu/iwyu.sh |  2 ++
 2 files changed, 35 insertions(+)
 create mode 100644 contrib/iwyu/README
 create mode 100755 contrib/iwyu/iwyu.sh
diff --git a/contrib/iwyu/README b/contrib/iwyu/README
new file mode 100644
index 0000000000..5e2d218602
--- /dev/null
+++ b/contrib/iwyu/README
@@ -0,0 +1,33 @@
+Include What You Use
+====================
+
+Include what you use (iwyu) [1] is a tool that points out which headers a file
+should include. Moreover, it can point out includes that are not used by a file,
+which makes it especially handy for cleanup tasks.
+
+To run this script, you will need iwyu to be installed on your system.
+
+The "iwyu.sh" script runs iwyu on a given object and omits mandatory headers
+defined in "Documentation/CodingGuidelines".
+
+Example usage:
+
+    ./contrib/iwyu/iwyu.sh diff.o
+
+This yields:
+
+    diff.c should remove these lines:
+    - #include "attr.h"  // lines 13-13
+    - #include "submodule-config.h"  // lines 18-18
+
+In its current form, this script should not be used to auto-generate patches,
+since there are still some false-positives that only a human can resolve. It is
+meant as a starting point for further cleanups. It could be nice to integrate
+this as a step in our CI, but we're not quite there yet.
+
+The inspiration for this script came from this [2] email-thread.
+
+Garrit Franke <garrit@slashdev.space>
+
+[1]: https://github.com/include-what-you-use/include-what-you-use
+[2]: https://lore.kernel.org/all/220401.8635ixp3f4.gmgdl@evledraar.gmail.com/#t
\ No newline at end of file
diff --git a/contrib/iwyu/iwyu.sh b/contrib/iwyu/iwyu.sh
new file mode 100755
index 0000000000..3ef8639eae
--- /dev/null
+++ b/contrib/iwyu/iwyu.sh
@@ -0,0 +1,2 @@
+make $1 CC=include-what-you-use CFLAGS="-Xiwyu --verbose=1" 2>&1 \
+| grep -v -E -e '^#include <' -e '^#include "(cache|git-compat-util|gettext)\.h"' 
\ No newline at end of file
-- 
2.35.1
Previous: Garrit FrankeNext: Ævar Arnfjörð Bjarmason
Message 8 of 12 in “bisect.c: remove unused includes”
  1. bisect.c: remove unused includesGarrit Franke, Mar 31, 2022
  2. Junio C HamanoMar 31, 2022
  3. using iwyu (include-what-you-use) to analyze includes (was: [PATCH] bisect.c: remove unused includes)Ævar Arnfjörð Bjarmason, Apr 1, 2022
  4. 0/4 various: use iwyu (include-what-you-use) to analyze includesGarrit Franke, Apr 5, 2022
  5. Ævar Arnfjörð BjarmasonApr 6, 2022
  6. 4/4 apply.c: remove unnecessary includeGarrit Franke, Apr 5, 2022
  7. 3/4 serve.c: remove unnecessary includeGarrit Franke, Apr 5, 2022
  8. 1/4 contrib: add iwyu scriptGarrit Franke, Apr 5, 2022
  9. Ævar Arnfjörð BjarmasonApr 6, 2022
  10. 2/4 bisect.c: remove unnecessary includeGarrit Franke, Apr 5, 2022
  11. Ævar Arnfjörð BjarmasonApr 6, 2022
  12. Junio C HamanoApr 6, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.