Re: Issue 1282 in include-what-you-use: can iwyu ignore certain headers?

218 views
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Oct 6, 2023, 5:18:46 AM10/6/23
to include-wh...@googlegroups.com
Comment #4 on issue 1282 by naeimeh69: can iwyu ignore certain headers?
https://github.com/include-what-you-use/include-what-you-use/issues/1282

@kimgr
For example in my library I have a header file called my_lib.h. This header file included date_generators.hpp from boost library and inside CmakeList.txt I have include boot as a sub_directory.
What I expect from iwyu is only analyzing my_lib.h. But what iwyu do is that it analyzes boost header files as well, e.x.
The full include-list for external/boost/include/boost/date_time/date_generators.hpp should add these lines:
The full include-list for /external/boost/include/boost/date_time/gregorian/greg_weekday.hpp:
I think @swiesheier wants to exclude boost from iwyu analysis. This is what I'm looking for it as well. Am I right @swiesheier?


notifi...@include-what-you-use.org

unread,
Oct 9, 2023, 4:01:48 PM10/9/23
to include-wh...@googlegroups.com
Comment #5 on issue 1282 by kimgr: can iwyu ignore certain headers?
https://github.com/include-what-you-use/include-what-you-use/issues/1282

Have you tried the [keep directive](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md#iwyu-pragma-keep)? Something like:
```
#include "boost/date_time/date_generators.hpp" // IWYU pragma: keep

..
```
If that didn't work, have you tried using [the mappings](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md#specifying-mapping-files) [for Boost](https://github.com/include-what-you-use/include-what-you-use/blob/master/boost-1.75-all.imp)?

In general, no, you can't exclude a library from analysis.


notifi...@include-what-you-use.org

unread,
Oct 12, 2023, 8:13:52 AM10/12/23
to include-wh...@googlegroups.com
Comment #6 on issue 1282 by naeimeh69: can iwyu ignore certain headers?
https://github.com/include-what-you-use/include-what-you-use/issues/1282

@kimgr
No, I didn't try these options. The project is big and I should think of a way that doesn't need to change all files.
I figured out that it would be better to run iwyu on single files. But now there is another issue. Lets assume that I have the below files:
test/include/foo.hpp
test/src/foo.cpp
And inside test/src/foo.cpp I have " #include "foo.hpp" ". When I run include-what-you-use test/src/foo.cpp I get the below error:
fatal error: 'foo.hpp' file not found.
How should I fix this issue? How should I make iwyu recognize 'foo.hpp' is test/include/foo.hpp?


notifi...@include-what-you-use.org

unread,
Oct 12, 2023, 5:40:02 PM10/12/23
to include-wh...@googlegroups.com
Comment #7 on issue 1282 by kilroyd: can iwyu ignore certain headers?
https://github.com/include-what-you-use/include-what-you-use/issues/1282

`include-what-you-use` needs the preprocessor options that get passed to the compiler i.e. the `-I` and `-D` compiler options. The easiest way to get this is to get CMake to generate a `compile_commands.json` files by either adding `CMAKE_EXPORT_COMPILE_COMMANDS=ON` to your `CMakeLists.txt` or to add `-D CMAKE_EXPORT_COMPILE_COMMANDS=ON`. Then call `iwyu_tool.py` rather than calling `include-what-you-use`:

iwyu_tool.py -p $PATH_TO_BUILD_DIR $SOURCES/test/src/foo.cpp

See https://github.com/include-what-you-use/include-what-you-use#using-with-a-compilation-database


notifi...@include-what-you-use.org

unread,
Oct 13, 2023, 4:10:29 AM10/13/23
to include-wh...@googlegroups.com
Comment #8 on issue 1282 by naeimeh69: can iwyu ignore certain headers?
https://github.com/include-what-you-use/include-what-you-use/issues/1282

@kilroyd
My first plan was to integrate iwyu in the build_system and use cmake. But there are a lot of problem as the project is big and has a lot of third-party libraries. So, iwyu processes third-party header files and also it takes a lot of time to build the project for iwyu. So, I decided to run iwyu on single files. In this way I collect a list of files that I want to check with iwyu.


notifi...@include-what-you-use.org

unread,
Oct 21, 2023, 4:53:02 AM10/21/23
to include-wh...@googlegroups.com
Comment #9 on issue 1282 by kimgr: can iwyu ignore certain headers?
https://github.com/include-what-you-use/include-what-you-use/issues/1282

> So, I decided to run iwyu on single files. In this way I collect a list of files that I want to check with iwyu.

You can do that, but you need to pass the same arguments to `include-what-you-use` as you pass to your compiler. All available alternatives are described here: https://github.com/include-what-you-use/include-what-you-use/#how-to-run.


Reply all
Reply to author
Forward
0 new messages