-
Notifications
You must be signed in to change notification settings - Fork 0
/
iwyu.sh
executable file
·76 lines (66 loc) · 1.82 KB
/
iwyu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash -x
COMPDB="compile_commands.json"
SYMDB="find_all_symbols_db.yaml"
MAPFILE="iwyu.imp"
SYMTMP="/tmp/iwyu/"
function allSources() {
find -type f \( -name '*.[Cch]' -o -name '*.[cht]pp' -o -name '*.ut' \) -a \( ! -name '*.pb.*' \)
}
function allBodies() {
find -type f \( -name '*.[Cc]' -o -name '*.[c]pp' \) -a \( ! -name '*.pb.*' \)
}
function allIncludes() { # [prefix]
local pfx=${1}
find -type d -name include | while read d ; do
echo "-I${d}" | sed -e "s#^#${pfx}#"
done
sed -e "s#^#${pfx}#" <<- EOF
-I../../include
-I/opt/include
-I/usr/include
-I/usr/include/c++/8
-I/usr/include/c++/8/backward
-I/usr/include/x86_64-linux-gnu
-I/usr/include/x86_64-linux-gnu/c++/8
-I/usr/include/x86_64-linux-gnu/8/include
-I/usr/include/x86_64-linux-gnu/8/include-fixed
-I/usr/local/include
EOF
}
function mustMake() { # target [dependency...]
local target=${1}; shift
local dependencies="$@"
[ -f "${target}" ] || return 0
for source in ${dependencies} ; do
[ -f "${source}" ] || return 1
[ "${target}" -nt "${source}" ] || return 0
done
return 1
}
function remakeMapping() {
mustMake ${MAPFILE} || return
cat > ${MAPFILE} <<-EOF
[
{ symbol: ["std::stringstream","private","<sstream>","public"] },
]
EOF
}
function remakeCompileDB() {
mustMake ${COMPDB} || return
make distclean
make generate
CPPFLAGS="-xc++ -std=c++11" bear make quick >/dev/null 2>&1
}
function remakeSymbolsDB() {
remakeMapping
remakeCompileDB
mustMake ${SYMDB} ${COMPDB} || return
rm -rf ${SYMTMP} ; mkdir ${SYMTMP}
find-all-symbols-7 $(allIncludes -extra-arg=) -output-dir=${SYMTMP} -p=. $(allBodies)
cat ${SYMTMP}/* > find_all_symbols_db.yaml
rm -rf ${SYMTMP}
}
remakeMapping
remakeSymbolsDB
iwyu_tool -p . -- --mapping_file=iwyu.imp | fix_include --comments --noblank_lines --nosafe_headers
# vi: ft=sh ts=3 :