Iceiceice:iwyu notes

From The Battle for Wesnoth Wiki

https://code.google.com/p/include-what-you-use/wiki/WhyIWYU

Notes on how I configured and installed the include-what-you-use tool:

First, install the debian package

sudo apt-get install iwyu


Now can try it, but problems ensue:

 chris@chris-KLR650 ~/wesnoth-src/clone/wesnoth $ iwyu -o build/release/ai/configuration.o -c -std=c++98 -pthread -W -Wall -Werror -Wno-unused-local-typedefs -Qunused-arguments -Wno-unknown-warning-option -O2 -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_LIBDBUS -DHAVE_CONFIG_H -D_X11 -Ibuild -Isrc -I/usr/include/SDL -I/usr/include -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/fribidi src/ai/configuration.cpp
 In file included from src/ai/configuration.cpp:21:
 In file included from src/ai/configuration.hpp:23:
 In file included from src/ai/../config.hpp:34:
 In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/iosfwd:40:
 In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/postypes.h:40:
 In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cwchar:44:
 /usr/include/wchar.h:39:11: fatal error: 'stdarg.h' file not found
 # include <stdarg.h>
           ^

Helpful reading: https://code.google.com/p/include-what-you-use/issues/detail?id=100 http://clang-developers.42468.n3.nabble.com/Standalone-tools-td4039043.html http://clang.llvm.org/docs/LibTooling.html#builtin-includes


New plan: install llvm 3.3

Installed llvm-3.3-dev

Doesn't work.

Verbose output:

 chris@chris-KLR650 ~/wesnoth-src/clone/wesnoth $ iwyu -o build/release/ai/configuration.o -c -std=c++98 -pthread -W -Wall -Werror -Wno-unused-local-typedefs -Qunused-arguments -Wno-unknown-warning-option -O2 -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_LIBDBUS -DHAVE_CONFIG_H -D_X11 -Ibuild -Isrc -I/usr/include/SDL -I/usr/include -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/fribidi src/ai/configuration.cpp -v
 Ubuntu clang version 3.3-16ubuntu1 (branches/release_33) (based on LLVM 3.3)
 Target: x86_64-pc-linux-gnu
 Thread model: posix
 clang invocation:
  "/usr/bin/include-what-you-use" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-main-file-name" "configuration.cpp" "-mrelocation-model" "static" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-target-linker-version" "2.24" "-momit-leaf-frame-pointer" "-v" "-resource-dir" "/usr/bin/../lib/clang/3.3" "-D" "_GNU_SOURCE=1" "-D" "_REENTRANT" "-D" "HAVE_LIBDBUS" "-D" "HAVE_CONFIG_H" "-D" "_X11" "-I" "build" "-I" "src" "-I" "/usr/include/SDL" "-I" "/usr/include" "-I" "/usr/include/pango-1.0" "-I" "/usr/include/cairo" "-I" "/usr/include/glib-2.0" "-I" "/usr/lib/x86_64-linux-gnu/glib-2.0/include" "-I" "/usr/include/pixman-1" "-I" "/usr/include/freetype2" "-I" "/usr/include/libpng12" "-I" "/usr/include/dbus-1.0" "-I" "/usr/lib/x86_64-linux-gnu/dbus-1.0/include" "-I" "/usr/include/fribidi" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/x86_64-linux-gnu" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/bin/../lib/clang/3.3/include" "-internal-isystem" "/usr/include/clang/3.3/include/" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/usr/include" "-O2" "-W" "-Wall" "-Werror" "-Wno-unused-local-typedefs" "-Wno-unknown-warning-option" "-std=c++98" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/chris/wesnoth-src/clone/wesnoth" "-ferror-limit" "19" "-fmessage-length" "141" "-pthread" "-mstackrealign" "-fobjc-runtime=gcc" "-fobjc-default-synthesize-properties" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-backend-option" "-vectorize-loops" "-x" "c++" "src/ai/configuration.cpp"
 clang -cc1 version 3.3 based upon LLVM 3.3 default target x86_64-pc-linux-gnu
 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/x86_64-linux-gnu"
 ignoring nonexistent directory "/usr/bin/../lib/clang/3.3/include"
 ignoring nonexistent directory "/usr/include/clang/3.3/include/"
 ignoring duplicate directory "/usr/include/x86_64-linux-gnu"
 ignoring duplicate directory "/usr/include"
   as it is a non-system directory that duplicates a system directory
 #include "..." search starts here:
 #include <...> search starts here:
  build
  src
  /usr/include/SDL
  /usr/include/pango-1.0
  /usr/include/cairo
  /usr/include/glib-2.0
  /usr/lib/x86_64-linux-gnu/glib-2.0/include
  /usr/include/pixman-1
  /usr/include/freetype2
  /usr/include/libpng12
  /usr/include/dbus-1.0
  /usr/lib/x86_64-linux-gnu/dbus-1.0/include
  /usr/include/fribidi
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8
  /usr/local/include
  /usr/include/x86_64-linux-gnu
  /usr/include
 End of search list.
 In file included from src/ai/configuration.cpp:21:
 In file included from src/ai/configuration.hpp:23:
 In file included from src/ai/../config.hpp:34:
 In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/iosfwd:40:
 In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/postypes.h:40:
 In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cwchar:44:

/usr/include/wchar.h:39:11: fatal error: 'stdarg.h' file not found

 # include <stdarg.h>
           ^
 src/ai/configuration.hpp should add these lines:
 #include <map>                          // for map, map<>::value_compare
 #include <string>                       // for string, operator<
 #include <vector>                       // for vector
 
 src/ai/configuration.hpp should remove these lines:
 
 The full include-list for src/ai/configuration.hpp:
 #include <map>                          // for map, map<>::value_compare
 #include <string>                       // for string, operator<
 #include <vector>                       // for vector
 #include "../config.hpp"                // for config, etc
 #include "game_info.hpp"                // for side_number
 ---
 src/ai/configuration.cpp should add these lines:
 #include <boost/mpl/bool.hpp>           // for bool_
 #include <boost/mpl/bool_fwd.hpp>       // for false_
 #include <ostream>                      // for operator<<, basic_ostream, etc
 #include <utility>                      // for pair
 #include "ai/../config.hpp"             // for config, operator<<, etc
 #include "ai/game_info.hpp"             // for side_number
 
 src/ai/configuration.cpp should remove these lines:
 - #include "../serialization/parser.hpp"  // lines 25-25
 - #include "../serialization/preprocessor.hpp"  // lines 26-26
 - #include "../team.hpp"  // lines 27-27
 
 The full include-list for src/ai/configuration.cpp:
 #include "configuration.hpp"
 #include <boost/foreach.hpp>            // for auto_any_base, etc
 #include <boost/mpl/bool.hpp>           // for bool_
 #include <boost/mpl/bool_fwd.hpp>       // for false_
 #include <ostream>                      // for operator<<, basic_ostream, etc
 #include <utility>                      // for pair
 #include <vector>                       // for vector
 #include "../filesystem.hpp"            // for scoped_istream
 #include "../log.hpp"                   // for LOG_STREAM, logger, etc
 #include "ai/../config.hpp"             // for config, operator<<, etc
 #include "ai/game_info.hpp"             // for side_number
 #include "wml_exception.hpp"            // for deprecate_wml_key_warning
 ---
 

New plan: put a sym link, usr/include/clang/3.3/include to usr/include/clang/3.4/include

Success!

now take a build log from scons, strip out the lib operations and replace clang++ with iywu. Label as a bash script, and pipe it's output to a log. (It doesn't matter if it has errors.)

Then take the fix_includes.py file, from iwyu-trunk (get from their svn), and move it to wesnoth root, and pipe into it, the output of iwyu.

The result won't compile, but can fix it up with sed scripts like the following:

 chris@chris-KLR650 ~/wesnoth-src/clone/wesnoth/src $ find . -type f -exec sed -i 's/\#include <boost\/smart_ptr\/shared_ptr\.hpp>/\#include <boost\/shared_ptr\.hpp> \/\/ #IWYU pragma: keep/g' '{}' \;
 chris@chris-KLR650 ~/wesnoth-src/clone/wesnoth/src $ find . -type f -exec sed -i 's/\#include <boost\/smart_ptr\/scoped_ptr\.hpp>/\#include <boost\/scoped_ptr\.hpp> \/\/ #IWYU pragma: keep/g' '{}' \;
 chris@chris-KLR650 ~/wesnoth-src/clone/wesnoth/src $ find . -type f -exec sed -i 's/\#include <boost\/smart_ptr\/detail\/operator_bool\.hpp>//g' '{}' \;
 chris@chris-KLR650 ~/wesnoth-src/clone/wesnoth/src $


Later ....

It seems like the best way to use the pragma is to go in and actually modify your boost library files:

 chris@chris-KLR650 /usr/include/boost $ sudo pico bind.hpp
 [sudo] password for chris: 
 chris@chris-KLR650 /usr/include/boost $ sudo pico function.hpp
 chris@chris-KLR650 /usr/include/boost $ sudo pico shared_ptr.hpp
 chris@chris-KLR650 /usr/include/boost $ sudo pico intrusive_ptr.hpp 
 chris@chris-KLR650 /usr/include/boost $ sudo pico preprocessor.hpp
 chris@chris-KLR650 /usr/include/boost $ sudo pico scoped_ptr.hpp 
 chris@chris-KLR650 /usr/include/boost $ sudo pico weak_ptr.hpp 
 chris@chris-KLR650 /usr/include/boost $ sudo pico unordered_map.hpp 
 chris@chris-KLR650 /usr/include/boost $ 

putting // IWYU #pragma export at each of the includes in these files.

Also: in gettext.hpp, put a similar export before libintl.h in unit_ptr.hpp, put a // IWYU #pragma keep on the include there of intrusive_ptr

Also: follow here https://code.google.com/p/include-what-you-use/wiki/IWYUPragmas and modify in the boost subdirectories as well

This page was last edited on 20 June 2014, at 06:50.