pvscheck: Refactor script so that it only cds in a subshell

[ci skip]
This commit is contained in:
ZyX 2017-05-02 18:08:48 +03:00
parent 4cb61aa742
commit 68945ead63

View File

@ -212,15 +212,20 @@ getopts_long() {
} }
get_pvs_comment() { 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 // 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 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
EOF EOF
} }
install_pvs() { install_pvs() {(
local pvs_url="$1" local tgt="$1" ; shift
local pvs_url="$1" ; shift
cd "$tgt"
mkdir pvs-studio mkdir pvs-studio
cd pvs-studio cd pvs-studio
@ -231,25 +236,36 @@ install_pvs() {
local pvsdir="$(find . -maxdepth 1 -mindepth 1)" local pvsdir="$(find . -maxdepth 1 -mindepth 1)"
find "$pvsdir" -maxdepth 1 -mindepth 1 -exec mv '{}' . \; find "$pvsdir" -maxdepth 1 -mindepth 1 -exec mv '{}' . \;
rmdir "$pvsdir" rmdir "$pvsdir"
)}
export PATH="$PWD/bin${PATH+:}${PATH}" adjust_path() {
if test -d "$tgt/pvs-studio" ; then
cd .. local saved_pwd="$PWD"
cd "$tgt/pvs-studio"
export PATH="$PWD/bin${PATH+:}${PATH}"
cd "$saved_pwd"
fi
} }
create_compile_commands() {( create_compile_commands() {(
local tgt="$1" ; shift
export CC=clang export CC=clang
export CFLAGS=' -O0 ' export CFLAGS=' -O0 '
mkdir build mkdir "$tgt/build"
cd build cd "$tgt/build"
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)" make -j"$(get_jobs_num)"
find src/nvim/auto -name '*.test-include.c' -delete find src/nvim/auto -name '*.test-include.c' -delete
)} )}
patch_sources() { patch_sources() {(
get_pvs_comment local tgt="$1" ; shift
local only_bulid="${1:-}"
get_pvs_comment "$tgt"
local sh_script=' local sh_script='
pvs_comment="$(cat pvs-comment ; echo -n EOS)" pvs_comment="$(cat pvs-comment ; echo -n EOS)"
@ -260,7 +276,9 @@ patch_sources() {
fi fi
' '
if test "${1:-}" != "--only-build" ; then cd "$tgt"
if test "$only_build" != "--only-build" ; then
find \ find \
src/nvim test/functional/fixtures test/unit/fixtures \ src/nvim test/functional/fixtures test/unit/fixtures \
-name '*.c' \ -name '*.c' \
@ -273,9 +291,13 @@ patch_sources() {
-exec /bin/sh -c "$sh_script" - '{}' \; -exec /bin/sh -c "$sh_script" - '{}' \;
rm pvs-comment rm pvs-comment
} )}
run_analysis() {(
local tgt="$1" ; shift
cd "$tgt"
run_analysis() {
pvs-studio-analyzer \ pvs-studio-analyzer \
analyze \ analyze \
--threads "$(get_jobs_num)" \ --threads "$(get_jobs_num)" \
@ -287,7 +309,7 @@ run_analysis() {
plog-converter -t xml -o PVS-studio.xml PVS-studio.log 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 errorfile -o PVS-studio.err PVS-studio.log
plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log plog-converter -t tasklist -o PVS-studio.tsk PVS-studio.log
} )}
do_check() { do_check() {
local tgt="$1" ; shift local tgt="$1" ; shift
@ -296,23 +318,21 @@ do_check() {
git clone --branch="$branch" . "$tgt" 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() { do_recheck() {
local tgt="$1" local tgt="$1"
cd "$tgt" adjust_path "$tgt"
export PATH="$PWD/pvs-studio/bin${PATH+:}${PATH}" run_analysis "$tgt"
run_analysis
} }
detect_url() { detect_url() {
@ -348,7 +368,7 @@ main() {
set -x set -x
if test -n "$patch" ; then if test -n "$patch" ; then
patch_sources "$only_build" patch_sources "$only_build" "$tgt"
return $? return $?
fi fi