diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-04-20 23:00:54 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-04-26 15:02:22 -0700 |
commit | 1f06e5f0b9ee483053b987c9cab9f1f5fce2590c (patch) | |
tree | 8ebebff055f4aa184e7d7b021190ab01d9376992 /build_tools | |
parent | daa217f533490e0b9bc4113a143e8f38de922b7a (diff) |
add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.
Fixes #2957
Diffstat (limited to 'build_tools')
-rw-r--r-- | build_tools/iwyu.linux.imp | 17 | ||||
-rw-r--r-- | build_tools/iwyu.osx.imp | 97 | ||||
-rwxr-xr-x | build_tools/lint.fish | 52 |
3 files changed, 157 insertions, 9 deletions
diff --git a/build_tools/iwyu.linux.imp b/build_tools/iwyu.linux.imp new file mode 100644 index 00000000..6fc614ae --- /dev/null +++ b/build_tools/iwyu.linux.imp @@ -0,0 +1,17 @@ +# Map file for the include-what-you-use tool on Linux. +[ + { include: ["<bits/fcntl-linux.h>", "private", "<fcntl.h>", "public"] }, + { include: ["<bits/mman-linux.h>", "private", "<sys/mman.h>", "public"] }, + { include: ["<bits/socket-linux.h>", "private", "<sys/socket.h>", "public"] }, + { include: ["<bits/socket_type.h>", "private", "<sys/socket.h>", "public"] }, + { include: ["<bits/local_lim.h>", "private", "<limits.h>", "public"] }, + { include: ["<tr1/memory>", "public", "<memory>", "public"] }, + { include: ["<features.h>", "public", "<stdio.h>", "public"] }, + { include: ["<features.h>", "public", "<stddef.h>", "public"] }, + { include: ["<features.h>", "public", "<unistd.h>", "public"] }, + + { symbol: ["size_t", "private", "<unistd.h>", "public"] }, + { symbol: ["size_t", "private", "<stddef.h>", "public"] }, + { symbol: ["size_t", "private", "<stdlib.h>", "public"] }, + { symbol: ["uint64_t", "private", "<sys/types.h>", "public"] }, +] diff --git a/build_tools/iwyu.osx.imp b/build_tools/iwyu.osx.imp new file mode 100644 index 00000000..cad467cd --- /dev/null +++ b/build_tools/iwyu.osx.imp @@ -0,0 +1,97 @@ +# Map file for the include-what-you-use tool on OS X. For some reason +# the version installed by HomeBrew doesn't have useful mappings for the +# system provided private headers. +[ + { include: ["<sys/_pthread/_pthread_once_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_pthread/_pthread_mutex_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_pthread/_pthread_rwlock_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_pthread/_pthread_mutexattr_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_pthread/_pthread_cond_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_pthread/_pthread_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_pthread/_pthread_key_t.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_types/_posix_vdisable.h>", "private", "<pthread.h>", "public"] }, + { include: ["<sys/_types/_time_t.h>", "private", "<time.h>", "public"] }, + { include: ["<sys/_types/_suseconds_t.h>", "private", "<time.h>", "public"] }, + { include: ["<sys/_types/_suseconds_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/errno.h>", "private", "<errno.h>", "public"] }, + { include: ["<sys/unistd.h>", "private", "<unistd.h>", "public"] }, + { include: ["<_wctype.h>", "private", "<wctype.h>", "public"] }, + { include: ["<sys/fcntl.h>", "private", "<fcntl.h>", "public"] }, + { include: ["<sys/_types/_seek_set.h>", "private", "<fcntl.h>", "public"] }, + { include: ["<sys/_types/_mbstate_t.h>", "private", "<wchar.h>", "public"] }, + { include: ["<iosfwd>", "private", "<string>", "public"] }, + { include: ["<sys/_types/_s_ifmt.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_size_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_size_t.h>", "private", "<stdlib.h>", "public"] }, + { include: ["<sys/_types/_mode_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_pid_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_fd_def.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_fd_isset.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_fd_set.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_fd_zero.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_timeval.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_uid_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<_types/_intmax_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<_types/_uintmax_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<_types/_uint8_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_int32_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<_types/_uint64_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_uintptr_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_dev_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_ino_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_va_list.h>", "private", "<stdio.h>", "public"] }, + { include: ["<__functional_base>", "private", "<memory>", "public"] }, + { include: ["<__functional_base>", "private", "<vector>", "public"] }, + { include: ["<__functional_base>", "private", "<string>", "public"] }, + { include: ["<__tree>", "private", "<map>", "public"] }, + { include: ["<__tree>", "private", "<set>", "public"] }, + { include: ["<_types/_uint32_t.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_va_list.h>", "private", "<sys/types.h>", "public"] }, + { include: ["<sys/_types/_sigset_t.h>", "private", "<signal.h>", "public"] }, + { include: ["<sys/signal.h>", "private", "<signal.h>", "public"] }, + { include: ["<strings.h>", "private", "<string.h>", "public"] }, + { include: ["<sys/termios.h>", "private", "<termios.h>", "public"] }, + { include: ["<sys/ttycom.h>", "private", "<termios.h>", "public"] }, + { include: ["<sys/syslimits.h>", "private", "<limits.h>", "public"] }, + { include: ["<i386/limits.h>", "private", "<limits.h>", "public"] }, + { include: ["<sys/_types/_wint_t.h>", "private", "<stddef.h>", "public"] }, + { include: ["<sys/_select.h>", "private", "<select.h>", "public"] }, + { include: ["<sys/cdefs.h>", "private", "<unistd.h>", "public"] }, + { include: ["<istream>", "private", "<iostream>", "public"] }, + { include: ["<sys/_endian.h>", "private", "<netinet/in.h>", "public"] }, + { include: ["<sys/_types/_timespec.h>", "private", "<time.h>", "public"] }, + { include: ["<sys/spawn.h>", "private", "<spawn.h>", "public"] }, + { include: ["<sys/dirent.h>", "private", "<dirent.h>", "public"] }, +# { include: ["<>", "private", "<>", "public"] }, + + { symbol: ["NULL", "private", "<stddef.h>", "public"] }, + { symbol: ["NULL", "private", "<stdlib.h>", "public"] }, + { symbol: ["NULL", "private", "<stdio.h>", "public"] }, + { symbol: ["NULL", "private", "<unistd.h>", "public"] }, + { symbol: ["off_t", "private", "<unistd.h>", "public"] }, + { symbol: ["size_t", "private", "<unistd.h>", "public"] }, + { symbol: ["size_t", "private", "<stddef.h>", "public"] }, + { symbol: ["size_t", "private", "<stdlib.h>", "public"] }, + { symbol: ["off_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["size_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["ssize_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["intptr_t", "private", "<unistd.h>", "public"] }, + { symbol: ["ssize_t", "private", "<unistd.h>", "public"] }, + { symbol: ["gid_t", "private", "<unistd.h>", "public"] }, + { symbol: ["uid_t", "private", "<unistd.h>", "public"] }, + { symbol: ["pid_t", "private", "<unistd.h>", "public"] }, + { symbol: ["pid_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["uid_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["gid_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["uint32_t", "private", "<sys/types.h>", "public"] }, + { symbol: ["uint32_t", "private", "<stdint.h>", "public"] }, + { symbol: ["intptr_t", "private", "<stdint.h>", "public"] }, + { symbol: ["size_t", "private", "<stdint.h>", "public"] }, + { symbol: ["tparm", "private", "<ncurses.h>", "public"] }, + { symbol: ["ERR", "private", "<ncurses.h>", "public"] }, + { symbol: ["select", "private", "<sys/select.h>", "public"] }, + { symbol: ["_LIBCPP_VERSION", "private", "<stddef.h>", "public"] }, + { symbol: ["_LIBCPP_VERSION", "private", "<unistd.h>", "public"] }, + { symbol: ["MB_CUR_MAX", "private", "<xlocale.h>", "public"] }, + { symbol: ["MB_CUR_MAX", "private", "<stdlib.h>", "public"] }, +] diff --git a/build_tools/lint.fish b/build_tools/lint.fish index 287269da..5ac05d7d 100755 --- a/build_tools/lint.fish +++ b/build_tools/lint.fish @@ -7,6 +7,8 @@ set cppchecks warning,performance,portability,information,missingInclude set cppcheck_args set c_files set all no +set kernel_name (uname -s) +set machine_type (uname -m) set -gx CXX $argv[1] set -e argv[1] @@ -17,15 +19,27 @@ if test "$argv[1]" = "--all" set -e argv[1] end +if test $kernel_name = Linux + # This is an awful hack. However, the include-what-you-use program spews lots of errors like + # /usr/include/unistd.h:226:10: fatal error: 'stddef.h' file not found + # if we don't explicitly tell it where to find the system headers on Linux. See + # http://stackoverflow.com/questions/19642590/libtooling-cant-find-stddef-h-nor-other-headers/ + set -l sys_includes (eval $CXX -v -c src/builtin.cpp 2>&1 | \ + sed -n -e '/^#include <...> search/,/^End of search list/s/^ *//p')[2..-2] + set -x CPLUS_INCLUDE_PATH (string join ':' $sys_includes) +end + # We only want -D and -I options to be passed thru to cppcheck. for arg in $argv if string match -q -- '-D*' $arg set cppcheck_args $cppcheck_args $arg else if string match -q -- '-I*' $arg set cppcheck_args $cppcheck_args $arg + else if string match -q -- '-iquote*' $arg + set cppcheck_args $cppcheck_args $arg end end -if test (uname -m) = "x86_64" +if test "$machine_type" = "x86_64" set cppcheck_args -D__x86_64__ -D__LP64__ $cppcheck_args end @@ -37,7 +51,7 @@ else set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//') if not set -q files[1] # No pending changes so lint the files in the most recent commit. - set files (git show --word-diff=porcelain --name-only --pretty=oneline head)[2..-1] + set files (git show --word-diff=porcelain --name-only --pretty=oneline)[2..-1] end # Extract just the C/C++ files. @@ -46,6 +60,26 @@ end # We now have a list of files to check so run the linters. if set -q c_files[1] + if type -q iwyu + # The stderr to stdout redirection is because cppcheck, incorrectly IMHO, writes its + # diagnostic messages to stderr. Anyone running this who wants to capture its output will + # expect those messages to be written to stdout. + for c_file in $c_files + echo + echo ======================================== + echo Running IWYU on $c_file + echo ======================================== + switch $kernel_name + case Darwin + include-what-you-use -Xiwyu --no_default_mappings -Xiwyu --mapping_file=build_tools/iwyu.osx.imp $cppcheck_args $c_file 2>&1 + case Linux + include-what-you-use -Xiwyu --mapping_file=build_tools/iwyu.linux.imp $cppcheck_args $c_file 2>&1 + case '*' # hope for the best + include-what-you-use $cppcheck_args $c_file 2>&1 + end + end + end + if type -q cppcheck echo echo ======================================== @@ -54,7 +88,7 @@ if set -q c_files[1] # The stderr to stdout redirection is because cppcheck, incorrectly IMHO, writes its # diagnostic messages to stderr. Anyone running this who wants to capture its output will # expect those messages to be written to stdout. - cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks $cppcheck_args $c_files 2>& 1 + cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks $cppcheck_args $c_files 2>&1 end if type -q oclint @@ -65,25 +99,25 @@ if set -q c_files[1] # The stderr to stdout redirection is because oclint, incorrectly writes its final summary # counts of the errors detected to stderr. Anyone running this who wants to capture its # output will expect those messages to be written to stdout. - if test (uname -s) = "Darwin" + if test "$kernel_name" = "Darwin" if not test -f compile_commands.json - xcodebuild > xcodebuild.log - oclint-xcodebuild xcodebuild.log > /dev/null + xcodebuild >xcodebuild.log + oclint-xcodebuild xcodebuild.log >/dev/null end if test $all = yes - oclint-json-compilation-database -e '/pcre2-10.21/' -- -enable-global-analysis 2>& 1 + oclint-json-compilation-database -e '/pcre2-10.21/' -- -enable-global-analysis 2>&1 else set i_files for f in $c_files set i_files $i_files -i $f end echo oclint-json-compilation-database -e '/pcre2-10.21/' $i_files - oclint-json-compilation-database -e '/pcre2-10.21/' $i_files 2>& 1 + oclint-json-compilation-database -e '/pcre2-10.21/' $i_files 2>&1 end else # Presumably we're on Linux or other platform not requiring special # handling for oclint to work. - oclint $c_files -- $argv 2>& 1 + oclint $c_files -- $argv 2>&1 end end else |