Skip to content

Commit 5a9c8dd

Browse files
author
Paul Dreik
committed
format shell script
1 parent b754ad6 commit 5a9c8dd

File tree

1 file changed

+138
-140
lines changed

1 file changed

+138
-140
lines changed

do_quality_checks.sh

Lines changed: 138 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -40,172 +40,170 @@ rootdir=$(dirname $0)
4040
ASSERT=
4141

4242
###############################################################################
43-
4443
start_from_scratch() {
45-
cd $rootdir
46-
if [ -e Makefile ] ; then
47-
make distclean >/dev/null 2>&1
48-
fi
44+
cd $rootdir
45+
if [ -e Makefile ] ; then
46+
make distclean >/dev/null 2>&1
47+
fi
4948

5049
}
5150
###############################################################################
5251
#argument 1 is the compiler
5352
#argument 2 is the c++ standard
5453
#argument 3 (optional) is appended to CXXFLAGS
5554
compile_and_test_standard() {
56-
start_from_scratch
57-
/bin/echo -n "using $(basename $1) with standard $2"
58-
if [ -n "$3" ] ; then
59-
echo " (with additional CXXFLAGS $3)"
60-
else
61-
echo ""
62-
fi
55+
start_from_scratch
56+
/bin/echo -n "using $(basename $1) with standard $2"
57+
if [ -n "$3" ] ; then
58+
echo " (with additional CXXFLAGS $3)"
59+
else
60+
echo ""
61+
fi
6362

64-
if ! ./bootstrap.sh >bootstrap.log 2>&1; then
65-
echo failed bootstrap - see bootstrap.log
66-
exit 1
67-
fi
68-
if ! ./configure $ASSERT --enable-warnings CXX=$1 CXXFLAGS="-std=$2 $3" >configure.log 2>&1 ; then
69-
echo failed configure - see configure.log
70-
exit 1
71-
fi
72-
#make sure it compiles
73-
if ! /usr/bin/time --format=%e --output=time.log make >make.log 2>&1; then
74-
echo failed make
75-
exit 1
76-
fi
77-
if [ ! -z $MEASURE_COMPILE_TIME ] ; then
78-
echo " compile with $(basename $1) $2 took $(cat time.log) seconds"
79-
fi
80-
#check for warnings
81-
if grep -q "warning" make.log; then
82-
echo found warning - see make.log
83-
exit 1
84-
fi
85-
#run the tests
86-
if ! make check >makecheck.log 2>&1 ; then
87-
echo failed make check - see makecheck.log
88-
exit 1
89-
fi
63+
if ! ./bootstrap.sh >bootstrap.log 2>&1; then
64+
echo failed bootstrap - see bootstrap.log
65+
exit 1
66+
fi
67+
if ! ./configure $ASSERT --enable-warnings CXX=$1 CXXFLAGS="-std=$2 $3" >configure.log 2>&1 ; then
68+
echo failed configure - see configure.log
69+
exit 1
70+
fi
71+
#make sure it compiles
72+
if ! /usr/bin/time --format=%e --output=time.log make >make.log 2>&1; then
73+
echo failed make
74+
exit 1
75+
fi
76+
if [ ! -z $MEASURE_COMPILE_TIME ] ; then
77+
echo " compile with $(basename $1) $2 took $(cat time.log) seconds"
78+
fi
79+
#check for warnings
80+
if grep -q "warning" make.log; then
81+
echo found warning - see make.log
82+
exit 1
83+
fi
84+
#run the tests
85+
if ! make check >makecheck.log 2>&1 ; then
86+
echo failed make check - see makecheck.log
87+
exit 1
88+
fi
9089
}
9190
###############################################################################
9291
#argument 1 is the compiler
9392
compile_and_test() {
94-
#this is the test program to compile, so we know the compiler and standard lib
95-
#works. clang 4 with c++2a does not.
96-
/bin/echo -e "#include <iostream>">x.cpp
97-
#does the compiler understand c++11? That is mandatory.
98-
if ! $1 -c x.cpp -std=c++11 >/dev/null 2>&1 ; then
99-
echo this compiler $1 does not understand c++11
100-
return 0
101-
fi
93+
#this is the test program to compile, so we know the compiler and standard lib
94+
#works. clang 4 with c++2a does not.
95+
/bin/echo -e "#include <iostream>">x.cpp
96+
#does the compiler understand c++11? That is mandatory.
97+
if ! $1 -c x.cpp -std=c++11 >/dev/null 2>&1 ; then
98+
echo this compiler $1 does not understand c++11
99+
return 0
100+
fi
102101

103-
#loop over all standard flags>=11 and try those which work.
104-
#use the code words.
105-
for std in 11 1y 1z 2a ; do
106-
if ! $1 -c x.cpp -std=c++$std >/dev/null 2>&1 ; then
107-
echo compiler does not understand c++$std, skipping this combination.
108-
else
109-
# debug build
110-
ASSERT=--enable-assert
111-
compile_and_test_standard $1 c++$std "-Og"
102+
#loop over all standard flags>=11 and try those which work.
103+
#use the code words.
104+
for std in 11 1y 1z 2a ; do
105+
if ! $1 -c x.cpp -std=c++$std >/dev/null 2>&1 ; then
106+
echo compiler does not understand c++$std, skipping this combination.
107+
else
108+
# debug build
109+
ASSERT=--enable-assert
110+
compile_and_test_standard $1 c++$std "-Og"
112111

113-
# release build
114-
ASSERT=--disable-assert
115-
compile_and_test_standard $1 c++$std "-O2"
116-
compile_and_test_standard $1 c++$std "-O3"
117-
compile_and_test_standard $1 c++$std "-Os"
118-
fi
119-
done
112+
# release build
113+
ASSERT=--disable-assert
114+
compile_and_test_standard $1 c++$std "-O2"
115+
compile_and_test_standard $1 c++$std "-O3"
116+
compile_and_test_standard $1 c++$std "-Os"
117+
fi
118+
done
120119
}
121120
###############################################################################
122-
123121
run_with_sanitizer() {
124-
echo "running with sanitizer (options $1)"
125-
#find the latest clang compiler
126-
latestclang=$(ls $(which clang++)* |grep -v libc |sort -g |tail -n1)
127-
if [ ! -x $latestclang ] ; then
128-
echo could not find latest clang $latestclang
129-
return 0
130-
fi
122+
echo "running with sanitizer (options $1)"
123+
#find the latest clang compiler
124+
latestclang=$(ls $(which clang++)* |grep -v libc |sort -g |tail -n1)
125+
if [ ! -x $latestclang ] ; then
126+
echo could not find latest clang $latestclang
127+
return 0
128+
fi
131129

132-
start_from_scratch
133-
./bootstrap.sh >bootstrap.log
134-
./configure $ASSERT CXX=$latestclang CXXFLAGS="-std=c++1y $1" >configure.log
135-
make > make.log 2>&1
136-
export UBSAN_OPTIONS="halt_on_error=true exitcode=1"
137-
export ASAN_OPTIONS="halt_on_error=true exitcode=1"
138-
make check >make-check.log 2>&1
139-
unset UBSAN_OPTIONS
140-
unset ASAN_OPTIONS
130+
start_from_scratch
131+
./bootstrap.sh >bootstrap.log
132+
./configure $ASSERT CXX=$latestclang CXXFLAGS="-std=c++1y $1" >configure.log
133+
make > make.log 2>&1
134+
export UBSAN_OPTIONS="halt_on_error=true exitcode=1"
135+
export ASAN_OPTIONS="halt_on_error=true exitcode=1"
136+
make check >make-check.log 2>&1
137+
unset UBSAN_OPTIONS
138+
unset ASAN_OPTIONS
141139
}
142140
###############################################################################
143141
#This tries to mimick how the debian package is built
144142
run_with_debian_buildflags() {
145-
echo "running with buildflags from debian dpkg-buildflags"
146-
if ! which dpkg-buildflags >/dev/null ; then
147-
echo dpkg-buildflags not found - skipping
148-
return 0
149-
fi
150-
start_from_scratch
151-
./bootstrap.sh >bootstrap.log
152-
eval $(DEB_BUILD_MAINT_OPTIONS="hardening=+all qa=+all,-canary reproducible=+all" dpkg-buildflags --export=sh)
153-
./configure >configure.log
154-
make > make.log 2>&1
155-
#check for warnings
156-
if grep -q "warning" make.log; then
157-
echo "found warning(s) - see make.log"
158-
exit 1
159-
fi
160-
make check >make-check.log 2>&1
143+
echo "running with buildflags from debian dpkg-buildflags"
144+
if ! which dpkg-buildflags >/dev/null ; then
145+
echo dpkg-buildflags not found - skipping
146+
return 0
147+
fi
148+
start_from_scratch
149+
./bootstrap.sh >bootstrap.log
150+
eval $(DEB_BUILD_MAINT_OPTIONS="hardening=+all qa=+all,-canary reproducible=+all" dpkg-buildflags --export=sh)
151+
./configure >configure.log
152+
make > make.log 2>&1
153+
#check for warnings
154+
if grep -q "warning" make.log; then
155+
echo "found warning(s) - see make.log"
156+
exit 1
157+
fi
158+
make check >make-check.log 2>&1
161159

162-
#restore the build environment
163-
for flag in $(dpkg-buildflags |cut -f1 -d=) ; do
164-
unset $flag
165-
done
160+
#restore the build environment
161+
for flag in $(dpkg-buildflags |cut -f1 -d=) ; do
162+
unset $flag
163+
done
166164
}
167165
###############################################################################
168166
run_with_libcpp() {
169-
latestclang=$(ls $(which clang++)* |grep -v libc|sort -g |tail -n1)
170-
if [ ! -x $latestclang ] ; then
171-
echo could not find latest clang - skipping test with libc++
172-
return 0
173-
fi
174-
#make a test program to make sure it works.
175-
echo "#include <iostream>
176-
int main() { std::cout<<\"libc++ works!\";}" >x.cpp
177-
if ! $latestclang -std=c++11 -stdlib=libc++ -lc++abi x.cpp >/dev/null 2>&1 && [ -x ./a.out ] && ./a.out ; then
178-
echo "$latestclang could not compile with libc++ - perhaps uninstalled."
179-
return 0
180-
fi
181-
#echo using $latestclang with libc++
182-
compile_and_test_standard $latestclang c++11 "-stdlib=libc++ -D_LIBCPP_DEBUG=1"
167+
latestclang=$(ls $(which clang++)* |grep -v libc|sort -g |tail -n1)
168+
if [ ! -x $latestclang ] ; then
169+
echo could not find latest clang - skipping test with libc++
170+
return 0
171+
fi
172+
#make a test program to make sure it works.
173+
echo "#include <iostream>
174+
int main() { std::cout<<\"libc++ works!\";}" >x.cpp
175+
if ! $latestclang -std=c++11 -stdlib=libc++ -lc++abi x.cpp >/dev/null 2>&1 && [ -x ./a.out ] && ./a.out ; then
176+
echo "$latestclang could not compile with libc++ - perhaps uninstalled."
177+
return 0
178+
fi
179+
#echo using $latestclang with libc++
180+
compile_and_test_standard $latestclang c++11 "-stdlib=libc++ -D_LIBCPP_DEBUG=1"
183181
}
184182
###############################################################################
185183

186184
verify_packaging() {
187-
#make sure the packaging works as intended.
188-
echo "trying to make a tar ball for release and building it..."
189-
log="$(pwd)/packagetest.log"
190-
./bootstrap.sh >$log
191-
./configure >>$log
185+
#make sure the packaging works as intended.
186+
echo "trying to make a tar ball for release and building it..."
187+
log="$(pwd)/packagetest.log"
188+
./bootstrap.sh >$log
189+
./configure >>$log
192190

193-
touch dummy
194-
make dist >>$log
195-
TARGZ=$(find "$(pwd)" -newer dummy -name "rdfind*gz" -type f |head -n1)
196-
temp=$(mktemp -d)
197-
cp "$TARGZ" "$temp"
198-
cd "$temp"
199-
tar xzf $(basename "$TARGZ") >>$log
200-
cd $(basename "$TARGZ" .tar.gz)
201-
./configure --prefix=$temp >>$log
202-
make >>$log
203-
make check >>$log
204-
make install >>$log
205-
$temp/bin/rdfind --version >>$log
206-
#coming here means all went fine, go back to the source dir.
207-
cd $(dirname "$TARGZ")
208-
rm -rf "$temp"
191+
touch dummy
192+
make dist >>$log
193+
TARGZ=$(find "$(pwd)" -newer dummy -name "rdfind*gz" -type f |head -n1)
194+
temp=$(mktemp -d)
195+
cp "$TARGZ" "$temp"
196+
cd "$temp"
197+
tar xzf $(basename "$TARGZ") >>$log
198+
cd $(basename "$TARGZ" .tar.gz)
199+
./configure --prefix=$temp >>$log
200+
make >>$log
201+
make check >>$log
202+
make install >>$log
203+
$temp/bin/rdfind --version >>$log
204+
#coming here means all went fine, go back to the source dir.
205+
cd $(dirname "$TARGZ")
206+
rm -rf "$temp"
209207
}
210208
###############################################################################
211209

@@ -217,11 +215,11 @@ if which g++ >/dev/null ; then
217215
for COMPILER in $(ls $(which g++)* |grep -v libc); do
218216
inode=$(stat --dereference --format=%i $COMPILER)
219217
if grep -q "^$inode\$" inodes_for_tested_compilers.txt ; then
220-
echo skipping this compiler $COMPILER - already tested
218+
echo skipping this compiler $COMPILER - already tested
221219
else
222220
#echo trying gcc $GCC:$($GCC --version|head -n1)
223-
echo $inode >>inodes_for_tested_compilers.txt
224-
compile_and_test $COMPILER
221+
echo $inode >>inodes_for_tested_compilers.txt
222+
compile_and_test $COMPILER
225223
fi
226224
done
227225
fi
@@ -231,11 +229,11 @@ if which clang++ >/dev/null ; then
231229
for COMPILER in $(ls $(which clang++)* |grep -v libc); do
232230
inode=$(stat --dereference --format=%i $COMPILER)
233231
if grep -q "^$inode\$" inodes_for_tested_compilers.txt ; then
234-
echo skipping this compiler $COMPILER - already tested
232+
echo skipping this compiler $COMPILER - already tested
235233
else
236234
#echo trying gcc $GCC:$($GCC --version|head -n1)
237-
echo $inode >>inodes_for_tested_compilers.txt
238-
compile_and_test $COMPILER
235+
echo $inode >>inodes_for_tested_compilers.txt
236+
compile_and_test $COMPILER
239237
fi
240238
done
241239
fi

0 commit comments

Comments
 (0)