diff options
author | iphydf <iphydf@users.noreply.github.com> | 2020-05-04 02:19:14 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-05-05 01:53:01 +0100 |
commit | c1a2ea3309969608a5553c34fa4199b05f20abc2 (patch) | |
tree | 1ad836defd832a87085ec7c717203d5414742784 | |
parent | f8ab7218f0eb752b4f936b4686be313921be1da6 (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.sh | 85 | ||||
-rwxr-xr-x | other/analysis/run-clang | 42 | ||||
-rwxr-xr-x | other/analysis/run-clang-analyze | 8 | ||||
-rwxr-xr-x | other/analysis/run-cppcheck | 4 | ||||
-rwxr-xr-x | other/analysis/run-gcc | 116 | ||||
-rwxr-xr-x | other/analysis/run-infer | 4 | ||||
-rwxr-xr-x | other/bootstrap_daemon/docker/update-sha256 | 7 |
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 | ||
3 | CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" | 3 | CPPFLAGS="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" |
4 | CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus" | 4 | CPPFLAGS+=("-isystem" "/usr/include/opus") |
5 | CPPFLAGS="$CPPFLAGS -Iauto_tests" | 5 | CPPFLAGS+=("-Iauto_tests") |
6 | CPPFLAGS="$CPPFLAGS -Iother" | 6 | CPPFLAGS+=("-Iother") |
7 | CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src" | 7 | CPPFLAGS+=("-Iother/bootstrap_daemon/src") |
8 | CPPFLAGS="$CPPFLAGS -Iother/fun" | 8 | CPPFLAGS+=("-Iother/fun") |
9 | CPPFLAGS="$CPPFLAGS -Itesting" | 9 | CPPFLAGS+=("-Itesting") |
10 | CPPFLAGS="$CPPFLAGS -Itoxcore" | 10 | CPPFLAGS+=("-Itesting/groupchats") |
11 | CPPFLAGS="$CPPFLAGS -Itoxav" | 11 | CPPFLAGS+=("-Itoxcore") |
12 | CPPFLAGS="$CPPFLAGS -Itoxencryptsave" | 12 | CPPFLAGS+=("-Itoxav") |
13 | CPPFLAGS+=("-Itoxencryptsave") | ||
13 | 14 | ||
14 | LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig" | 15 | LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig") |
16 | LDFLAGS+=("-fuse-ld=gold") | ||
17 | LDFLAGS+=("-Wl,--detect-odr-violations") | ||
18 | LDFLAGS+=("-Wl,--warn-common") | ||
19 | LDFLAGS+=("-Wl,--warn-execstack") | ||
20 | LDFLAGS+=("-Wl,-z,noexecstack") | ||
21 | LDFLAGS+=("-Wl,-z,now") | ||
15 | 22 | ||
16 | put() { | 23 | put() { |
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 | ||
23 | putmain() { | 30 | putmain() { |
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 | ||
32 | callmain() { | 39 | callmain() { |
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 | ||
38 | echo "#include <algorithm>" >> amalgamation.cc | 45 | echo "#include <algorithm>" >>amalgamation.cc |
39 | echo "#include <cstdio>" >> amalgamation.cc | 46 | echo "#include <cstdio>" >>amalgamation.cc |
40 | echo "#include <memory>" >> amalgamation.cc | 47 | echo "#include <memory>" >>amalgamation.cc |
41 | echo "#include <random>" >> amalgamation.cc | 48 | echo "#include <random>" >>amalgamation.cc |
42 | 49 | ||
43 | put auto_tests/check_compat.h | 50 | put auto_tests/check_compat.h |
44 | 51 | ||
@@ -53,33 +60,35 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c" | |||
53 | FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" | 60 | FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" |
54 | FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" | 61 | FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" |
55 | 62 | ||
56 | (for i in $(eval "$FIND_QUERY"); do | 63 | readarray -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' | ||
59 | done) | sort -u >> amalgamation.cc | ||
60 | 64 | ||
61 | echo 'namespace {' >> amalgamation.cc | 65 | (for i in "${FILES[@]}"; do |
62 | for 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' | ||
68 | done) | sort -u >>amalgamation.cc | ||
69 | |||
70 | echo 'namespace {' >>amalgamation.cc | ||
71 | for 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 |
66 | done | 75 | done |
67 | 76 | ||
68 | for i in $(eval "$FIND_QUERY"); do | 77 | for 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 |
72 | done | 81 | done |
73 | 82 | ||
74 | echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc | 83 | echo "static void call(int m(), int argc, char **argv) { m(); }" >>amalgamation.cc |
75 | echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc | 84 | echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc |
76 | echo '} // namespace' >> amalgamation.cc | 85 | echo '} // namespace' >>amalgamation.cc |
77 | 86 | ||
78 | echo "int main(int argc, char **argv) {" >> amalgamation.cc | 87 | echo "int main(int argc, char **argv) {" >>amalgamation.cc |
79 | for i in $(eval "$FIND_QUERY"); do | 88 | for 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 |
83 | done | 92 | done |
84 | echo " return 0;" >> amalgamation.cc | 93 | echo " return 0;" >>amalgamation.cc |
85 | echo "}" >> amalgamation.cc | 94 | echo "}" >>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 | ||
5 | echo "Running Clang compiler" | 5 | echo "Running Clang compiler" |
6 | clang++ -o /dev/null amalgamation.cc \ | 6 | clang++ -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 | ||
5 | echo "Running Clang static analyzer" | 5 | echo "Running Clang static analyzer" |
6 | clang++ --analyze amalgamation.cc \ | 6 | clang++ --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 | ||
5 | cppcheck amalgamation.cc $CPPFLAGS | 5 | cppcheck 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 | ||
5 | echo "Running GCC" | 5 | echo "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 |
7 | g++ -O3 -o /dev/null amalgamation.cc \ | 7 | g++ -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". |
4 | SKIP_LINES=1 | 4 | SKIP_LINES=1 |
5 | 5 | ||
6 | . other/analysis/gen-file.sh | 6 | . other/analysis/gen-file.sh |
7 | 7 | ||
8 | infer -- clang++ -fsyntax-only amalgamation.cc $CPPFLAGS | 8 | infer -- 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 | ||
3 | set -eux | 3 | set -eux |
4 | 4 | ||
5 | docker_build() { | 5 | docker_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) | |||
17 | if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then | 18 | if 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 |
21 | fi | 22 | fi |
22 | 23 | ||
23 | # Run once last time to complete the build. | 24 | # Run once last time to complete the build. |