aboutsummaryrefslogtreecommitdiffhomepage
path: root/build_tools/lint.fish
diff options
context:
space:
mode:
Diffstat (limited to 'build_tools/lint.fish')
-rwxr-xr-xbuild_tools/lint.fish52
1 files changed, 43 insertions, 9 deletions
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