Use bash arrays instead of strings for static analysis scripts.

These are more robust wrt. spaces in names.
This commit is contained in:
iphydf 2020-05-04 02:19:14 +01:00
parent f8ab7218f0
commit c1a2ea3309
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
7 changed files with 138 additions and 128 deletions

View File

@ -1,17 +1,24 @@
#!/bin/sh
#!/bin/bash
CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus"
CPPFLAGS="$CPPFLAGS -Iauto_tests"
CPPFLAGS="$CPPFLAGS -Iother"
CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src"
CPPFLAGS="$CPPFLAGS -Iother/fun"
CPPFLAGS="$CPPFLAGS -Itesting"
CPPFLAGS="$CPPFLAGS -Itoxcore"
CPPFLAGS="$CPPFLAGS -Itoxav"
CPPFLAGS="$CPPFLAGS -Itoxencryptsave"
CPPFLAGS="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
CPPFLAGS+=("-isystem" "/usr/include/opus")
CPPFLAGS+=("-Iauto_tests")
CPPFLAGS+=("-Iother")
CPPFLAGS+=("-Iother/bootstrap_daemon/src")
CPPFLAGS+=("-Iother/fun")
CPPFLAGS+=("-Itesting")
CPPFLAGS+=("-Itesting/groupchats")
CPPFLAGS+=("-Itoxcore")
CPPFLAGS+=("-Itoxav")
CPPFLAGS+=("-Itoxencryptsave")
LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig"
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig")
LDFLAGS+=("-fuse-ld=gold")
LDFLAGS+=("-Wl,--detect-odr-violations")
LDFLAGS+=("-Wl,--warn-common")
LDFLAGS+=("-Wl,--warn-execstack")
LDFLAGS+=("-Wl,-z,noexecstack")
LDFLAGS+=("-Wl,-z,now")
put() {
if [ "$SKIP_LINES" = "" ]; then
@ -21,16 +28,16 @@ put() {
}
putmain() {
echo "namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc
echo "namespace ${1//[^a-zA-Z0-9_]/_} {" >>amalgamation.cc
if [ "$SKIP_LINES" = "" ]; then
echo "#line 1 \"$1\"" >>amalgamation.cc
fi
sed -e 's/^int main(/static &/' "$1" >>amalgamation.cc
echo "} // namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc
echo "} // namespace ${1//[^a-zA-Z0-9_]/_}" >>amalgamation.cc
}
callmain() {
echo " call($(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc
echo " call(${1//[^a-zA-Z0-9_]/_}::main, argc, argv);" >>amalgamation.cc
}
: >amalgamation.cc
@ -53,19 +60,21 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
(for i in $(eval "$FIND_QUERY"); do
grep -o '#include <[^>]*>' "$i" \
| grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
readarray -t FILES <<<"$(eval "$FIND_QUERY")"
(for i in "${FILES[@]}"; do
grep -o '#include <[^>]*>' "$i" |
grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
done) | sort -u >>amalgamation.cc
echo 'namespace {' >>amalgamation.cc
for i in $(eval "$FIND_QUERY"); do
for i in "${FILES[@]}"; do
if ! grep -q '^int main(' "$i"; then
put "$i"
fi
done
for i in $(eval "$FIND_QUERY"); do
for i in "${FILES[@]}"; do
if grep -q '^int main(' "$i"; then
putmain "$i"
fi
@ -76,7 +85,7 @@ echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, arg
echo '} // namespace' >>amalgamation.cc
echo "int main(int argc, char **argv) {" >>amalgamation.cc
for i in $(eval "$FIND_QUERY"); do
for i in "${FILES[@]}"; do
if grep -q '^int main(' "$i"; then
callmain "$i"
fi

View File

@ -1,11 +1,11 @@
#!/bin/sh
#!/bin/bash
. other/analysis/gen-file.sh
echo "Running Clang compiler"
clang++ -o /dev/null amalgamation.cc \
$CPPFLAGS \
$LDFLAGS \
"${CPPFLAGS[@]}" \
"${LDFLAGS[@]}" \
-std=c++11 \
-Werror \
-Weverything \
@ -22,4 +22,4 @@ clang++ -o /dev/null amalgamation.cc \
-Wno-sign-compare \
-Wno-unreachable-code-return \
-Wno-unused-parameter \
-Wno-used-but-marked-unused \
-Wno-used-but-marked-unused

View File

@ -1,8 +1,8 @@
#!/bin/sh
#!/bin/bash
. other/analysis/gen-file.sh
echo "Running Clang static analyzer"
clang++ --analyze amalgamation.cc \
$CPPFLAGS \
"${CPPFLAGS[@]}" \
-std=c++11

View File

@ -1,5 +1,5 @@
#!/bin/sh
#!/bin/bash
. other/analysis/gen-file.sh
cppcheck amalgamation.cc $CPPFLAGS
cppcheck amalgamation.cc "${CPPFLAGS[@]}"

View File

@ -1,12 +1,12 @@
#!/bin/sh
#!/bin/bash
. other/analysis/gen-file.sh
echo "Running GCC"
# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector
g++ -O3 -o /dev/null amalgamation.cc \
$CPPFLAGS \
$LDFLAGS \
"${CPPFLAGS[@]}" \
"${LDFLAGS[@]}" \
-std=c++11 \
-pedantic \
-fdiagnostics-color=always \
@ -60,4 +60,4 @@ g++ -O3 -o /dev/null amalgamation.cc \
-Wunused-local-typedefs \
-Wunused-value \
-Wunused-but-set-parameter \
-Wunused-but-set-variable \
-Wunused-but-set-variable

View File

@ -1,8 +1,8 @@
#!/bin/sh
#!/bin/bash
# Infer ignores everything that's not in the "current file".
SKIP_LINES=1
. other/analysis/gen-file.sh
infer -- clang++ -fsyntax-only amalgamation.cc $CPPFLAGS
infer -- clang++ -fsyntax-only amalgamation.cc "${CPPFLAGS[@]}"

View File

@ -1,9 +1,10 @@
#!/bin/sh
#!/bin/bash
set -eux
docker_build() {
tar c $(git ls-files) | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
readarray -t FILES <<<"$(git ls-files)"
tar c "${FILES[@]}" | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
}
# Run Docker build once. If it succeeds, we're good.