-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-build.sh
executable file
·196 lines (174 loc) · 4.51 KB
/
test-build.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
set -euf
srcdir="$(cd -- "${0%/*}/" && pwd -P)"
cd -- "$srcdir"
if [ -d .git ]; then
git clean -xdf
else
rm -rf build
fi
exists () {
r=0; cwd="$(pwd)"
while [ $# -gt 0 ]; do
v=1; arg="$1"; shift
case "$arg" in
''|*/ )
:
;;
/* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
printf %s\\n "$arg"
v=0
fi
;;
./* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
pre="$(cd -- "${arg%%/*}/" && pwd)"
printf %s\\n "${pre%/}/$arg"
v=0
fi
;;
*/* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
printf %s\\n "$(cd -- "${arg%%/*}/.." && pwd)/$arg"
v=0
fi
;;
* )
if [ -n "${PATH+x}" ]; then
p=":${PATH:-$cwd}"
while [ "$p" != "${p#*:}" ] && [ -n "${p#*:}" ]; do
p="${p#*:}"; x="${p%%:*}"; z="${x:-$cwd}"; d="${z%/}/$arg"
if [ -f "$d" ] && [ -x "$d" ]; then
case "$d" in
/* ) : ;;
./* ) pre="$(cd -- "${d%/*}/" && pwd)"; d="${pre%/}/$d" ;;
* ) d="$(cd -- "${d%/*}/" && pwd)/$arg" ;;
esac
printf %s\\n "$d"
v=0
break
fi
done
fi
;;
esac
[ $v = 0 ] || r=1
done
return $r
}
check=
while [ $# -gt 0 ]; do
check="${check} $1"
shift
done
if exists doxygen >/dev/null 2>&1; then
doc='--enable-doc'
else
printf %s\\n 'WARNING: Building without doxygen' >&2
doc=
fi
autoreconf -fi
compiler='cc clang gcc'
eval "set -- $compiler"
for cc do
confdir="build/configure/$cc"
mkdir -p -- "$confdir"
(
cd -- "$confdir"/
printf %s\\n '' "Configuring for $cc" ''
CC="$cc" "$srcdir"/configure $doc
)
done
build () {
test="${1:-default}"
cflags="${2:-}"
rm -rf -- build/"$test"
mkdir -p -- build/"$test"
eval "set -- $compiler"
for cc do
if check_asan "$test" "$cc" "$musl"; then
eval "set -- $standard"
for std do
cpp=
libs=
if check_cxx "$std"; then
cpp='-xc++'
libs='-lstdc++'
fi
# TODO: Add -Ofast
for optimization in '' -O1 -O2 -O3 -O0 -Os -Og; do
build_string="$(printf %s "$std" | tr = _ | tr -d '[:space:]')"
dir="build/${test}/${cc}${optimization}${build_string}"
rm -rf -- "$dir"
cp -r -- build/configure/"$cc" "$dir"
(
cd -- "$dir"/
print_flags="${std} ${optimization}"
build_flags="$(printf %s "${print_flags}" | sed 's/-xc++//')"
all_flags="${build_flags} ${_CFLAGS} ${cflags}"
printf %s\\n '' "Building ${cc} ${print_flags}: ${test}" ''
make install V=1 CFLAGS="$all_flags" CPPFLAGS="$cpp" LDFLAGS="$libs" \
DESTDIR="$srcdir/$dir"/install
make check V=1 CFLAGS="$all_flags" CPPFLAGS="$cpp" LDFLAGS="$libs"
)
done
done
fi
done
}
check_asan () {
case "$1" in
*san )
# TODO: sanitizers are disabled with clang and musl
if [ "$2" = 'clang' ] || [ -n "${3}" ]; then
return 1
fi
;;
esac
return 0
}
check_cxx () {
case "$1" in
*c++* ) return 0 ;;
* ) return 1 ;;
esac
}
if ldd "$(exists ls)" | grep -q musl; then
printf %s\\n 'WARNING: Skipping the sanitizer tests on musl systems' >&2
musl='1'
else
musl=
fi
###########
## Tests ##
###########
_CFLAGS='-Werror -Wall -Wextra'
_CFLAGS_ASAN='-g -fno-omit-frame-pointer'
standard=
all_std='default c90 c99 c11 c17 c2x c++ c++98 c++11 c++14 c++17 c++20 c++23'
for i in $(printf %s "${all_std}"); do
case "$i" in
c[0-9]* ) standard="${standard} -std=$i -std=gnu${i#?}" ;;
c++ ) standard="${standard} -x$i" ;;
c++* ) standard="${standard} '-xc++ -std=$i' '-xc++ -std=gnu${i#?}'" ;;
default ) standard="${standard} ''" ;;
* ) printf %s\\n "ERROR: Unknown '$i' standard." >&2; exit 1 ;;
esac
done
if [ -z "${check}" ]; then
# TODO: Indeterminate non-reproducible failures with lsan
check='default ansi lto asan tsan ubsan'
fi
for i in $(printf %s "${check}"); do
case "$i" in
ansi ) build "$i" '-ansi' ;;
lto ) build "$i" '-flto' ;;
asan ) build "$i" "${_CFLAGS_ASAN} -fsanitize=address" ;;
lsan ) build "$i" "${_CFLAGS_ASAN} -fsanitize=leak" ;;
tsan ) build "$i" "${_CFLAGS_ASAN} -fsanitize=thread" ;;
ubsan ) build "$i" "${_CFLAGS_ASAN} -fsanitize=undefined" ;;
default ) build ;;
* ) printf %s\\n "ERROR: Unknown '$i' test." >&2; exit 1 ;;
esac
done