From ebfcf2fa386853b39f6d8b9541cbe41fdc3e4009 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 13:24:31 +0300 Subject: scripts: Create script which checks Neovim with PVS-studio --- scripts/pvscheck.sh | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 scripts/pvscheck.sh (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh new file mode 100755 index 0000000000..0a3d7486f2 --- /dev/null +++ b/scripts/pvscheck.sh @@ -0,0 +1,96 @@ +#!/bin/sh +set -x +set -e + +get_jobs_num() { + local num="$(cat /proc/cpuinfo | grep -c "^processor")" + num="$(echo $(( num + 1 )))" + num="${num:-1}" + echo $num +} + +get_pvs_comment() { + cat > pvs-comment << EOF +// This is an open source non-commercial project. Dear PVS-Studio, please check it. +// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +EOF +} + +install_pvs() { + mkdir pvs-studio + cd pvs-studio + + curl -o pvs-studio.tar.gz "$PVS_URL" + tar xzf pvs-studio.tar.gz + rm pvs-studio.tar.gz + local pvsdir="$(find . -maxdepth 1 -mindepth 1)" + find "$pvsdir" -maxdepth 1 -mindepth 1 -exec mv '{}' . \; + rmdir "$pvsdir" + + export PATH="$PWD/bin${PATH+:}${PATH}" + + cd .. +} + +create_compile_commands() { + mkdir build + cd build + env \ + CC=clang \ + CFLAGS=' -O0 ' \ + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" + make -j"$(get_jobs_num)" + find src/nvim/auto -name '*.test-include.c' -delete + + cd .. +} + +patch_sources() { + get_pvs_comment + + local sh_script=' + cat pvs-comment "$1" > "$1.tmp" + mv "$1.tmp" "$1" + ' + + find \ + src/nvim test/functional/fixtures test/unit/fixtures \ + -name '*.[ch]' \ + -exec /bin/sh -c "$sh_script" - '{}' \; + + find \ + build/src/nvim/auto build/config \ + -name '*.[ch]' -not -name '*.test-include.c' \ + -exec /bin/sh -c "$sh_script" - '{}' \; +} + +main() { + local PVS_URL="http://files.viva64.com/pvs-studio-6.14.21446.1-x86_64.tgz" + + local tgt="${1:-$PWD/../neovim-pvs}" + local branch="${2:-master}" + + git worktree add "$tgt" "$branch" + + cd "$tgt" + + install_pvs + + create_compile_commands + + patch_sources + + pvs-studio-analyzer \ + analyze \ + --threads "$(get_jobs_num)" \ + --output-file PVS-studio.log \ + --verbose \ + --file build/compile_commands.json \ + --sourcetree-root . + + plog-converter -t xml -o PVS-studio.xml PVS-studio.log + plog-converter -t errorfile -o PVS-studio.err PVS-studio.log + plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log +} + +main "$@" -- cgit From 59f0cbc282b1f110dd0281d835f52cfeb62c91d4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 13:41:09 +0300 Subject: pvscheck: Add help --- scripts/pvscheck.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 0a3d7486f2..00f2d481ea 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -64,9 +64,25 @@ patch_sources() { -exec /bin/sh -c "$sh_script" - '{}' \; } +help() { + echo 'Usage: pvscheck.sh [target-directory [branch]]' + echo + echo ' target-directory: Directory where build should occur' + echo ' Default: ../neovim-pvs' + echo + echo ' branch: Branch to check' + echo ' Must not be already checked out: uses git worktree.' + echo ' Default: master' +} + main() { local PVS_URL="http://files.viva64.com/pvs-studio-6.14.21446.1-x86_64.tgz" + if test "x$1" = "x--help" ; then + help + return 0 + fi + local tgt="${1:-$PWD/../neovim-pvs}" local branch="${2:-master}" -- cgit From 3bd11f29116510baf0f7700503d0977d84bb218b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 13:42:31 +0300 Subject: pvsscript: Use git clone and not git worktree --- scripts/pvscheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 00f2d481ea..0e1b9ba404 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -80,13 +80,13 @@ main() { if test "x$1" = "x--help" ; then help - return 0 + return fi local tgt="${1:-$PWD/../neovim-pvs}" local branch="${2:-master}" - git worktree add "$tgt" "$branch" + git clone --depth=1 --branch="$branch" . "$tgt" cd "$tgt" -- cgit From d7086f44f46cea5d949452e22c6ca1286bd9db77 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 13:45:33 +0300 Subject: pvscheck: Do not trace help --- scripts/pvscheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 0e1b9ba404..cd8bf60a92 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -1,5 +1,4 @@ #!/bin/sh -set -x set -e get_jobs_num() { @@ -82,6 +81,7 @@ main() { help return fi + set -x local tgt="${1:-$PWD/../neovim-pvs}" local branch="${2:-master}" -- cgit From 2b13c87fa241c877f56366ab632fd2057fe297d8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 13:47:31 +0300 Subject: pvscheck: Do not use --depth --- scripts/pvscheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index cd8bf60a92..3b21c65702 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -86,7 +86,7 @@ main() { local tgt="${1:-$PWD/../neovim-pvs}" local branch="${2:-master}" - git clone --depth=1 --branch="$branch" . "$tgt" + git clone --branch="$branch" . "$tgt" cd "$tgt" -- cgit From 55292685d36c0aff7733982033a4567b6e7a6ee3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 14:07:26 +0300 Subject: pvscheck: Add --recheck argument --- scripts/pvscheck.sh | 95 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 30 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 3b21c65702..2e4f990693 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -8,6 +8,20 @@ get_jobs_num() { echo $num } +help() { + echo 'Usage:' + echo ' pvscheck.sh [target-directory [branch]]' + echo ' pvscheck.sh [--recheck] [target-directory]' + echo + echo ' --recheck: run analysis on a prepared target directory' + echo + echo ' target-directory: Directory where build should occur' + echo ' Default: ../neovim-pvs' + echo + echo ' branch: Branch to check' + echo ' Default: master' +} + get_pvs_comment() { cat > pvs-comment << EOF // This is an open source non-commercial project. Dear PVS-Studio, please check it. @@ -63,28 +77,23 @@ patch_sources() { -exec /bin/sh -c "$sh_script" - '{}' \; } -help() { - echo 'Usage: pvscheck.sh [target-directory [branch]]' - echo - echo ' target-directory: Directory where build should occur' - echo ' Default: ../neovim-pvs' - echo - echo ' branch: Branch to check' - echo ' Must not be already checked out: uses git worktree.' - echo ' Default: master' -} - -main() { - local PVS_URL="http://files.viva64.com/pvs-studio-6.14.21446.1-x86_64.tgz" +run_analysis() { + pvs-studio-analyzer \ + analyze \ + --threads "$(get_jobs_num)" \ + --output-file PVS-studio.log \ + --verbose \ + --file build/compile_commands.json \ + --sourcetree-root . - if test "x$1" = "x--help" ; then - help - return - fi - set -x + plog-converter -t xml -o PVS-studio.xml PVS-studio.log + plog-converter -t errorfile -o PVS-studio.err PVS-studio.log + plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log +} - local tgt="${1:-$PWD/../neovim-pvs}" - local branch="${2:-master}" +do_check() { + local tgt="${1}" + local branch="${2}" git clone --branch="$branch" . "$tgt" @@ -96,17 +105,43 @@ main() { patch_sources - pvs-studio-analyzer \ - analyze \ - --threads "$(get_jobs_num)" \ - --output-file PVS-studio.log \ - --verbose \ - --file build/compile_commands.json \ - --sourcetree-root . + run_analysis +} - plog-converter -t xml -o PVS-studio.xml PVS-studio.log - plog-converter -t errorfile -o PVS-studio.err PVS-studio.log - plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log +do_recheck() { + local tgt="${1}" + + cd "$tgt" + + export PATH="$PWD/pvs-studio/bin${PATH+:}${PATH}" + + run_analysis +} + +main() { + local PVS_URL="http://files.viva64.com/pvs-studio-6.14.21446.1-x86_64.tgz" + + if test "x$1" = "x--help" ; then + help + return + fi + + set -x + + local recheck= + if test "x$1" = "x--recheck" ; then + recheck=1 + shift + fi + + local tgt="${1:-$PWD/../neovim-pvs}" + local branch="${2:-master}" + + if test "x$recheck" = "x" ; then + do_check "$tgt" "$branch" + else + do_recheck "$tgt" + fi } main "$@" -- cgit From 38b2bc9a883d88b5257673048f687c5ac1fe7446 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 19 Apr 2017 18:55:32 +0300 Subject: scripts: Make pvs do not patch separate directory, add patch mode --- scripts/pvscheck.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 2e4f990693..faa6f92c9a 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -12,20 +12,24 @@ help() { echo 'Usage:' echo ' pvscheck.sh [target-directory [branch]]' echo ' pvscheck.sh [--recheck] [target-directory]' + echo ' pvscheck.sh --patch' echo - echo ' --recheck: run analysis on a prepared target directory' + echo ' --patch: patch sources in the current directory.' + echo ' Does not run analysis.' echo - echo ' target-directory: Directory where build should occur' + echo ' --recheck: run analysis on a prepared target directory.' + echo + echo ' target-directory: Directory where build should occur.' echo ' Default: ../neovim-pvs' echo - echo ' branch: Branch to check' - echo ' Default: master' + echo ' branch: Branch to check.' + echo ' Default: master.' } get_pvs_comment() { cat > pvs-comment << EOF -// This is an open source non-commercial project. Dear PVS-Studio, please check it. -// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com EOF } @@ -75,6 +79,8 @@ patch_sources() { build/src/nvim/auto build/config \ -name '*.[ch]' -not -name '*.test-include.c' \ -exec /bin/sh -c "$sh_script" - '{}' \; + + rm pvs-comment } run_analysis() { @@ -103,8 +109,6 @@ do_check() { create_compile_commands - patch_sources - run_analysis } @@ -128,6 +132,11 @@ main() { set -x + if test "x$1" = "x--patch" ; then + patch_sources + exit $? + fi + local recheck= if test "x$1" = "x--recheck" ; then recheck=1 -- cgit From 9fd048d901e1191dc56066e4be70014c3387c9fe Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 19 Apr 2017 19:04:00 +0300 Subject: scripts: Do not patch already patched sources in patch mode Also do not patch header files, that is not needed. --- scripts/pvscheck.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index faa6f92c9a..e2d2a2eada 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -15,6 +15,7 @@ help() { echo ' pvscheck.sh --patch' echo echo ' --patch: patch sources in the current directory.' + echo ' Does not patch already patched files.' echo ' Does not run analysis.' echo echo ' --recheck: run analysis on a prepared target directory.' @@ -66,18 +67,22 @@ patch_sources() { get_pvs_comment local sh_script=' - cat pvs-comment "$1" > "$1.tmp" - mv "$1.tmp" "$1" + pvs_comment="$(cat pvs-comment ; echo -n EOS)" + filehead="$(head -c $(( ${#pvs_comment} - 3 )) "$1" ; echo -n EOS)" + if test "x$filehead" != "x$pvs_comment" ; then + cat pvs-comment "$1" > "$1.tmp" + mv "$1.tmp" "$1" + fi ' find \ src/nvim test/functional/fixtures test/unit/fixtures \ - -name '*.[ch]' \ + -name '*.c' \ -exec /bin/sh -c "$sh_script" - '{}' \; find \ build/src/nvim/auto build/config \ - -name '*.[ch]' -not -name '*.test-include.c' \ + -name '*.c' -not -name '*.test-include.c' \ -exec /bin/sh -c "$sh_script" - '{}' \; rm pvs-comment -- cgit From 4555bf9e7f8829053e3a687f814a2036d72ce0e1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 19 Apr 2017 19:08:27 +0300 Subject: scripts: Allow patching only build files --- scripts/pvscheck.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index e2d2a2eada..5020d5f86a 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -12,12 +12,14 @@ help() { echo 'Usage:' echo ' pvscheck.sh [target-directory [branch]]' echo ' pvscheck.sh [--recheck] [target-directory]' - echo ' pvscheck.sh --patch' + echo ' pvscheck.sh --patch [--only-build]' echo echo ' --patch: patch sources in the current directory.' echo ' Does not patch already patched files.' echo ' Does not run analysis.' echo + echo ' --only-build: Only patch files in ./build directory.' + echo echo ' --recheck: run analysis on a prepared target directory.' echo echo ' target-directory: Directory where build should occur.' @@ -75,10 +77,12 @@ patch_sources() { fi ' - find \ - src/nvim test/functional/fixtures test/unit/fixtures \ - -name '*.c' \ - -exec /bin/sh -c "$sh_script" - '{}' \; + if test "x$1" != "x--only-build" ; then + find \ + src/nvim test/functional/fixtures test/unit/fixtures \ + -name '*.c' \ + -exec /bin/sh -c "$sh_script" - '{}' \; + fi find \ build/src/nvim/auto build/config \ @@ -138,7 +142,13 @@ main() { set -x if test "x$1" = "x--patch" ; then - patch_sources + shift + if test "x$1" = "x--only-build" ; then + shift + patch_sources --only-build + else + patch_sources + fi exit $? fi -- cgit From 3351016dcde8f8d400c247baaca4a5575d94535d Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 19 Apr 2017 19:11:37 +0300 Subject: scripts: Add newline after the comment --- scripts/pvscheck.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 5020d5f86a..32d63646aa 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -33,6 +33,7 @@ get_pvs_comment() { cat > pvs-comment << EOF // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + EOF } -- cgit From bcc97afbd258c8608e73ff7765c33fe5da713fb9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 01:54:21 +0300 Subject: pvscheck: Do not use `test x` [ci skip] --- scripts/pvscheck.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 32d63646aa..6e95358aa8 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -135,16 +135,16 @@ do_recheck() { main() { local PVS_URL="http://files.viva64.com/pvs-studio-6.14.21446.1-x86_64.tgz" - if test "x$1" = "x--help" ; then + if test "$1" = "--help" ; then help return fi set -x - if test "x$1" = "x--patch" ; then + if test "$1" = "--patch" ; then shift - if test "x$1" = "x--only-build" ; then + if test "$1" = "--only-build" ; then shift patch_sources --only-build else @@ -154,7 +154,7 @@ main() { fi local recheck= - if test "x$1" = "x--recheck" ; then + if test "$1" = "--recheck" ; then recheck=1 shift fi @@ -162,7 +162,7 @@ main() { local tgt="${1:-$PWD/../neovim-pvs}" local branch="${2:-master}" - if test "x$recheck" = "x" ; then + if test -z "$recheck" ; then do_check "$tgt" "$branch" else do_recheck "$tgt" -- cgit From 7fc3cccfaabf8f576af73a21d7538257df4d41ed Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 01:54:44 +0300 Subject: pvscheck: Update pvs-studio URL [ci skip] --- scripts/pvscheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 6e95358aa8..c8928dc266 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -133,7 +133,7 @@ do_recheck() { } main() { - local PVS_URL="http://files.viva64.com/pvs-studio-6.14.21446.1-x86_64.tgz" + local PVS_URL="http://files.viva64.com/pvs-studio-6.15.21741.1-x86_64.tgz" if test "$1" = "--help" ; then help -- cgit From 15d39022abc3eb3d086b33977b9dec9972aab8e1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 02:08:16 +0300 Subject: pvscheck: Add --pvs key to pvscheck.sh [ci skip] --- scripts/pvscheck.sh | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index c8928dc266..2af38d7711 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -10,10 +10,17 @@ get_jobs_num() { help() { echo 'Usage:' - echo ' pvscheck.sh [target-directory [branch]]' - echo ' pvscheck.sh [--recheck] [target-directory]' + echo ' pvscheck.sh [--pvs URL] [target-directory [branch]]' + echo ' pvscheck.sh [--pvs URL] [--recheck] [target-directory]' echo ' pvscheck.sh --patch [--only-build]' echo + echo ' --pvs: Use the specified URL as a path to pvs-studio archive.' + echo ' By default latest tested version is used.' + echo + echo ' May use `--pvs detect` to try detecting latest version.' + echo ' That assumes certain viva64.com site properties and' + echo ' may be broken by the site update.' + echo echo ' --patch: patch sources in the current directory.' echo ' Does not patch already patched files.' echo ' Does not run analysis.' @@ -38,10 +45,12 @@ EOF } install_pvs() { + local pvs_url="$1" + mkdir pvs-studio cd pvs-studio - curl -o pvs-studio.tar.gz "$PVS_URL" + curl -L -o pvs-studio.tar.gz "$pvs_url" tar xzf pvs-studio.tar.gz rm pvs-studio.tar.gz local pvsdir="$(find . -maxdepth 1 -mindepth 1)" @@ -108,14 +117,15 @@ run_analysis() { } do_check() { - local tgt="${1}" - local branch="${2}" + local tgt="$1" + local branch="$2" + local pvs_url="$3" git clone --branch="$branch" . "$tgt" cd "$tgt" - install_pvs + install_pvs "$pvs_url" create_compile_commands @@ -132,8 +142,13 @@ do_recheck() { run_analysis } +detect_url() { + curl -L 'https://www.viva64.com/en/pvs-studio-download-linux/' \ + | grep -o 'https\{0,1\}://[^"<>]\{1,\}/pvs-studio[^/"<>]*\.tgz' +} + main() { - local PVS_URL="http://files.viva64.com/pvs-studio-6.15.21741.1-x86_64.tgz" + local pvs_url="http://files.viva64.com/pvs-studio-6.15.21741.1-x86_64.tgz" if test "$1" = "--help" ; then help @@ -142,6 +157,15 @@ main() { set -x + if test "$1" = "--pvs" ; then + shift + pvs_url="$1" ; shift + + if test "$pvs_url" = "detect" ; then + pvs_url="$(detect_url)" + fi + fi + if test "$1" = "--patch" ; then shift if test "$1" = "--only-build" ; then @@ -163,7 +187,7 @@ main() { local branch="${2:-master}" if test -z "$recheck" ; then - do_check "$tgt" "$branch" + do_check "$tgt" "$branch" "$pvs_url" else do_recheck "$tgt" fi -- cgit From 4cb61aa7428128283c45ee3ca90f01c4805c8148 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 17:56:30 +0300 Subject: pvscheck: Create getopts_long implementation Needed as argument list is growing large and I absolutely do not find short options provided by getopts being particularly readable for unfamiliar commands. [ci skip] --- scripts/pvscheck.sh | 258 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 212 insertions(+), 46 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 2af38d7711..51ecaf0c46 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -1,5 +1,8 @@ #!/bin/sh set -e +# Note: -u causes problems with posh, it barks at “undefined” $@ when no +# arguments provided. +test -z "$POSH_VERSION" && set -u get_jobs_num() { local num="$(cat /proc/cpuinfo | grep -c "^processor")" @@ -36,6 +39,178 @@ help() { echo ' Default: master.' } +getopts_error() { + printf '%s\n' "$1" >&2 + echo 'return 1' + return 1 +} + +# Usage `eval "$(getopts_long long_defs -- positionals_defs -- "$@")"` +# +# long_defs: list of pairs of arguments like `longopt action`. +# positionals_defs: list of arguments like `action`. +# +# `action` is a space-separated commands: +# +# store_const [const] [varname] [default] +# Store constant [const] (default 1) (note: eval’ed) if argument is present +# (long options only). Assumes long option accepts no arguments. +# store [varname] [default] +# Store value. Assumes long option needs an argument. +# run {func} [varname] [default] +# Run function {func} and store its output to the [varname]. Assumes no +# arguments accepted (long options only). +# modify {func} [varname] [default] +# Like run, but assumes a single argument, passed to function {func} as $1. +# +# All actions stores empty value if neither [varname] nor [default] are +# present. [default] is evaled by top-level `eval`, so be careful. Also note +# that no arguments may contain spaces, including [default] and [const]. +getopts_long() { + local positional= + local opt_bases="" + while test $# -gt 0 ; do + local arg="$1" ; shift + local opt_base= + local act= + local opt_name= + if test -z "$positional" ; then + if test "$arg" = "--" ; then + positional=0 + continue + fi + act="$1" ; shift + opt_name="$(echo "$arg" | tr '-' '_')" + opt_base="longopt_$opt_name" + else + if test "$arg" = "--" ; then + break + fi + : $(( positional+=1 )) + act="$arg" + opt_name="arg_$positional" + opt_base="positional_$positional" + fi + opt_bases="$opt_bases $opt_base" + eval "local varname_$opt_base=$opt_name" + local i=0 + for act_subarg in $act ; do + eval "local act_$(( i+=1 ))_$opt_base=\"\$act_subarg\"" + done + done + # Process options + local positional=0 + local force_positional= + while test $# -gt 0 ; do + local argument="$1" ; shift + local opt_base= + local has_equal= + local equal_arg= + local is_positional= + if test "$argument" = "--" ; then + force_positional=1 + continue + elif test -z "$force_positional" && test "${argument#--}" != "$argument" + then + local opt_name="${argument#--}" + local opt_name_striparg="${opt_name%%=*}" + if test "$opt_name" = "$opt_name_striparg" ; then + has_equal=0 + else + has_equal=1 + equal_arg="${argument#*=}" + opt_name="$opt_name_striparg" + fi + # Use trailing x to prevent stripping newlines + opt_name="$(printf '%sx' "$opt_name" | tr '-' '_')" + opt_name="${opt_name%x}" + if test -n "$(printf '%sx' "$opt_name" | tr -d 'a-z_')" ; then + getopts_error "Option contains invalid characters: $opt_name" + fi + opt_base="longopt_$opt_name" + else + : $(( positional+=1 )) + opt_base="positional_$positional" + is_positional=1 + fi + if test -n "$opt_base" ; then + eval "local occurred_$opt_base=1" + + eval "local act_1=\"\$act_1_$opt_base\"" + eval "local varname=\"\$varname_$opt_base\"" + local need_val= + local func= + case "$act_1" in + (store_const) + eval "local const=\"\${act_2_${opt_base}:-1}\"" + eval "local varname=\"\${act_3_${opt_base}:-$varname}\"" + printf 'local %s=%s\n' "$varname" "$const" + ;; + (store) + eval "varname=\"\${act_2_${opt_base}:-$varname}\"" + need_val=1 + ;; + (run) + eval "func=\"\${act_2_${opt_base}}\"" + eval "varname=\"\${act_3_${opt_base}:-$varname}\"" + printf 'local %s="$(%s)"\n' "$varname" "$func" + ;; + (modify) + eval "func=\"\${act_2_${opt_base}}\"" + eval "varname=\"\${act_3_${opt_base}:-$varname}\"" + need_val=1 + ;; + esac + if test -n "$need_val" ; then + local val= + if test -z "$is_positional" ; then + if test $has_equal = 1 ; then + val="$equal_arg" + else + if test $# -eq 0 ; then + getopts_error "Missing argument for $opt_name" + fi + val="$1" ; shift + fi + else + val="$argument" + fi + local escaped_val="'$(printf "%s" "$val" | sed "s/'/'\\\\''/g")'" + case "$act_1" in + (store) + printf 'local %s=%s\n' "$varname" "$escaped_val" + ;; + (modify) + printf 'local %s="$(%s %s)"\n' "$varname" "$func" "$escaped_val" + ;; + esac + fi + fi + done + # Print default values when no values were provided + local opt_base= + for opt_base in $opt_bases ; do + eval "local occurred=\"\${occurred_$opt_base:-}\"" + if test -n "$occurred" ; then + continue + fi + eval "local act_1=\"\$act_1_$opt_base\"" + eval "local varname=\"\$varname_$opt_base\"" + case "$act_1" in + (store) + eval "local varname=\"\${act_2_${opt_base}:-$varname}\"" + eval "local default=\"\${act_3_${opt_base}:-}\"" + printf 'local %s=%s\n' "$varname" "$default" + ;; + (store_const|run|modify) + eval "local varname=\"\${act_3_${opt_base}:-$varname}\"" + eval "local default=\"\${act_4_${opt_base}:-}\"" + printf 'local %s=%s\n' "$varname" "$default" + ;; + esac + done +} + get_pvs_comment() { cat > pvs-comment << EOF // This is an open source non-commercial project. Dear PVS-Studio, please check @@ -62,18 +237,16 @@ install_pvs() { cd .. } -create_compile_commands() { +create_compile_commands() {( + export CC=clang + export CFLAGS=' -O0 ' + mkdir build cd build - env \ - CC=clang \ - CFLAGS=' -O0 ' \ - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" make -j"$(get_jobs_num)" find src/nvim/auto -name '*.test-include.c' -delete - - cd .. -} +)} patch_sources() { get_pvs_comment @@ -87,7 +260,7 @@ patch_sources() { fi ' - if test "x$1" != "x--only-build" ; then + if test "${1:-}" != "--only-build" ; then find \ src/nvim test/functional/fixtures test/unit/fixtures \ -name '*.c' \ @@ -117,9 +290,9 @@ run_analysis() { } do_check() { - local tgt="$1" - local branch="$2" - local pvs_url="$3" + local tgt="$1" ; shift + local branch="$1" ; shift + local pvs_url="$1" ; shift git clone --branch="$branch" . "$tgt" @@ -133,7 +306,7 @@ do_check() { } do_recheck() { - local tgt="${1}" + local tgt="$1" cd "$tgt" @@ -143,49 +316,42 @@ do_recheck() { } detect_url() { - curl -L 'https://www.viva64.com/en/pvs-studio-download-linux/' \ - | grep -o 'https\{0,1\}://[^"<>]\{1,\}/pvs-studio[^/"<>]*\.tgz' + local url="${1:-detect}" + if test "$url" = detect ; then + curl -L 'https://www.viva64.com/en/pvs-studio-download-linux/' \ + | grep -o 'https\{0,1\}://[^"<>]\{1,\}/pvs-studio[^/"<>]*\.tgz' + else + printf '%s' "$url" + fi } main() { - local pvs_url="http://files.viva64.com/pvs-studio-6.15.21741.1-x86_64.tgz" - - if test "$1" = "--help" ; then + local def_pvs_url="http://files.viva64.com/pvs-studio-6.15.21741.1-x86_64.tgz" + eval "$( + getopts_long \ + help store_const \ + pvs 'modify detect_url pvs_url "${def_pvs_url}"' \ + patch store_const \ + only-build 'store_const --only-build' \ + recheck store_const \ + -- \ + 'store tgt "$PWD/../neovim-pvs"' \ + 'store branch master' \ + -- "$@" + )" + + if test -n "$help" ; then help - return + return 0 fi set -x - if test "$1" = "--pvs" ; then - shift - pvs_url="$1" ; shift - - if test "$pvs_url" = "detect" ; then - pvs_url="$(detect_url)" - fi - fi - - if test "$1" = "--patch" ; then - shift - if test "$1" = "--only-build" ; then - shift - patch_sources --only-build - else - patch_sources - fi - exit $? + if test -n "$patch" ; then + patch_sources "$only_build" + return $? fi - local recheck= - if test "$1" = "--recheck" ; then - recheck=1 - shift - fi - - local tgt="${1:-$PWD/../neovim-pvs}" - local branch="${2:-master}" - if test -z "$recheck" ; then do_check "$tgt" "$branch" "$pvs_url" else -- cgit From 68945ead6327aa7050fd3a82f5803e007ab5d979 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 18:08:48 +0300 Subject: pvscheck: Refactor script so that it only `cd`s in a subshell [ci skip] --- scripts/pvscheck.sh | 66 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 23 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 51ecaf0c46..7e965f5edf 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -212,15 +212,20 @@ getopts_long() { } get_pvs_comment() { - cat > pvs-comment << EOF + local tgt="$1" ; shift + + cat > "$tgt/pvs-comment" << EOF // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com EOF } -install_pvs() { - local pvs_url="$1" +install_pvs() {( + local tgt="$1" ; shift + local pvs_url="$1" ; shift + + cd "$tgt" mkdir pvs-studio cd pvs-studio @@ -231,25 +236,36 @@ install_pvs() { local pvsdir="$(find . -maxdepth 1 -mindepth 1)" find "$pvsdir" -maxdepth 1 -mindepth 1 -exec mv '{}' . \; rmdir "$pvsdir" +)} - export PATH="$PWD/bin${PATH+:}${PATH}" - - cd .. +adjust_path() { + if test -d "$tgt/pvs-studio" ; then + local saved_pwd="$PWD" + cd "$tgt/pvs-studio" + export PATH="$PWD/bin${PATH+:}${PATH}" + cd "$saved_pwd" + fi } create_compile_commands() {( + local tgt="$1" ; shift + export CC=clang export CFLAGS=' -O0 ' - mkdir build - cd build + mkdir "$tgt/build" + cd "$tgt/build" + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" make -j"$(get_jobs_num)" find src/nvim/auto -name '*.test-include.c' -delete )} -patch_sources() { - get_pvs_comment +patch_sources() {( + local tgt="$1" ; shift + local only_bulid="${1:-}" + + get_pvs_comment "$tgt" local sh_script=' pvs_comment="$(cat pvs-comment ; echo -n EOS)" @@ -260,7 +276,9 @@ patch_sources() { fi ' - if test "${1:-}" != "--only-build" ; then + cd "$tgt" + + if test "$only_build" != "--only-build" ; then find \ src/nvim test/functional/fixtures test/unit/fixtures \ -name '*.c' \ @@ -273,9 +291,13 @@ patch_sources() { -exec /bin/sh -c "$sh_script" - '{}' \; rm pvs-comment -} +)} + +run_analysis() {( + local tgt="$1" ; shift + + cd "$tgt" -run_analysis() { pvs-studio-analyzer \ analyze \ --threads "$(get_jobs_num)" \ @@ -287,7 +309,7 @@ run_analysis() { plog-converter -t xml -o PVS-studio.xml PVS-studio.log plog-converter -t errorfile -o PVS-studio.err PVS-studio.log plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log -} +)} do_check() { local tgt="$1" ; shift @@ -296,23 +318,21 @@ do_check() { git clone --branch="$branch" . "$tgt" - cd "$tgt" + install_pvs "$tgt" "$pvs_url" - install_pvs "$pvs_url" + adjust_path "$tgt" - create_compile_commands + create_compile_commands "$tgt" - run_analysis + run_analysis "$tgt" } do_recheck() { local tgt="$1" - cd "$tgt" - - export PATH="$PWD/pvs-studio/bin${PATH+:}${PATH}" + adjust_path "$tgt" - run_analysis + run_analysis "$tgt" } detect_url() { @@ -348,7 +368,7 @@ main() { set -x if test -n "$patch" ; then - patch_sources "$only_build" + patch_sources "$only_build" "$tgt" return $? fi -- cgit From 97806ee6d682ca8912f95825c485d96410802138 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 18:17:12 +0300 Subject: pvscheck: Add --pvs-install mode [ci skip] --- scripts/pvscheck.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 7e965f5edf..39de763fe2 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -15,6 +15,7 @@ help() { echo 'Usage:' echo ' pvscheck.sh [--pvs URL] [target-directory [branch]]' echo ' pvscheck.sh [--pvs URL] [--recheck] [target-directory]' + echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}' echo ' pvscheck.sh --patch [--only-build]' echo echo ' --pvs: Use the specified URL as a path to pvs-studio archive.' @@ -24,12 +25,14 @@ help() { echo ' That assumes certain viva64.com site properties and' echo ' may be broken by the site update.' echo + echo ' --only-build: (for --patch) Only patch files in ./build directory.' + echo + echo ' --pvs-install: Only install PVS-studio to the specified location.' + echo echo ' --patch: patch sources in the current directory.' echo ' Does not patch already patched files.' echo ' Does not run analysis.' echo - echo ' --only-build: Only patch files in ./build directory.' - echo echo ' --recheck: run analysis on a prepared target directory.' echo echo ' target-directory: Directory where build should occur.' @@ -354,6 +357,7 @@ main() { patch store_const \ only-build 'store_const --only-build' \ recheck store_const \ + pvs-install store_const \ -- \ 'store tgt "$PWD/../neovim-pvs"' \ 'store branch master' \ @@ -369,13 +373,12 @@ main() { if test -n "$patch" ; then patch_sources "$only_build" "$tgt" - return $? - fi - - if test -z "$recheck" ; then - do_check "$tgt" "$branch" "$pvs_url" - else + elif test -n "$pvs_install" ; then + install_pvs "$tgt" "$pvs_url" + elif test -n "$recheck" ; then do_recheck "$tgt" + else + do_check "$tgt" "$branch" "$pvs_url" fi } -- cgit From 3638d28f68969c81242b8d7345f1d0348fce497d Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 18:24:29 +0300 Subject: pvscheck: Add --deps to build with all dependencies [ci skip] --- scripts/pvscheck.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 39de763fe2..da55965d36 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -13,7 +13,7 @@ get_jobs_num() { help() { echo 'Usage:' - echo ' pvscheck.sh [--pvs URL] [target-directory [branch]]' + echo ' pvscheck.sh [--pvs URL] [--deps] [target-directory [branch]]' echo ' pvscheck.sh [--pvs URL] [--recheck] [target-directory]' echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}' echo ' pvscheck.sh --patch [--only-build]' @@ -25,6 +25,10 @@ help() { echo ' That assumes certain viva64.com site properties and' echo ' may be broken by the site update.' echo + echo ' --deps: (for regular run) Use top-level Makefile and build deps.' + echo ' Without this it assumes all dependencies are already' + echo ' installed.' + echo echo ' --only-build: (for --patch) Only patch files in ./build directory.' echo echo ' --pvs-install: Only install PVS-studio to the specified location.' @@ -252,15 +256,22 @@ adjust_path() { create_compile_commands() {( local tgt="$1" ; shift + local deps="$1" ; shift export CC=clang export CFLAGS=' -O0 ' - mkdir "$tgt/build" - cd "$tgt/build" + if test -z "$deps" ; then + mkdir "$tgt/build" + cd "$tgt/build" + + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" + make -j"$(get_jobs_num)" + else + cd "$tgt" - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" - make -j"$(get_jobs_num)" + make -j"$(get_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " + fi find src/nvim/auto -name '*.test-include.c' -delete )} @@ -318,6 +329,7 @@ do_check() { local tgt="$1" ; shift local branch="$1" ; shift local pvs_url="$1" ; shift + local deps="$1" ; shift git clone --branch="$branch" . "$tgt" @@ -325,7 +337,7 @@ do_check() { adjust_path "$tgt" - create_compile_commands "$tgt" + create_compile_commands "$tgt" "$deps" run_analysis "$tgt" } @@ -358,6 +370,7 @@ main() { only-build 'store_const --only-build' \ recheck store_const \ pvs-install store_const \ + deps store_const \ -- \ 'store tgt "$PWD/../neovim-pvs"' \ 'store branch master' \ @@ -378,7 +391,7 @@ main() { elif test -n "$recheck" ; then do_recheck "$tgt" else - do_check "$tgt" "$branch" "$pvs_url" + do_check "$tgt" "$branch" "$pvs_url" "$deps" fi } -- cgit From 0c6e0460b6f15dce8dd5f517712093d843d76058 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 18:33:41 +0300 Subject: pvscheck: When using --recheck rerun build [ci skip] --- scripts/pvscheck.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index da55965d36..67834cca8a 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -262,7 +262,7 @@ create_compile_commands() {( export CFLAGS=' -O0 ' if test -z "$deps" ; then - mkdir "$tgt/build" + mkdir -p "$tgt/build" cd "$tgt/build" cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" @@ -347,6 +347,8 @@ do_recheck() { adjust_path "$tgt" + create_compile_commands "$tgt" "$deps" + run_analysis "$tgt" } -- cgit From 4f4d21693bb1665f1a398fb58dc2c554ba7b4eba Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 2 May 2017 21:53:16 +0300 Subject: pvscheck: Use absolute path for finding test-include.c It was currently unknown in which directory create_compile_commands will end up in. [ci skip] --- scripts/pvscheck.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 67834cca8a..c75dd2ab76 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -263,16 +263,29 @@ create_compile_commands() {( if test -z "$deps" ; then mkdir -p "$tgt/build" - cd "$tgt/build" + ( + cd "$tgt/build" - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" - make -j"$(get_jobs_num)" + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" + make -j"$(get_jobs_num)" + ) else - cd "$tgt" + ( + cd "$tgt" - make -j"$(get_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " + make -j"$(get_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " + ) fi - find src/nvim/auto -name '*.test-include.c' -delete + find "$tgt/build/src/nvim/auto" -name '*.test-include.c' -delete +)} + +# Warning: realdir below only cares about directories unlike realpath. +# +# realpath is not available in Ubuntu trusty yet. +realdir() {( + local dir="$1" + cd "$dir" + printf '%s\n' "$PWD" )} patch_sources() {( @@ -374,7 +387,7 @@ main() { pvs-install store_const \ deps store_const \ -- \ - 'store tgt "$PWD/../neovim-pvs"' \ + 'modify realdir tgt "$PWD/../neovim-pvs"' \ 'store branch master' \ -- "$@" )" -- cgit From d72df05b930c7dd79f138ec371124329eb9c9259 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:35:50 +0300 Subject: pvscheck: Add --only-analyse mode --- scripts/pvscheck.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index c75dd2ab76..79ed08f458 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -14,7 +14,7 @@ get_jobs_num() { help() { echo 'Usage:' echo ' pvscheck.sh [--pvs URL] [--deps] [target-directory [branch]]' - echo ' pvscheck.sh [--pvs URL] [--recheck] [target-directory]' + echo ' pvscheck.sh [--pvs URL] [--recheck|--only-analyse] [target-directory]' echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}' echo ' pvscheck.sh --patch [--only-build]' echo @@ -39,6 +39,9 @@ help() { echo echo ' --recheck: run analysis on a prepared target directory.' echo + echo ' --only-analyse: run analysis on a prepared target directory ' + echo ' without building Neovim.' + echo echo ' target-directory: Directory where build should occur.' echo ' Default: ../neovim-pvs' echo @@ -348,20 +351,23 @@ do_check() { install_pvs "$tgt" "$pvs_url" - adjust_path "$tgt" + do_recheck "$tgt" "$deps" +} + +do_recheck() { + local tgt="$1" ; shift + local deps="$2" ; shift create_compile_commands "$tgt" "$deps" - run_analysis "$tgt" + do_analysis "$tgt" } -do_recheck() { - local tgt="$1" +do_analysis() { + local tgt="$1" ; shift adjust_path "$tgt" - create_compile_commands "$tgt" "$deps" - run_analysis "$tgt" } @@ -384,6 +390,7 @@ main() { patch store_const \ only-build 'store_const --only-build' \ recheck store_const \ + only-analyse store_const \ pvs-install store_const \ deps store_const \ -- \ @@ -404,7 +411,9 @@ main() { elif test -n "$pvs_install" ; then install_pvs "$tgt" "$pvs_url" elif test -n "$recheck" ; then - do_recheck "$tgt" + do_recheck "$tgt" "$deps" + elif test -n "$only_analyse" ; then + do_analysis "$tgt" else do_check "$tgt" "$branch" "$pvs_url" "$deps" fi -- cgit From 7f24736ebc050a9b81d4d2db0158111486b1836b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:44:23 +0300 Subject: pvscheck: Handle invalid option error gracefully --- scripts/pvscheck.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 79ed08f458..949021a174 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -50,7 +50,17 @@ help() { } getopts_error() { - printf '%s\n' "$1" >&2 + local msg="$1" ; shift + local do_help= + if test "$msg" = "--help" ; then + msg="$1" ; shift + do_help=1 + fi + printf '%s\n' "$msg" >&2 + if test -n "$do_help" ; then + printf '\n' >&2 + help >&2 + fi echo 'return 1' return 1 } @@ -146,8 +156,8 @@ getopts_long() { if test -n "$opt_base" ; then eval "local occurred_$opt_base=1" - eval "local act_1=\"\$act_1_$opt_base\"" - eval "local varname=\"\$varname_$opt_base\"" + eval "local act_1=\"\${act_1_$opt_base:-}\"" + eval "local varname=\"\${varname_$opt_base:-}\"" local need_val= local func= case "$act_1" in @@ -170,6 +180,9 @@ getopts_long() { eval "varname=\"\${act_3_${opt_base}:-$varname}\"" need_val=1 ;; + ("") + getopts_error --help "Wrong argument: $argument" + ;; esac if test -n "$need_val" ; then local val= -- cgit From c585a72cdc6d2cb7f507c59eb4a6981e54c77ebc Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 05:06:16 +0300 Subject: pvscheck: Provide arguments to `patch_sources` in correct order --- scripts/pvscheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 949021a174..ca85b6be7f 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -306,7 +306,7 @@ realdir() {( patch_sources() {( local tgt="$1" ; shift - local only_bulid="${1:-}" + local only_bulid="${1}" ; shift get_pvs_comment "$tgt" @@ -420,7 +420,7 @@ main() { set -x if test -n "$patch" ; then - patch_sources "$only_build" "$tgt" + patch_sources "$tgt" "$only_build" elif test -n "$pvs_install" ; then install_pvs "$tgt" "$pvs_url" elif test -n "$recheck" ; then -- cgit From 90f20bd7b17a4c6889136008593312f8f8fe377b Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 9 Jun 2017 16:42:43 -0400 Subject: pvscheck: Fix argument handling in do_recheck [ci skip] --- scripts/pvscheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index ca85b6be7f..d6d28e3c6c 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -369,7 +369,7 @@ do_check() { do_recheck() { local tgt="$1" ; shift - local deps="$2" ; shift + local deps="$1" ; shift create_compile_commands "$tgt" "$deps" -- cgit From 45df8f77dff1083ec518427289533ec05f1ff0c3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 15 Jun 2017 19:01:11 +0200 Subject: scripts/pvscheck.sh: fixes [ci skip] --- scripts/pvscheck.sh | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index d6d28e3c6c..535f14beb4 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -1,14 +1,15 @@ #!/bin/sh + +# Assume that "local" is available. +# shellcheck disable=SC2039 + set -e # Note: -u causes problems with posh, it barks at “undefined” $@ when no # arguments provided. test -z "$POSH_VERSION" && set -u -get_jobs_num() { - local num="$(cat /proc/cpuinfo | grep -c "^processor")" - num="$(echo $(( num + 1 )))" - num="${num:-1}" - echo $num +echo_jobs_num() { + echo $(( $(grep -c "^processor" /proc/cpuinfo) + 1 )) } help() { @@ -21,7 +22,7 @@ help() { echo ' --pvs: Use the specified URL as a path to pvs-studio archive.' echo ' By default latest tested version is used.' echo - echo ' May use `--pvs detect` to try detecting latest version.' + echo ' May use "--pvs detect" to try detecting latest version.' echo ' That assumes certain viva64.com site properties and' echo ' may be broken by the site update.' echo @@ -261,15 +262,6 @@ install_pvs() {( rmdir "$pvsdir" )} -adjust_path() { - if test -d "$tgt/pvs-studio" ; then - local saved_pwd="$PWD" - cd "$tgt/pvs-studio" - export PATH="$PWD/bin${PATH+:}${PATH}" - cd "$saved_pwd" - fi -} - create_compile_commands() {( local tgt="$1" ; shift local deps="$1" ; shift @@ -283,13 +275,13 @@ create_compile_commands() {( cd "$tgt/build" cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" - make -j"$(get_jobs_num)" + make -j"$(echo_jobs_num)" ) else ( cd "$tgt" - make -j"$(get_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " + make -j"$(echo_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " ) fi find "$tgt/build/src/nvim/auto" -name '*.test-include.c' -delete @@ -379,7 +371,12 @@ do_recheck() { do_analysis() { local tgt="$1" ; shift - adjust_path "$tgt" + if test -d "$tgt/pvs-studio" ; then + local saved_pwd="$PWD" + cd "$tgt/pvs-studio" + export PATH="$PWD/bin${PATH+:}${PATH}" + cd "$saved_pwd" + fi run_analysis "$tgt" } -- cgit From a46970449540e327dd858b597dbfad0a2c1fb48a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 25 Jun 2017 03:26:04 +0200 Subject: scripts/pvscheck.sh: HACK: de-parallelize on CI References https://github.com/neovim/bot-ci/pull/105 --- scripts/pvscheck.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 535f14beb4..b3ca2c0fb8 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -9,7 +9,9 @@ set -e test -z "$POSH_VERSION" && set -u echo_jobs_num() { - echo $(( $(grep -c "^processor" /proc/cpuinfo) + 1 )) + [ -n "$TRAVIS_CI_BUILD" ] \ + && echo 1 \ + || echo $(( $(grep -c "^processor" /proc/cpuinfo) + 1 )) } help() { -- cgit From 4b08b5d1942ac12c54b959ec4bb2c5e13b2de587 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 25 Jun 2017 07:35:01 +0200 Subject: scripts/pvscheck.sh: HACK: de-parallelize on CI https://github.com/neovim/bot-ci/pull/105#issuecomment-309282132 --- scripts/pvscheck.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index b3ca2c0fb8..575648c688 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -9,9 +9,12 @@ set -e test -z "$POSH_VERSION" && set -u echo_jobs_num() { - [ -n "$TRAVIS_CI_BUILD" ] \ - && echo 1 \ - || echo $(( $(grep -c "^processor" /proc/cpuinfo) + 1 )) + if [ -n "${TRAVIS:-}" ] ; then + # HACK: /proc/cpuinfo on Travis CI is misleading, so hardcode 1. + echo 1 + else + echo $(( $(grep -c "^processor" /proc/cpuinfo) + 1 )) + fi } help() { -- cgit From 2b377d89dbe4174a74e021ffe4e8b86d0d729d0e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 25 Jun 2017 07:52:21 +0200 Subject: scripts/pvscheck.sh: fix function rename --- scripts/pvscheck.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 575648c688..dfdc539bf9 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -8,7 +8,7 @@ set -e # arguments provided. test -z "$POSH_VERSION" && set -u -echo_jobs_num() { +get_jobs_num() { if [ -n "${TRAVIS:-}" ] ; then # HACK: /proc/cpuinfo on Travis CI is misleading, so hardcode 1. echo 1 @@ -280,13 +280,13 @@ create_compile_commands() {( cd "$tgt/build" cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root" - make -j"$(echo_jobs_num)" + make -j"$(get_jobs_num)" ) else ( cd "$tgt" - make -j"$(echo_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " + make -j"$(get_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug " ) fi find "$tgt/build/src/nvim/auto" -name '*.test-include.c' -delete -- cgit From aa3e3b4ca641cd87b1c051f740f16bd11f57197d Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 4 Jul 2017 19:22:48 +0300 Subject: pvscheck: Add --environment-cc switch To be used to make bot-ci able to use clang-4.0 without hacks. [ci skip] --- scripts/pvscheck.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index dfdc539bf9..e4536b3dce 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -19,8 +19,11 @@ get_jobs_num() { help() { echo 'Usage:' - echo ' pvscheck.sh [--pvs URL] [--deps] [target-directory [branch]]' - echo ' pvscheck.sh [--pvs URL] [--recheck|--only-analyse] [target-directory]' + echo ' pvscheck.sh [--pvs URL] [--deps] [--environment-cc]' + echo ' [target-directory [branch]]' + echo ' pvscheck.sh [--pvs URL] [--recheck] [--environment-cc]' + echo ' [target-directory]' + echo ' pvscheck.sh [--pvs URL] --only-analyse [target-directory]' echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}' echo ' pvscheck.sh --patch [--only-build]' echo @@ -35,6 +38,9 @@ help() { echo ' Without this it assumes all dependencies are already' echo ' installed.' echo + echo ' --environment-cc: (for regular run and --recheck) Do not export' + echo ' CC=clang. Build is still run with CFLAGS=-O0.' + echo echo ' --only-build: (for --patch) Only patch files in ./build directory.' echo echo ' --pvs-install: Only install PVS-studio to the specified location.' @@ -270,8 +276,11 @@ install_pvs() {( create_compile_commands() {( local tgt="$1" ; shift local deps="$1" ; shift + local environment_cc="$1" ; shift - export CC=clang + if test -z "$environment_cc" ; then + export CC=clang + fi export CFLAGS=' -O0 ' if test -z "$deps" ; then @@ -356,19 +365,21 @@ do_check() { local branch="$1" ; shift local pvs_url="$1" ; shift local deps="$1" ; shift + local environment_cc="$1" ; shift git clone --branch="$branch" . "$tgt" install_pvs "$tgt" "$pvs_url" - do_recheck "$tgt" "$deps" + do_recheck "$tgt" "$deps" "$environment_cc" } do_recheck() { local tgt="$1" ; shift local deps="$1" ; shift + local environment_cc="$1" ; shift - create_compile_commands "$tgt" "$deps" + create_compile_commands "$tgt" "$deps" "$environment_cc" do_analysis "$tgt" } @@ -408,6 +419,7 @@ main() { only-analyse store_const \ pvs-install store_const \ deps store_const \ + environment-cc store_const \ -- \ 'modify realdir tgt "$PWD/../neovim-pvs"' \ 'store branch master' \ @@ -426,11 +438,11 @@ main() { elif test -n "$pvs_install" ; then install_pvs "$tgt" "$pvs_url" elif test -n "$recheck" ; then - do_recheck "$tgt" "$deps" + do_recheck "$tgt" "$deps" "$environment_cc" elif test -n "$only_analyse" ; then do_analysis "$tgt" else - do_check "$tgt" "$branch" "$pvs_url" "$deps" + do_check "$tgt" "$branch" "$pvs_url" "$deps" "$environment_cc" fi } -- cgit From 84d9245c70c2c65668e0b56beee7f4dcd8ea3644 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 21 Nov 2017 01:31:34 +0100 Subject: pvscheck.sh: auto-detect URL by default The hardcoded URL breaks very often, this confuses people. Instead, auto-detect if no URL is provided. Also auto-detect if the script is invoked with no arguments. --- scripts/pvscheck.sh | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'scripts/pvscheck.sh') diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index e4536b3dce..30c4d296d7 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -27,12 +27,8 @@ help() { echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}' echo ' pvscheck.sh --patch [--only-build]' echo - echo ' --pvs: Use the specified URL as a path to pvs-studio archive.' - echo ' By default latest tested version is used.' - echo - echo ' May use "--pvs detect" to try detecting latest version.' - echo ' That assumes certain viva64.com site properties and' - echo ' may be broken by the site update.' + echo ' --pvs: Fetch pvs-studio from URL.' + echo ' --pvs detect: Auto-detect latest version (by scraping viva64.com).' echo echo ' --deps: (for regular run) Use top-level Makefile and build deps.' echo ' Without this it assumes all dependencies are already' @@ -360,6 +356,17 @@ run_analysis() {( plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log )} +detect_url() { + local url="${1:-detect}" + if test "$url" = detect ; then + curl --silent -L 'https://www.viva64.com/en/pvs-studio-download-linux/' \ + | grep -o 'https\{0,1\}://[^"<>]\{1,\}/pvs-studio[^/"<>]*\.tgz' \ + || echo FAILED + else + printf '%s' "$url" + fi +} + do_check() { local tgt="$1" ; shift local branch="$1" ; shift @@ -367,6 +374,15 @@ do_check() { local deps="$1" ; shift local environment_cc="$1" ; shift + if test -z "$pvs_url" || test "$pvs_url" = FAILED ; then + pvs_url="$(detect_url detect)" + if test -z "$pvs_url" || test "$pvs_url" = FAILED ; then + echo "failed to auto-detect PVS URL" + exit 1 + fi + echo "Auto-detected PVS URL: ${pvs_url}" + fi + git clone --branch="$branch" . "$tgt" install_pvs "$tgt" "$pvs_url" @@ -397,22 +413,11 @@ do_analysis() { run_analysis "$tgt" } -detect_url() { - local url="${1:-detect}" - if test "$url" = detect ; then - curl -L 'https://www.viva64.com/en/pvs-studio-download-linux/' \ - | grep -o 'https\{0,1\}://[^"<>]\{1,\}/pvs-studio[^/"<>]*\.tgz' - else - printf '%s' "$url" - fi -} - main() { - local def_pvs_url="http://files.viva64.com/pvs-studio-6.15.21741.1-x86_64.tgz" eval "$( getopts_long \ help store_const \ - pvs 'modify detect_url pvs_url "${def_pvs_url}"' \ + pvs 'modify detect_url pvs_url' \ patch store_const \ only-build 'store_const --only-build' \ recheck store_const \ @@ -431,7 +436,7 @@ main() { return 0 fi - set -x + # set -x if test -n "$patch" ; then patch_sources "$tgt" "$only_build" -- cgit