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