libshit

Just some random shit
git clone https://git.neptards.moe/neptards/libshit.git
Log | Files | Refs | Submodules | README | LICENSE

iwyu.sh (2666B)


      1 #! /bin/bash
      2 
      3 if [[ $# < 1 ]]; then
      4     echo "Usage: $0 [--accept] file [extra clang args...]" >&2
      5     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
      6     exit 255
      7 fi
      8 
      9 dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
     10 build_dir="${build_dir-$dir/build}"
     11 base_dir="${base_dir-$dir}"
     12 base_dir_escaped="$(sed 's/[[*?\]/\\\0/g' <<<"$base_dir")"
     13 
     14 accept=false
     15 verbose=false
     16 comments=false
     17 
     18 while [[ $1 == -* ]]; do
     19     if [[ $1 == -a || $1 == --accept ]]; then
     20         accept=true
     21     elif [[ $1 == -v || $1 == --verbose ]]; then
     22         verbose=true
     23     elif [[ $1 == --comments ]]; then
     24         comments=true
     25     else
     26         echo "Unknown argument $1" >&2
     27         exit 1
     28     fi
     29     shift
     30 done
     31 
     32 if [[ $1 == *.[ch]pp ]]; then
     33     flags+=(
     34         -std=c++17
     35         -nostdinc++
     36         -isystem "$dir/ext/libcxx/libcxx/include"
     37         -isystem "$dir/ext/libcxx/libcxxabi/include"
     38         -D_LIBCPP_NO_CONFIG
     39     )
     40 else
     41     flags+=(-std=c11)
     42 fi
     43 
     44 flags+=(
     45     -Xiwyu --mapping_file="$dir/iwyu.imp"
     46     -Xiwyu --max_line_length=200
     47     -Xiwyu --cxx17ns
     48     -Xiwyu --keep='*.binding.hpp'
     49     -DLIBSHIT_INSIDE_IWYU=1
     50     -I"$dir/src"
     51     -I"$build_dir/src"
     52     -I"$build_dir/test"
     53     -I"$dir/../build/clang-debug/libshit/src"
     54     -I"$dir/../build/libshit/src"
     55     -isystem "$dir/ext/boost/boost"
     56     -isystem "$dir/ext/doctest/doctest/doctest"
     57     -isystem "$dir/ext/lua/lua-5.3.6/src"
     58     -isystem "$dir/ext/tracy/tracy/public"
     59     -isystem "$dir/misc/yaml-cpp/include" # ci
     60     -Wno-parentheses -Wno-dangling-else -Werror=undef
     61     -DLIBSHIT_WITH_ABORT_WRAP=1
     62     -DLIBSHIT_WITH_LIBBACKTRACE=0
     63     -DLIBSHIT_WITH_LUA=1
     64     -DLIBSHIT_WITH_MEMCHECK=0
     65     -DLIBSHIT_WITH_TESTS=1
     66     -DLIBSHIT_WITH_TRACY=1
     67     -DLIBSHIT_TRANSLATE_DUMP=1
     68     -DLIBSHIT_TRANSLATE_YAML=1
     69 )
     70 
     71 $comments || flags+=(-Xiwyu --no_comments)
     72 $verbose && flags+=(-Xiwyu --verbose=3)
     73 
     74 file="${1%.iwyu_out}"
     75 shift
     76 
     77 [[ $file == *.binding.hpp ]] && exit 0
     78 
     79 succ=false
     80 out="$($verbose && set -x; include-what-you-use "${flags[@]}" "$file" "$@" 2>&1)"
     81 $verbose && cat <<<"$out"
     82 
     83 [[ $? -eq 2 ]] && succ=true
     84 tail -n1 <<<"$out" | grep -q 'has correct #includes/fwd-decls)' && succ=true
     85 
     86 out="${out//$base_dir_escaped\/}"
     87 if $accept; then
     88     if $succ; then
     89         rm -f "$file".iwyu_out
     90     else
     91         cat <<<"$out" > "$file".iwyu_out
     92     fi
     93     exit 0
     94 elif [[ -f "$file".iwyu_out ]]; then
     95     diff -u "$file".iwyu_out <(cat <<<"$out")
     96     [[ $? -eq 0 ]] && exit 0
     97 elif $succ; then
     98     exit 0
     99 fi
    100 
    101 echo -e '\033[33m'"$file"' output\033[0m'
    102 cat <<<"$out"
    103 echo -e '\033[31;1m'"$file"' failed\033[0m'
    104 exit 1