Go to file
Volodymyr Sapsai ca5bef8272 Collect Boost and Qt mappings created by Scott Howard aka @maqifrnswa. 2015-09-09 22:42:52 -07:00
docs Rename all docs to .md 2015-08-23 21:10:02 +02:00
more_tests Fixed file heading comments not matching the filename (issue #83). Patch by Ryan Pavlik. 2012-11-25 22:09:37 +00:00
tests Allow size_t from multiple headers. 2015-06-24 17:00:49 -04:00
.clang-format Disallow short block collapsing in .clang-format. Typical style seems to be hanging indent for one-line ifs and many debuggers can't set breakpoints on indivudual statements in one-liners. 2014-06-08 09:03:52 +00:00
CMakeLists.txt Update to reflect changes in LLVM. 2015-08-19 22:58:56 -07:00
LICENSE.TXT Add a test to protect against syntax errors in main(). Also 2011-04-13 03:11:35 +00:00
Makefile Handle --version option (issue #106). 2014-02-23 00:31:52 +00:00
README.md Rewrite relative links so they can be followed on GitHub. 2015-09-02 22:35:48 +02:00
boost-all-private.imp Collect Boost and Qt mappings created by Scott Howard aka @maqifrnswa. 2015-09-09 22:42:52 -07:00
boost-all.imp Collect Boost and Qt mappings created by Scott Howard aka @maqifrnswa. 2015-09-09 22:42:52 -07:00
dist.sh Add shebang line and specify error handling options in dist.sh script. 2013-10-20 17:43:09 +00:00
fix_includes.py Change shebang so that python is picked up from the PATH. 2015-05-11 20:39:32 +00:00
fix_includes_test.py Change shebang so that python is picked up from the PATH. 2015-05-11 20:39:32 +00:00
gcc.libc.imp Specify public STL headers explicitly (issue #132). 2014-09-28 17:54:48 +00:00
gcc.stl.headers.imp Fix issue #88: GCC header map lists some private headers as public 2013-02-18 21:06:08 +00:00
gcc.symbols.imp Allow size_t from multiple headers. 2015-06-24 17:00:49 -04:00
iwyu.cc Remove some more unnecessary uses of FullSourceLoc. 2015-03-02 19:54:28 +00:00
iwyu.gcc.imp Specify public STL headers explicitly (issue #132). 2014-09-28 17:54:48 +00:00
iwyu_ast_util.cc Fix issue 129: Unused templates are ignored on Windows 2014-08-20 19:48:06 +00:00
iwyu_ast_util.h Fix issue 129: Unused templates are ignored on Windows 2014-08-20 19:48:06 +00:00
iwyu_cache.cc Handle precomputed template arguments in libc++ like in libstdc++ (issue #132). 2014-09-07 01:04:27 +00:00
iwyu_cache.h A few small fixes to get the build working. 2011-05-04 20:52:23 +00:00
iwyu_driver.cc Clang in cl-mode now supports -fsyntax-only. 2015-07-23 18:43:25 +02:00
iwyu_driver.h Fix license header for iwyu_driver.cc. 2013-08-04 08:57:25 +00:00
iwyu_getopt.cc Added getopt_long for Windows (resolves issue #52). 2012-08-11 18:15:00 +00:00
iwyu_getopt.h Added getopt_long for Windows (resolves issue #52). 2012-08-11 18:15:00 +00:00
iwyu_globals.cc Fix issue 181: Align why comments to any width 2015-04-25 09:20:21 +00:00
iwyu_globals.h Fix issue 181: Align why comments to any width 2015-04-25 09:20:21 +00:00
iwyu_include_picker.cc Allow size_t from multiple headers. 2015-06-24 17:00:49 -04:00
iwyu_include_picker.h Specify public STL headers explicitly (issue #132). 2014-09-28 17:54:48 +00:00
iwyu_lexer_utils.cc Introduce CHECK_UNREACHABLE_("message") instead of CHECK_(false && "message"). 2013-12-31 15:38:47 +00:00
iwyu_lexer_utils.h Include-what-you-use fixit -- run iwyu on itself to fix up includes (part 2). 2011-05-04 18:32:59 +00:00
iwyu_location_util.cc Simplify handling include filename location in macro. 2012-12-02 21:50:10 +00:00
iwyu_location_util.h Remove some more unnecessary uses of FullSourceLoc. 2015-03-02 19:54:28 +00:00
iwyu_output.cc Address review comments. 2015-08-06 11:54:42 +02:00
iwyu_output.h Fix issue 157: Return different exit codes. 2014-11-30 09:26:43 +00:00
iwyu_path_util.cc Update to reflect changes in LLVM (issue #149). 2014-06-13 16:36:34 +00:00
iwyu_path_util.h Remove unused function GetCWD 2013-03-19 20:53:26 +00:00
iwyu_preprocessor.cc Update to reflect changes in Clang. 2015-05-06 07:56:27 +00:00
iwyu_preprocessor.h Assume override keyword support. 2015-07-14 22:19:13 +02:00
iwyu_stl_util.h iwyu was egregiously wrong in how it handled template 2011-08-31 11:42:23 +00:00
iwyu_string_util.h Address review comments. 2015-08-05 12:14:52 +02:00
iwyu_test_util.py Update shebangs to find Python in PATH. 2015-08-04 10:56:23 +02:00
iwyu_tool.py Add svn:executable on iwyu_tool.py. 2015-03-02 20:21:54 +00:00
iwyu_verrs.cc Fixed file heading comments not matching the filename (issue #83). Patch by Ryan Pavlik. 2012-11-25 22:09:37 +00:00
iwyu_verrs.h Fixed file heading comments not matching the filename (issue #83). Patch by Ryan Pavlik. 2012-11-25 22:09:37 +00:00
iwyu_version.h Bump version to 0.5 on trunk. 2015-05-26 20:04:38 +00:00
make_readme.py Rewrite relative links so they can be followed on GitHub. 2015-09-02 22:35:48 +02:00
port.h Assume override keyword support. 2015-07-14 22:19:13 +02:00
qt4.imp Collect Boost and Qt mappings created by Scott Howard aka @maqifrnswa. 2015-09-09 22:42:52 -07:00
run_iwyu_tests.py Resolve merge conflict 2015-08-05 10:57:56 +02:00
stl.c.headers.imp Specify public STL headers explicitly (issue #132). 2014-09-28 17:54:48 +00:00
third_party.imp Read private to public mappings from external file. Patch by Kim Gräsman. 2012-10-14 22:39:30 +00:00

README.md

Include What You Use

This README was generated on 2015-09-02 20:35:20 UTC.

For more in-depth documentation, see http://github.com/include-what-you-use/include-what-you-use/tree/master/docs.

Instructions for Users

"Include what you use" means this: for every symbol (type, function, variable, or macro) that you use in foo.cc (or foo.cpp), either foo.cc or foo.h should include a .h file that exports the declaration of that symbol. (Similarly, for foo_test.cc, either foo_test.cc or foo.h should do the including.) Obviously symbols defined in foo.cc itself are excluded from this requirement.

This puts us in a state where every file includes the headers it needs to declare the symbols that it uses. When every file includes what it uses, then it is possible to edit any file and remove unused headers, without fear of accidentally breaking the upwards dependencies of that file. It also becomes easy to automatically track and update dependencies in the source code.

CAVEAT

This is alpha quality software -- at best (as of February 2011). It was written to work specifically in the Google source tree, and may make assumptions, or have gaps, that are immediately and embarrassingly evident in other types of code. For instance, we only run this on C++ code, not C or Objective C. Even for Google code, the tool still makes a lot of mistakes.

While we work to get IWYU quality up, we will be stinting new features, and will prioritize reported bugs along with the many existing, known bugs. The best chance of getting a problem fixed is to submit a patch that fixes it (along with a unittest case that verifies the fix)!

How to Build

Include-what-you-use makes heavy use of Clang internals, and will occasionally break when Clang is updated. See the include-what-you-use Makefile for instructions on how to keep them in sync.

We support two build configurations: out-of-tree and in-tree.

Building out-of-tree

In an out-of-tree configuration, we assume you already have compiled LLVM and Clang headers and libs somewhere on your filesystem, such as via the libclang-dev package. Out-of-tree builds are only supported with CMake (patches very welcome for the Make system).

  • Create a directory for IWYU development, e.g. iwyu-trunk

  • Clone the IWYU Git repo:

    iwyu-trunk$ git clone https://github.com/include-what-you-use/include-what-you-use.git
    
  • Presumably, you'll be building IWYU with a released version of LLVM and Clang, so check out the corresponding branch. For example if you have Clang 3.2 installed, use the clang_3.2 branch. IWYU master tracks LLVM & Clang trunk:

    iwyu-trunk$ cd include-what-you-use
    iwyu-trunk/include-what-you-use$ git checkout clang_3.2
    iwyu-trunk/include-what-you-use$ cd ..
    
  • Create a build root and use CMake to generate a build system linked with LLVM/Clang prebuilts, e.g.

    # This example uses the Makefile generator, but anything should work.
    iwyu-trunk$ mkdir build && cd build
    iwyu-trunk/build$ cmake -G "Unix Makefiles" -DIWYU_LLVM_ROOT_PATH=/usr/lib/llvm-3.4 ../include-what-you-use
    
  • Once CMake has generated a build system, you can invoke it directly from build, e.g.

    iwyu-trunk/build$ make
    

This configuration is more useful if you want to get IWYU up and running quickly without building Clang and LLVM from scratch.

Building in-tree

You will need the Clang and LLVM trees on your system, such as by checking out their SVN trees (but don't configure or build before you've done the following.)

  • Clone the IWYU Git repo into the Clang source tree:

    llvm/tools/clang/tools$ git clone https://github.com/include-what-you-use/include-what-you-use.git
    
  • Edit tools/clang/tools/Makefile and add include-what-you-use to the DIRS variable

  • Edit tools/clang/tools/CMakeLists.txt and put in add_subdirectory(include-what-you-use)

  • Once this is done, IWYU is recognized and picked up by both autoconf and CMake workflows as described in the Clang Getting Started guide

This configuration is more useful if you're actively developing IWYU against Clang trunk. It's easier to set up correctly, but it requires that you build all of LLVM and Clang.

How to Install

If you're building IWYU out-of-tree or installing pre-built binaries, you need to make sure it can find Clang built-in headers (stdarg.h and friends.)

Clang's default policy is to look in path/to/clang-executable/../lib/clang/<clang ver>/include. So if Clang 3.5.0 is installed in /usr/bin, it will search for built-ins in /usr/lib/clang/3.5.0/include.

Clang tools have the same policy by default, so in order for IWYU to analyze any non-trivial code, it needs to find Clang's built-ins in path/to/iwyu/../lib/clang/3.5.0/include where 3.5.0 is a stand-in for the version of Clang your IWYU was built against.

So for IWYU to function correctly, you need to copy in the Clang headers at a good location before running.

This weirdness is tracked in issue 100, hopefully we can make this more transparent over time.

How to Run

The easiest way to run IWYU over your codebase is to run

  make -k CXX=/path/to/llvm/Debug+Asserts/bin/include-what-you-use

or

  make -k CXX=/path/to/llvm/Release/bin/include-what-you-use

(include-what-you-use always exits with an error code, so the build system knows it didn't build a .o file. Hence the need for -k.)

Include-what-you-use only analyzes .cc (or .cpp) files built by make, along with their corresponding .h files. If your project has a .h file with no corresponding .cc file, IWYU will ignore it unless you use the --check_also switch to add it for analysis together with a .cc file.

We also include, in this directory, a tool that automatically fixes up your source files based on the IWYU recommendations. This is also alpha-quality software! Here's how to use it (requires python):

  make -k CXX=/path/to/llvm/Debug+Asserts/bin/include-what-you-use > /tmp/iwyu.out
  python fix_includes.py < /tmp/iwyu.out

If you don't like the way fix_includes.py munges your #include lines, you can control its behavior via flags. fix_includes.py --help will give a full list, but these are some common ones:

  • -b: Put blank lines between system and Google includes
  • --nocomments: Don't add the 'why' comments next to includes

How to Correct IWYU Mistakes

  • If fix_includes.py has removed an #include you actually need, add it back in with the comment '// IWYU pragma: keep' at the end of the #include line. Note that the comment is case-sensitive.
  • If fix_includes.py has added an #include you don't need, just take it out. We hope to come up with a more permanent way of fixing later.
  • If fix_includes.py has wrongly added or removed a forward-declare, just fix it up manually.
  • If fix_includes.py has suggested a private header file (such as <bits/stl_vector.h>) instead of the proper public header file (<vector>), you can fix this by inserting a specially crafted comment near top of the private file (assuming you can write to it): '// IWYU pragma: private, include "the/public/file.h"'.

Current IWYU pragmas are described in IWYUPragmas.