summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2020-05-04 02:19:14 +0100
committeriphydf <iphydf@users.noreply.github.com>2020-05-05 01:53:01 +0100
commitc1a2ea3309969608a5553c34fa4199b05f20abc2 (patch)
tree1ad836defd832a87085ec7c717203d5414742784
parentf8ab7218f0eb752b4f936b4686be313921be1da6 (diff)
Use bash arrays instead of strings for static analysis scripts.
These are more robust wrt. spaces in names.
-rw-r--r--other/analysis/gen-file.sh85
-rwxr-xr-xother/analysis/run-clang42
-rwxr-xr-xother/analysis/run-clang-analyze8
-rwxr-xr-xother/analysis/run-cppcheck4
-rwxr-xr-xother/analysis/run-gcc116
-rwxr-xr-xother/analysis/run-infer4
-rwxr-xr-xother/bootstrap_daemon/docker/update-sha2567
7 files changed, 138 insertions, 128 deletions
diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh
index ad8df3b8..1c2a3f6d 100644
--- a/other/analysis/gen-file.sh
+++ b/other/analysis/gen-file.sh
@@ -1,44 +1,51 @@
1#!/bin/sh 1#!/bin/bash
2 2
3CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" 3CPPFLAGS="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
4CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus" 4CPPFLAGS+=("-isystem" "/usr/include/opus")
5CPPFLAGS="$CPPFLAGS -Iauto_tests" 5CPPFLAGS+=("-Iauto_tests")
6CPPFLAGS="$CPPFLAGS -Iother" 6CPPFLAGS+=("-Iother")
7CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src" 7CPPFLAGS+=("-Iother/bootstrap_daemon/src")
8CPPFLAGS="$CPPFLAGS -Iother/fun" 8CPPFLAGS+=("-Iother/fun")
9CPPFLAGS="$CPPFLAGS -Itesting" 9CPPFLAGS+=("-Itesting")
10CPPFLAGS="$CPPFLAGS -Itoxcore" 10CPPFLAGS+=("-Itesting/groupchats")
11CPPFLAGS="$CPPFLAGS -Itoxav" 11CPPFLAGS+=("-Itoxcore")
12CPPFLAGS="$CPPFLAGS -Itoxencryptsave" 12CPPFLAGS+=("-Itoxav")
13CPPFLAGS+=("-Itoxencryptsave")
13 14
14LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig" 15LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig")
16LDFLAGS+=("-fuse-ld=gold")
17LDFLAGS+=("-Wl,--detect-odr-violations")
18LDFLAGS+=("-Wl,--warn-common")
19LDFLAGS+=("-Wl,--warn-execstack")
20LDFLAGS+=("-Wl,-z,noexecstack")
21LDFLAGS+=("-Wl,-z,now")
15 22
16put() { 23put() {
17 if [ "$SKIP_LINES" = "" ]; then 24 if [ "$SKIP_LINES" = "" ]; then
18 echo "#line 1 \"$1\"" >> amalgamation.cc 25 echo "#line 1 \"$1\"" >>amalgamation.cc
19 fi 26 fi
20 cat "$1" >> amalgamation.cc 27 cat "$1" >>amalgamation.cc
21} 28}
22 29
23putmain() { 30putmain() {
24 echo "namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc 31 echo "namespace ${1//[^a-zA-Z0-9_]/_} {" >>amalgamation.cc
25 if [ "$SKIP_LINES" = "" ]; then 32 if [ "$SKIP_LINES" = "" ]; then
26 echo "#line 1 \"$1\"" >> amalgamation.cc 33 echo "#line 1 \"$1\"" >>amalgamation.cc
27 fi 34 fi
28 sed -e 's/^int main(/static &/' "$1" >> amalgamation.cc 35 sed -e 's/^int main(/static &/' "$1" >>amalgamation.cc
29 echo "} // namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc 36 echo "} // namespace ${1//[^a-zA-Z0-9_]/_}" >>amalgamation.cc
30} 37}
31 38
32callmain() { 39callmain() {
33 echo " call($(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc 40 echo " call(${1//[^a-zA-Z0-9_]/_}::main, argc, argv);" >>amalgamation.cc
34} 41}
35 42
36:> amalgamation.cc 43: >amalgamation.cc
37 44
38echo "#include <algorithm>" >> amalgamation.cc 45echo "#include <algorithm>" >>amalgamation.cc
39echo "#include <cstdio>" >> amalgamation.cc 46echo "#include <cstdio>" >>amalgamation.cc
40echo "#include <memory>" >> amalgamation.cc 47echo "#include <memory>" >>amalgamation.cc
41echo "#include <random>" >> amalgamation.cc 48echo "#include <random>" >>amalgamation.cc
42 49
43put auto_tests/check_compat.h 50put auto_tests/check_compat.h
44 51
@@ -53,33 +60,35 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
53FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" 60FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
54FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" 61FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
55 62
56(for i in $(eval "$FIND_QUERY"); do 63readarray -t FILES <<<"$(eval "$FIND_QUERY")"
57 grep -o '#include <[^>]*>' "$i" \
58 | grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
59done) | sort -u >> amalgamation.cc
60 64
61echo 'namespace {' >> amalgamation.cc 65(for i in "${FILES[@]}"; do
62for i in $(eval "$FIND_QUERY"); do 66 grep -o '#include <[^>]*>' "$i" |
67 grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
68done) | sort -u >>amalgamation.cc
69
70echo 'namespace {' >>amalgamation.cc
71for i in "${FILES[@]}"; do
63 if ! grep -q '^int main(' "$i"; then 72 if ! grep -q '^int main(' "$i"; then
64 put "$i" 73 put "$i"
65 fi 74 fi
66done 75done
67 76
68for i in $(eval "$FIND_QUERY"); do 77for i in "${FILES[@]}"; do
69 if grep -q '^int main(' "$i"; then 78 if grep -q '^int main(' "$i"; then
70 putmain "$i" 79 putmain "$i"
71 fi 80 fi
72done 81done
73 82
74echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc 83echo "static void call(int m(), int argc, char **argv) { m(); }" >>amalgamation.cc
75echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc 84echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc
76echo '} // namespace' >> amalgamation.cc 85echo '} // namespace' >>amalgamation.cc
77 86
78echo "int main(int argc, char **argv) {" >> amalgamation.cc 87echo "int main(int argc, char **argv) {" >>amalgamation.cc
79for i in $(eval "$FIND_QUERY"); do 88for i in "${FILES[@]}"; do
80 if grep -q '^int main(' "$i"; then 89 if grep -q '^int main(' "$i"; then
81 callmain "$i" 90 callmain "$i"
82 fi 91 fi
83done 92done
84echo " return 0;" >> amalgamation.cc 93echo " return 0;" >>amalgamation.cc
85echo "}" >> amalgamation.cc 94echo "}" >>amalgamation.cc
diff --git a/other/analysis/run-clang b/other/analysis/run-clang
index fbb0d427..59fc75a6 100755
--- a/other/analysis/run-clang
+++ b/other/analysis/run-clang
@@ -1,25 +1,25 @@
1#!/bin/sh 1#!/bin/bash
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5echo "Running Clang compiler" 5echo "Running Clang compiler"
6clang++ -o /dev/null amalgamation.cc \ 6clang++ -o /dev/null amalgamation.cc \
7 $CPPFLAGS \ 7 "${CPPFLAGS[@]}" \
8 $LDFLAGS \ 8 "${LDFLAGS[@]}" \
9 -std=c++11 \ 9 -std=c++11 \
10 -Werror \ 10 -Werror \
11 -Weverything \ 11 -Weverything \
12 -Wno-c++98-compat-pedantic \ 12 -Wno-c++98-compat-pedantic \
13 -Wno-c99-extensions \ 13 -Wno-c99-extensions \
14 -Wno-cast-align \ 14 -Wno-cast-align \
15 -Wno-conversion \ 15 -Wno-conversion \
16 -Wno-covered-switch-default \ 16 -Wno-covered-switch-default \
17 -Wno-disabled-macro-expansion \ 17 -Wno-disabled-macro-expansion \
18 -Wno-documentation-deprecated-sync \ 18 -Wno-documentation-deprecated-sync \
19 -Wno-missing-field-initializers \ 19 -Wno-missing-field-initializers \
20 -Wno-old-style-cast \ 20 -Wno-old-style-cast \
21 -Wno-padded \ 21 -Wno-padded \
22 -Wno-sign-compare \ 22 -Wno-sign-compare \
23 -Wno-unreachable-code-return \ 23 -Wno-unreachable-code-return \
24 -Wno-unused-parameter \ 24 -Wno-unused-parameter \
25 -Wno-used-but-marked-unused \ 25 -Wno-used-but-marked-unused
diff --git a/other/analysis/run-clang-analyze b/other/analysis/run-clang-analyze
index 0e6d9af0..d790de00 100755
--- a/other/analysis/run-clang-analyze
+++ b/other/analysis/run-clang-analyze
@@ -1,8 +1,8 @@
1#!/bin/sh 1#!/bin/bash
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5echo "Running Clang static analyzer" 5echo "Running Clang static analyzer"
6clang++ --analyze amalgamation.cc \ 6clang++ --analyze amalgamation.cc \
7 $CPPFLAGS \ 7 "${CPPFLAGS[@]}" \
8 -std=c++11 8 -std=c++11
diff --git a/other/analysis/run-cppcheck b/other/analysis/run-cppcheck
index dc369840..17d0ee25 100755
--- a/other/analysis/run-cppcheck
+++ b/other/analysis/run-cppcheck
@@ -1,5 +1,5 @@
1#!/bin/sh 1#!/bin/bash
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5cppcheck amalgamation.cc $CPPFLAGS 5cppcheck amalgamation.cc "${CPPFLAGS[@]}"
diff --git a/other/analysis/run-gcc b/other/analysis/run-gcc
index 3ea32782..74f294df 100755
--- a/other/analysis/run-gcc
+++ b/other/analysis/run-gcc
@@ -1,63 +1,63 @@
1#!/bin/sh 1#!/bin/bash
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5echo "Running GCC" 5echo "Running GCC"
6# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector 6# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector
7g++ -O3 -o /dev/null amalgamation.cc \ 7g++ -O3 -o /dev/null amalgamation.cc \
8 $CPPFLAGS \ 8 "${CPPFLAGS[@]}" \
9 $LDFLAGS \ 9 "${LDFLAGS[@]}" \
10 -std=c++11 \ 10 -std=c++11 \
11 -pedantic \ 11 -pedantic \
12 -fdiagnostics-color=always \ 12 -fdiagnostics-color=always \
13 -Wall \ 13 -Wall \
14 -Wextra \ 14 -Wextra \
15 -Wno-aggregate-return \ 15 -Wno-aggregate-return \
16 -Wno-aggressive-loop-optimizations \ 16 -Wno-aggressive-loop-optimizations \
17 -Wno-float-conversion \ 17 -Wno-float-conversion \
18 -Wno-format-signedness \ 18 -Wno-format-signedness \
19 -Wno-missing-field-initializers \ 19 -Wno-missing-field-initializers \
20 -Wno-padded \ 20 -Wno-padded \
21 -Wno-sign-compare \ 21 -Wno-sign-compare \
22 -Wno-sign-conversion \ 22 -Wno-sign-conversion \
23 -Wno-switch-default \ 23 -Wno-switch-default \
24 -Wno-unused-parameter \ 24 -Wno-unused-parameter \
25 -Wstrict-aliasing=0 \ 25 -Wstrict-aliasing=0 \
26 -Wstrict-overflow=1 \ 26 -Wstrict-overflow=1 \
27 \ 27 \
28 -Wmissing-declarations \ 28 -Wmissing-declarations \
29 -Wbool-compare \ 29 -Wbool-compare \
30 -Wcast-align \ 30 -Wcast-align \
31 -Wcast-qual \ 31 -Wcast-qual \
32 -Wchar-subscripts \ 32 -Wchar-subscripts \
33 -Wdouble-promotion \ 33 -Wdouble-promotion \
34 -Wduplicated-cond \ 34 -Wduplicated-cond \
35 -Wempty-body \ 35 -Wempty-body \
36 -Wenum-compare \ 36 -Wenum-compare \
37 -Wfloat-equal \ 37 -Wfloat-equal \
38 -Wformat=2 \ 38 -Wformat=2 \
39 -Wframe-address \ 39 -Wframe-address \
40 -Wframe-larger-than=133168 \ 40 -Wframe-larger-than=133168 \
41 -Wignored-qualifiers \ 41 -Wignored-qualifiers \
42 -Wignored-attributes \ 42 -Wignored-attributes \
43 -Winit-self \ 43 -Winit-self \
44 -Winline \ 44 -Winline \
45 -Wlarger-than=133120 \ 45 -Wlarger-than=133120 \
46 -Wmaybe-uninitialized \ 46 -Wmaybe-uninitialized \
47 -Wmemset-transposed-args \ 47 -Wmemset-transposed-args \
48 -Wmisleading-indentation \ 48 -Wmisleading-indentation \
49 -Wnonnull \ 49 -Wnonnull \
50 -Wnonnull-compare \ 50 -Wnonnull-compare \
51 -Wnull-dereference \ 51 -Wnull-dereference \
52 -Wodr \ 52 -Wodr \
53 -Wredundant-decls \ 53 -Wredundant-decls \
54 -Wreturn-type \ 54 -Wreturn-type \
55 -Wshadow \ 55 -Wshadow \
56 -Wsuggest-attribute=format \ 56 -Wsuggest-attribute=format \
57 -Wundef \ 57 -Wundef \
58 -Wunsafe-loop-optimizations \ 58 -Wunsafe-loop-optimizations \
59 -Wunused-label \ 59 -Wunused-label \
60 -Wunused-local-typedefs \ 60 -Wunused-local-typedefs \
61 -Wunused-value \ 61 -Wunused-value \
62 -Wunused-but-set-parameter \ 62 -Wunused-but-set-parameter \
63 -Wunused-but-set-variable \ 63 -Wunused-but-set-variable
diff --git a/other/analysis/run-infer b/other/analysis/run-infer
index 2a897227..3b168d08 100755
--- a/other/analysis/run-infer
+++ b/other/analysis/run-infer
@@ -1,8 +1,8 @@
1#!/bin/sh 1#!/bin/bash
2 2
3# Infer ignores everything that's not in the "current file". 3# Infer ignores everything that's not in the "current file".
4SKIP_LINES=1 4SKIP_LINES=1
5 5
6. other/analysis/gen-file.sh 6. other/analysis/gen-file.sh
7 7
8infer -- clang++ -fsyntax-only amalgamation.cc $CPPFLAGS 8infer -- clang++ -fsyntax-only amalgamation.cc "${CPPFLAGS[@]}"
diff --git a/other/bootstrap_daemon/docker/update-sha256 b/other/bootstrap_daemon/docker/update-sha256
index 78aa656f..32eb4e32 100755
--- a/other/bootstrap_daemon/docker/update-sha256
+++ b/other/bootstrap_daemon/docker/update-sha256
@@ -1,9 +1,10 @@
1#!/bin/sh 1#!/bin/bash
2 2
3set -eux 3set -eux
4 4
5docker_build() { 5docker_build() {
6 tar c $(git ls-files) | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node - 6 readarray -t FILES <<<"$(git ls-files)"
7 tar c "${FILES[@]}" | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
7} 8}
8 9
9# Run Docker build once. If it succeeds, we're good. 10# Run Docker build once. If it succeeds, we're good.
@@ -17,7 +18,7 @@ OUTPUT=$(docker_build || true 2>&1)
17if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then 18if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then
18 # This is a checksum warning, so we need to update it. 19 # This is a checksum warning, so we need to update it.
19 IMAGE=$(echo "$OUTPUT" | grep '^ ---> [0-9a-f]*$' | grep -o '[0-9a-f]*$' | tail -n1) 20 IMAGE=$(echo "$OUTPUT" | grep '^ ---> [0-9a-f]*$' | grep -o '[0-9a-f]*$' | tail -n1)
20 docker run --rm "$IMAGE" sha256sum /usr/local/bin/tox-bootstrapd > other/bootstrap_daemon/docker/tox-bootstrapd.sha256 21 docker run --rm "$IMAGE" sha256sum /usr/local/bin/tox-bootstrapd >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
21fi 22fi
22 23
23# Run once last time to complete the build. 24# Run once last time to complete the build.