Issue 980 in include-what-you-use: Mapping files not working

62 views
Skip to first unread message

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

unread,
Dec 7, 2021, 4:49:33 AM12/7/21
to include-wh...@googlegroups.com
New issue 980 by a-cristi: Mapping files not working
https://github.com/include-what-you-use/include-what-you-use/issues/980

This is probably not an issue with IWYU, but a lack of understanding on my part, but I can't figure it out just by following the documentation.

I have a header that is a collection of other headers. I want `iwyu` to suggest me to include that, instead of the headers it includes, and to not suggest those other headers.

I'll use a simplified example.

I have the 2 header files and a source file:

```c
// h1.h
#pragma once

#include "h2.h"

#define H1_DEF 1
```

```c
// h2.h
#pragma once

#define H2_DEF 2
```

```c
// s.c
#include "h1.h" // I want this to be considered OK by iwyu
#include <stdio.h>

int main()
{
printf("%d %d\n", H1_DEF, H2_DEF);
return 0;
}
```

Running `iwyu` gives the following result:

```console
$ iwyu -Xiwyu s.c

s.c should add these lines:
#include "h2.h" // for H2_DEF

s.c should remove these lines:

The full include-list for s.c:
#include <stdio.h> // for printf
#include "h1.h" // for H1_DEF
#include "h2.h" // for H2_DEF
---
```

I'm trying to use a mapping file, but it seems to have no effect:

```
[
{ include: ["<h2.h>", "private", "<h1.h>", "public"] }
]
```

Running `iwyu`:

```console
iwyu -Xiwyu --mapping_file=m.imp s.c

s.c should add these lines:
#include "h2.h" // for H2_DEF

s.c should remove these lines:

The full include-list for s.c:
#include <stdio.h> // for printf
#include "h1.h" // for H1_DEF
#include "h2.h" // for H2_DEF
---
```

If I'm using `symbol` it almost works:

```
[
{ symbol: ["H2_DEF", "private", "<h1.h>", "public"] }
]
```

This gives the following result:

```
s.c should add these lines:
#include <h1.h> // for H2_DEF

s.c should remove these lines:

The full include-list for s.c:
#include <h1.h> // for H2_DEF
#include <stdio.h> // for printf
#include "h1.h" // for H1_DEF
---
```

There are 3 problems here:

1. `h1` is suggested twice
2. `<h1.h>` is suggested
3. I'd like to not write one `symbol` line for everything I have in those headers


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

unread,
Dec 8, 2021, 3:36:30 AM12/8/21
to include-wh...@googlegroups.com
Comment #1 on issue 980 by a-cristi: Mapping files not working
https://github.com/include-what-you-use/include-what-you-use/issues/980

Thanks for helping me out, but I think I'm still doing something wrong:

Should this suggest `<h1.h>` instead of `<h2.h>` or `"h2.h"`? Because it still suggests both `"h1.h"` and `"h2.h"`.

```
[
{ include: ["@[\"<](h2\\.h[\">]", "private", "<h1.h>", "public"] }
]
```

> Mappings include the quoting, so "h1.h" is different from <h1.h> (unfortunately).

Does this apply the to-entry as well? Trying to specify it in any other way triggers an: ` error: Expected to-entry to be quoted include`.


Reply all
Reply to author
Forward
0 new messages