Announcing include-what-you-use 0.1

I am very pleased to announce the version 0.1 release of
include-what-you-use:
   http://code.google.com/p/include-what-you-use/

Include-what-you-use is a tool built on top of clang libraries, that
analyzes a C++ (or C) file to figure out what #includes are actually
needed. It then lists the set of changes needed to get the file to
have minimal, direct #includes, that reflect the symbols the file
actual uses.

Include-what-you-use is a hard problem
(http://code.google.com/p/include-what-you-use/wiki/WhyIWYUIsDifficult),
so the results are not yet perfect. But this is an ideal crowd to
make them more so! (Especially since my knowledge of clang internals
is still pretty rudimentary, to say nothing of the dark, dusty corners
of C++.) Feel free to play around with iwyu, and to submit patches to
improve it!

craig

You may wish to emphasize the removing-superfluous-includes feature more
on the project page; it's not clear that that's an aim (and it's the
feature that most attracts me).

John Bytheway

I would really really like to see this lib included directly in the
main clang svn repository, it would be easier to maintain, attract
developers and keep up to date. I think the scope of iwuy is general
purpose enough to justify it.

My first comment is that this lib really needs a CMake makefile.
I really want to build this thing using MSVC.

I wanted to try it out with CMake as well. I've attached a simple CMakeLists.txt file that seems to do the trick. Just drop it in the include-what-you-use directory and add:

add_subdirectory(include-what-you-use)

at the end of tools/clang/CMakeLists.txt. Works for me :slight_smile:

Jason

CMakeLists.txt (413 Bytes)

} I would really really like to see this lib included directly in the
} main clang svn repository, it would be easier to maintain, attract
} developers and keep up to date. I think the scope of iwuy is general
} purpose enough to justify it.

I'm happy to do this if there's general agreement it's a good idea.

} My first comment is that this lib really needs a CMake makefile. I
} really want to build this thing using MSVC.

I'm happy to accept a patch! I don't know cmake at all.

craig

csilvers-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org (Craig Silverstein)
writes:

} I would really really like to see this lib included directly in the
} main clang svn repository, it would be easier to maintain, attract
} developers and keep up to date. I think the scope of iwuy is general
} purpose enough to justify it.

I'm happy to do this if there's general agreement it's a good idea.

At worst it seems like an interesting example tool. (IMHO)

} My first comment is that this lib really needs a CMake makefile. I
} really want to build this thing using MSVC.

I'm happy to accept a patch! I don't know cmake at all.

Jason Haslam gave a suitable one on Friday.

} Jason Haslam gave a suitable one on Friday.

Thanks, I've submitted that one to the SVN.

} > I'm happy to do this if there's general agreement it's a good idea.
} At worst it seems like an interesting example tool. (IMHO)

OK. What does that mean in terms of next steps?

craig

Craig Silverstein <csilvers-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
writes:

} Jason Haslam gave a suitable one on Friday.

[...]

} At worst it seems like an interesting example tool. (IMHO)

OK. What does that mean in terms of next steps?

It means nothing (it was just my opinion), so carry on as you are.

Practically, if Chris Lattner agrees and thinks it ought to be an
example rather than a tool then it would go into examples/ rather than
tools/, and I imagine you'd need commit access, etc. But my opinion
carries negligable weight (quite likely none at all, and nor should it).

Jason Haslam <jason.haslam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
writes:

[...]

add_subdirectory(include-what-you-use)

at the end of tools/clang/CMakeLists.txt. Works for me :slight_smile:

Fails in the link for me:

Linking CXX executable ../../../../bin/include-what-you-use
../../../../lib/libclangAST.a(InheritViz.cpp.o): In function `clang::InheritanceHierarchyWriter::WriteNode(clang::QualType, bool)':
/local/brs/work/llvm-source/tools/clang/lib/AST/InheritViz.cpp:80: undefined reference to `llvm::DOT::EscapeString(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
../../../../lib/libclangAST.a(InheritViz.cpp.o): In function `clang::CXXRecordDecl::viewInheritance(clang::ASTContext&) const':
/local/brs/work/llvm-source/tools/clang/lib/AST/InheritViz.cpp:160: undefined reference to `llvm::DisplayGraph(llvm::sys::Path const&, bool, llvm::GraphProgram::Name)'

I'm using GNU ld on GNU/Linux. Presumably the linker behaviour is
what's different. Building with VERBOSE=1 shows that libLLVMSupport.a
(which defines llvm::DOT::EscapeString()) and so on are being included
in the link line. By adding copies of such libraries to the link line
(linking on the command-line rather than through make) I can link it.

Presumably some change to CMakeLists.txt would fix it, but I'm not sure
what. Maybe the list of clang dependencies is in the wrong order or
something?

Ugh, I probably screwed it up by sorting the libraries. Here's a patch that restores the original order from the Makefile. I didn't test it with a linker that cares about order, but it probably works.

Jason

iwyu_cmake_lib_order.patch (488 Bytes)

Ugh, I probably screwed it up by sorting the libraries. Here's a patch that restores the original order from the Makefile. I didn't test it with a linker that cares about order, but it probably works.

You should submit this patch here:
http://code.google.com/p/include-what-you-use/issues/list

Jason Haslam <jason.haslam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
writes:

[...]

Ugh, I probably screwed it up by sorting the libraries. Here's a patch
that restores the original order from the Makefile. I didn't test it
with a linker that cares about order, but it probably works.

That works, thanks.

[...]

} > Ugh, I probably screwed it up by sorting the libraries. Here's a patch
} > that restores the original order from the Makefile. I didn't test it
} > with a linker that cares about order, but it probably works.
}
} That works, thanks.

I've committed the fix to the svn repository.

(btw, I won't generally be posting resolutions of include-what-you-use
bugs to this mailing list after this, since many readers probably
don't care. But include-what-you-use@googlegroups.com will continue
to hold all the gory details!)

craig