You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.6 KiB
Bash
105 lines
2.6 KiB
Bash
#! /bin/bash
|
|
|
|
if [[ $# < 1 ]]; then
|
|
echo "Usage: $0 [--accept] file [extra clang args...]" >&2
|
|
echo "Check all files: find src test \( -name '*.[ch]' -o -name '*.[ch]pp' \) -print0 | nice xargs -0P$(grep -c ^processor /proc/cpuinfo) -n1 $0" >&2
|
|
exit 255
|
|
fi
|
|
|
|
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
build_dir="${build_dir-$dir/build}"
|
|
base_dir="${base_dir-$dir}"
|
|
base_dir_escaped="$(sed 's/[[*?\]/\\\0/g' <<<"$base_dir")"
|
|
|
|
accept=false
|
|
verbose=false
|
|
comments=false
|
|
|
|
while [[ $1 == -* ]]; do
|
|
if [[ $1 == -a || $1 == --accept ]]; then
|
|
accept=true
|
|
elif [[ $1 == -v || $1 == --verbose ]]; then
|
|
verbose=true
|
|
elif [[ $1 == --comments ]]; then
|
|
comments=true
|
|
else
|
|
echo "Unknown argument $1" >&2
|
|
exit 1
|
|
fi
|
|
shift
|
|
done
|
|
|
|
if [[ $1 == *.[ch]pp ]]; then
|
|
flags+=(
|
|
-std=c++17
|
|
-nostdinc++
|
|
-isystem "$dir/ext/libcxx/libcxx/include"
|
|
-isystem "$dir/ext/libcxx/libcxxabi/include"
|
|
-D_LIBCPP_NO_CONFIG
|
|
)
|
|
else
|
|
flags+=(-std=c11)
|
|
fi
|
|
|
|
flags+=(
|
|
-Xiwyu --mapping_file="$dir/iwyu.imp"
|
|
-Xiwyu --max_line_length=200
|
|
-Xiwyu --cxx17ns
|
|
-Xiwyu --keep='*.binding.hpp'
|
|
-DLIBSHIT_INSIDE_IWYU=1
|
|
-I"$dir/src"
|
|
-I"$build_dir/src"
|
|
-I"$build_dir/test"
|
|
-I"$dir/../build/clang-debug/libshit/src"
|
|
-I"$dir/../build/libshit/src"
|
|
-isystem "$dir/ext/boost/boost"
|
|
-isystem "$dir/ext/doctest/doctest/doctest"
|
|
-isystem "$dir/ext/lua/lua-5.3.6/src"
|
|
-isystem "$dir/ext/tracy/tracy/public"
|
|
-isystem "$dir/misc/yaml-cpp/include" # ci
|
|
-Wno-parentheses -Wno-dangling-else -Werror=undef
|
|
-DLIBSHIT_WITH_ABORT_WRAP=1
|
|
-DLIBSHIT_WITH_LIBBACKTRACE=0
|
|
-DLIBSHIT_WITH_LUA=1
|
|
-DLIBSHIT_WITH_MEMCHECK=0
|
|
-DLIBSHIT_WITH_TESTS=1
|
|
-DLIBSHIT_WITH_TRACY=1
|
|
-DLIBSHIT_TRANSLATE_DUMP=1
|
|
-DLIBSHIT_TRANSLATE_YAML=1
|
|
)
|
|
|
|
$comments || flags+=(-Xiwyu --no_comments)
|
|
$verbose && flags+=(-Xiwyu --verbose=3)
|
|
|
|
file="${1%.iwyu_out}"
|
|
shift
|
|
|
|
[[ $file == *.binding.hpp ]] && exit 0
|
|
|
|
succ=false
|
|
out="$($verbose && set -x; include-what-you-use "${flags[@]}" "$file" "$@" 2>&1)"
|
|
$verbose && cat <<<"$out"
|
|
|
|
[[ $? -eq 2 ]] && succ=true
|
|
tail -n1 <<<"$out" | grep -q 'has correct #includes/fwd-decls)' && succ=true
|
|
|
|
out="${out//$base_dir_escaped\/}"
|
|
if $accept; then
|
|
if $succ; then
|
|
rm -f "$file".iwyu_out
|
|
else
|
|
cat <<<"$out" > "$file".iwyu_out
|
|
fi
|
|
exit 0
|
|
elif [[ -f "$file".iwyu_out ]]; then
|
|
diff -u "$file".iwyu_out <(cat <<<"$out")
|
|
[[ $? -eq 0 ]] && exit 0
|
|
elif $succ; then
|
|
exit 0
|
|
fi
|
|
|
|
echo -e '\033[33m'"$file"' output\033[0m'
|
|
cat <<<"$out"
|
|
echo -e '\033[31;1m'"$file"' failed\033[0m'
|
|
exit 1
|