berkus / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
1 stars 0 forks source link

Pragma export not working for inline files #162

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?  Give the *exact* arguments passed
to include-what-you-use, and attach the input source file that gives the
problem (minimal test-cases are much appreciated!)

I'm working on a smaller test case, but for now the error comes up here: 

0. Built IWYU in-tree
1. clone https://github.com/aherlihy/mongo-cxx-driver legacy branch.
2. add "// IWYU pragma: export" to src/mongo/base/status.h:150 (at 
https://github.com/aherlihy/mongo-cxx-driver/blob/iwyu-PNT/src/mongo/base/status
.h#L150)
2. Run IWYU:
          a. Need to write little wrappers around iwyu because scons requires successful exit status. I've attached my two wrapper scripts (they'll need to be changed to match the path to iwyu).
          b. Run "scons --cc=iwyu.cc --cxx=iwyu.cxx build-base/parse_number_test"
4. Apply IWYU changes to code base: python fix_includes.py < iwyu_cxx.out

What is the expected output? What do you see instead?

We expect status.h to be included instead of status-inl.h. Instead, in places 
where status.h is used, status-inl.h is added to the include list. One example 
of many is in mongo/src/base/parse_number_test.cpp.

What version of the product are you using? On what operating system?

The most recent pull from svn: I ran svn co 
http://include-what-you-use.googlecode.com/svn/trunk/ include-what-you-use on 
Mac OSX 10.9.5 on 2.6GHz on Intel Core i5.

Please provide any additional information below.

I will try my best to recreate the issue with smaller test files, but so far 
I've been unsuccessful. I will let you know as soon as I do. Thank you!

Original issue reported on code.google.com by anna.her...@10gen.com on 7 Nov 2014 at 10:07

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report!

I'd love it if you could boil this down, I tried with a minimal repro with a .h 
and a -inl.h, but it seems to just work.

I'm on Windows, and I haven't been able to force scons to use IWYU for 
compiler, partly because I'm all new to scons :-) The toolchain search in your 
SConstruct seems a little too eager to use MSVC on Windows.

Any more detail would be great!

Original comment by kim.gras...@gmail.com on 13 Nov 2014 at 9:29

GoogleCodeExporter commented 9 years ago
Hi! I've found a much smaller example that recreates this issue (without 
scons!).  The bottom line is that when include-what-you-use is run from a 
different directory than the source files or is given the full path to the 
source files, it ignores pragma export. The attached files use pragma export, 
although we have tested with begin_exports/end_exports and have the same result.

From the directory with all the sample files, we ran:
     "~/llvm/build/bin/include-what-you-use ~/Documents/workspace/export-test/main.cpp &> test.out"

The expected output is that anywhere a function defined in test-inl.h is used, 
test.h is included instead. The exact results we are getting can be found in 
test.out (attached). Essentially, include-what-you-use is recommending that 
main.cpp include test-inl.h. 

This example is using the most recent pull from svn on Mac OSX 10.9.5.

Thank you!

Original comment by anna.her...@10gen.com on 14 Nov 2014 at 6:44

Attachments:

GoogleCodeExporter commented 9 years ago
Great info! I might not be able to look at this for a few days, but I'll try 
and reproduce and debug.

Original comment by kim.gras...@gmail.com on 15 Nov 2014 at 8:51

GoogleCodeExporter commented 9 years ago
I've now been able to take a quick look, and I know what's wrong, at least.

We have a heuristic function, ConvertToQuotedInclude, that attempts to map 
backwards from a full path to the quoted include name we'd use to include it. 
I'm beginning to think there is no good, general way to do that.

This is more or less the same as issue 5.

A workaround I found is to pass the path to test-inl.h on the command-line to 
IWYU:

$ include-what-you-use ~/Documents/workspace/export-test/main.cpp -I 
~/Documents/workspace/export-test

This worked for the reduced test case, but I have a hunch it might not work for 
your in-tree problem with mongodb...?

FWIW, I'll keep looking at this off and on.

Original comment by kim.gras...@gmail.com on 18 Nov 2014 at 8:13

GoogleCodeExporter commented 9 years ago
Thank you for getting back to me!

Unfortunately linking the path to the inline files doesn't fix our in-tree 
issue.

We are very interested in getting include-what-you-use to run on MongoDB, and I 
was wondering if you had any  ideas for how we could go in and fix this for our 
use case. We have a fairly consistent include pattern and standardized headers 
for most of our project. Any tips on how to get include-what-you-use 
(specifically CovertToQuotedInclude?) the information it needs to recognize 
inline files?

Thank you again!

Original comment by anna.her...@10gen.com on 19 Nov 2014 at 5:05

GoogleCodeExporter commented 9 years ago
Shame it didn't work... 

Yes, we're very interested in getting IWYU working for profile open-source 
projects (MongoDB being an obvious candidate) too! :-)

One idea I've had for ConvertToQuotedInclude is to also pass it the full path 
or FileEntry of the includer. This would solve things (I hope), because a 
quoted include's form depends directly on the path that includes it (this 
differs a little between compilers, but is generally true).

Unfortunately, it's used in a lot of places where the includer isn't known 
(pragma export handling being one example), so we lack the information we need 
to calculate the quoted include.

But I also have a feeling that IWYU overuses quoted includes, so maybe a 
majority of those cases can be eliminated altogether. For example, for pragma: 
export both the exporting and the exported FileEntry are known, and we should 
be able to store the export relationship without involving 
ConvertToQuotedInclude at all (touch wood!)

Original comment by kim.gras...@gmail.com on 19 Nov 2014 at 6:43