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="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus" CPPFLAGS+=("-isystem" "/usr/include/opus")
CPPFLAGS="$CPPFLAGS -Iauto_tests" CPPFLAGS+=("-Iauto_tests")
CPPFLAGS="$CPPFLAGS -Iother" CPPFLAGS+=("-Iother")
CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src" CPPFLAGS+=("-Iother/bootstrap_daemon/src")
CPPFLAGS="$CPPFLAGS -Iother/fun" CPPFLAGS+=("-Iother/fun")
CPPFLAGS="$CPPFLAGS -Itesting" CPPFLAGS+=("-Itesting")
CPPFLAGS="$CPPFLAGS -Itoxcore" CPPFLAGS+=("-Itesting/groupchats")
CPPFLAGS="$CPPFLAGS -Itoxav" CPPFLAGS+=("-Itoxcore")
CPPFLAGS="$CPPFLAGS -Itoxencryptsave" 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() { put() {
if [ "$SKIP_LINES" = "" ]; then if [ "$SKIP_LINES" = "" ]; then
@ -21,16 +28,16 @@ put() {
} }
putmain() { 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 if [ "$SKIP_LINES" = "" ]; then
echo "#line 1 \"$1\"" >>amalgamation.cc echo "#line 1 \"$1\"" >>amalgamation.cc
fi fi
sed -e 's/^int main(/static &/' "$1" >>amalgamation.cc 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() { 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 : >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 dht_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
(for i in $(eval "$FIND_QUERY"); do readarray -t FILES <<<"$(eval "$FIND_QUERY")"
grep -o '#include <[^>]*>' "$i" \
| grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux' (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 done) | sort -u >>amalgamation.cc
echo 'namespace {' >>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 if ! grep -q '^int main(' "$i"; then
put "$i" put "$i"
fi fi
done done
for i in $(eval "$FIND_QUERY"); do for i in "${FILES[@]}"; do
if grep -q '^int main(' "$i"; then if grep -q '^int main(' "$i"; then
putmain "$i" putmain "$i"
fi 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 '} // namespace' >>amalgamation.cc
echo "int main(int argc, char **argv) {" >>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 if grep -q '^int main(' "$i"; then
callmain "$i" callmain "$i"
fi fi

View File

@ -1,11 +1,11 @@
#!/bin/sh #!/bin/bash
. other/analysis/gen-file.sh . other/analysis/gen-file.sh
echo "Running Clang compiler" echo "Running Clang compiler"
clang++ -o /dev/null amalgamation.cc \ clang++ -o /dev/null amalgamation.cc \
$CPPFLAGS \ "${CPPFLAGS[@]}" \
$LDFLAGS \ "${LDFLAGS[@]}" \
-std=c++11 \ -std=c++11 \
-Werror \ -Werror \
-Weverything \ -Weverything \
@ -22,4 +22,4 @@ clang++ -o /dev/null amalgamation.cc \
-Wno-sign-compare \ -Wno-sign-compare \
-Wno-unreachable-code-return \ -Wno-unreachable-code-return \
-Wno-unused-parameter \ -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 . other/analysis/gen-file.sh
echo "Running Clang static analyzer" echo "Running Clang static analyzer"
clang++ --analyze amalgamation.cc \ clang++ --analyze amalgamation.cc \
$CPPFLAGS \ "${CPPFLAGS[@]}" \
-std=c++11 -std=c++11

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/bash
. other/analysis/gen-file.sh . 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 . other/analysis/gen-file.sh
echo "Running GCC" echo "Running GCC"
# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector # TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector
g++ -O3 -o /dev/null amalgamation.cc \ g++ -O3 -o /dev/null amalgamation.cc \
$CPPFLAGS \ "${CPPFLAGS[@]}" \
$LDFLAGS \ "${LDFLAGS[@]}" \
-std=c++11 \ -std=c++11 \
-pedantic \ -pedantic \
-fdiagnostics-color=always \ -fdiagnostics-color=always \
@ -60,4 +60,4 @@ g++ -O3 -o /dev/null amalgamation.cc \
-Wunused-local-typedefs \ -Wunused-local-typedefs \
-Wunused-value \ -Wunused-value \
-Wunused-but-set-parameter \ -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". # Infer ignores everything that's not in the "current file".
SKIP_LINES=1 SKIP_LINES=1
. other/analysis/gen-file.sh . 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 set -eux
docker_build() { 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. # Run Docker build once. If it succeeds, we're good.