2017-04-10 03:24:31 -07:00
|
|
|
|
#!/bin/sh
|
2017-06-15 10:01:11 -07:00
|
|
|
|
|
|
|
|
|
# Assume that "local" is available.
|
|
|
|
|
# shellcheck disable=SC2039
|
|
|
|
|
|
2017-04-10 03:24:31 -07:00
|
|
|
|
set -e
|
2017-05-02 07:56:30 -07:00
|
|
|
|
# Note: -u causes problems with posh, it barks at “undefined” $@ when no
|
|
|
|
|
# arguments provided.
|
|
|
|
|
test -z "$POSH_VERSION" && set -u
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2019-01-07 16:29:44 -07:00
|
|
|
|
log_info() {
|
|
|
|
|
>&2 printf "pvscheck.sh: %s\n" "$@"
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-24 22:52:21 -07:00
|
|
|
|
get_jobs_num() {
|
2017-06-24 22:35:01 -07:00
|
|
|
|
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
|
2017-04-10 03:24:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 04:07:26 -07:00
|
|
|
|
help() {
|
|
|
|
|
echo 'Usage:'
|
2017-07-04 09:22:48 -07:00
|
|
|
|
echo ' pvscheck.sh [--pvs URL] [--deps] [--environment-cc]'
|
|
|
|
|
echo ' [target-directory [branch]]'
|
2018-04-16 15:35:59 -07:00
|
|
|
|
echo ' pvscheck.sh [--pvs URL] [--recheck] [--environment-cc] [--update]'
|
2017-07-04 09:22:48 -07:00
|
|
|
|
echo ' [target-directory]'
|
|
|
|
|
echo ' pvscheck.sh [--pvs URL] --only-analyse [target-directory]'
|
2017-05-02 08:17:12 -07:00
|
|
|
|
echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}'
|
2017-04-19 09:08:27 -07:00
|
|
|
|
echo ' pvscheck.sh --patch [--only-build]'
|
2017-04-10 04:07:26 -07:00
|
|
|
|
echo
|
2017-11-20 17:31:34 -07:00
|
|
|
|
echo ' --pvs: Fetch pvs-studio from URL.'
|
2018-04-16 15:35:59 -07:00
|
|
|
|
echo
|
2017-11-20 17:31:34 -07:00
|
|
|
|
echo ' --pvs detect: Auto-detect latest version (by scraping viva64.com).'
|
2017-05-01 16:08:16 -07:00
|
|
|
|
echo
|
2017-05-02 08:24:29 -07:00
|
|
|
|
echo ' --deps: (for regular run) Use top-level Makefile and build deps.'
|
|
|
|
|
echo ' Without this it assumes all dependencies are already'
|
|
|
|
|
echo ' installed.'
|
|
|
|
|
echo
|
2017-07-04 09:22:48 -07:00
|
|
|
|
echo ' --environment-cc: (for regular run and --recheck) Do not export'
|
|
|
|
|
echo ' CC=clang. Build is still run with CFLAGS=-O0.'
|
|
|
|
|
echo
|
2017-05-02 08:17:12 -07:00
|
|
|
|
echo ' --only-build: (for --patch) Only patch files in ./build directory.'
|
|
|
|
|
echo
|
|
|
|
|
echo ' --pvs-install: Only install PVS-studio to the specified location.'
|
|
|
|
|
echo
|
2017-04-19 08:55:32 -07:00
|
|
|
|
echo ' --patch: patch sources in the current directory.'
|
2017-04-19 09:04:00 -07:00
|
|
|
|
echo ' Does not patch already patched files.'
|
2017-04-19 08:55:32 -07:00
|
|
|
|
echo ' Does not run analysis.'
|
2017-04-10 04:07:26 -07:00
|
|
|
|
echo
|
2017-04-19 08:55:32 -07:00
|
|
|
|
echo ' --recheck: run analysis on a prepared target directory.'
|
|
|
|
|
echo
|
2018-04-16 15:35:59 -07:00
|
|
|
|
echo ' --update: when rechecking first do a pull.'
|
|
|
|
|
echo
|
2017-05-19 17:35:50 -07:00
|
|
|
|
echo ' --only-analyse: run analysis on a prepared target directory '
|
|
|
|
|
echo ' without building Neovim.'
|
|
|
|
|
echo
|
2017-04-19 08:55:32 -07:00
|
|
|
|
echo ' target-directory: Directory where build should occur.'
|
2017-04-10 04:07:26 -07:00
|
|
|
|
echo ' Default: ../neovim-pvs'
|
|
|
|
|
echo
|
2017-04-19 08:55:32 -07:00
|
|
|
|
echo ' branch: Branch to check.'
|
|
|
|
|
echo ' Default: master.'
|
2017-04-10 04:07:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 07:56:30 -07:00
|
|
|
|
getopts_error() {
|
2017-05-19 17:44:23 -07:00
|
|
|
|
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
|
2017-05-02 07:56:30 -07:00
|
|
|
|
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"
|
|
|
|
|
|
2017-05-19 17:44:23 -07:00
|
|
|
|
eval "local act_1=\"\${act_1_$opt_base:-}\""
|
|
|
|
|
eval "local varname=\"\${varname_$opt_base:-}\""
|
2017-05-02 07:56:30 -07:00
|
|
|
|
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
|
|
|
|
|
;;
|
2017-05-19 17:44:23 -07:00
|
|
|
|
("")
|
|
|
|
|
getopts_error --help "Wrong argument: $argument"
|
|
|
|
|
;;
|
2017-05-02 07:56:30 -07:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 03:24:31 -07:00
|
|
|
|
get_pvs_comment() {
|
2017-05-02 08:08:48 -07:00
|
|
|
|
local tgt="$1" ; shift
|
|
|
|
|
|
|
|
|
|
cat > "$tgt/pvs-comment" << EOF
|
2017-04-19 08:55:32 -07:00
|
|
|
|
// 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
|
2017-04-19 09:11:37 -07:00
|
|
|
|
|
2017-04-10 03:24:31 -07:00
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 08:08:48 -07:00
|
|
|
|
install_pvs() {(
|
|
|
|
|
local tgt="$1" ; shift
|
|
|
|
|
local pvs_url="$1" ; shift
|
|
|
|
|
|
|
|
|
|
cd "$tgt"
|
2017-05-01 16:08:16 -07:00
|
|
|
|
|
2019-01-07 16:29:44 -07:00
|
|
|
|
if test -d pvs-studio ; then
|
|
|
|
|
log_info 'install_pvs: "pvs-studio" directory already exists, skipping install'
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2017-04-10 03:24:31 -07:00
|
|
|
|
mkdir pvs-studio
|
|
|
|
|
cd pvs-studio
|
|
|
|
|
|
2017-05-01 16:08:16 -07:00
|
|
|
|
curl -L -o pvs-studio.tar.gz "$pvs_url"
|
2017-04-10 03:24:31 -07:00
|
|
|
|
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"
|
2017-05-02 08:08:48 -07:00
|
|
|
|
)}
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-05-02 07:56:30 -07:00
|
|
|
|
create_compile_commands() {(
|
2017-05-02 08:08:48 -07:00
|
|
|
|
local tgt="$1" ; shift
|
2017-05-02 08:24:29 -07:00
|
|
|
|
local deps="$1" ; shift
|
2017-07-04 09:22:48 -07:00
|
|
|
|
local environment_cc="$1" ; shift
|
2017-05-02 08:08:48 -07:00
|
|
|
|
|
2017-07-04 09:22:48 -07:00
|
|
|
|
if test -z "$environment_cc" ; then
|
|
|
|
|
export CC=clang
|
|
|
|
|
fi
|
2017-05-02 07:56:30 -07:00
|
|
|
|
export CFLAGS=' -O0 '
|
|
|
|
|
|
2017-05-02 08:24:29 -07:00
|
|
|
|
if test -z "$deps" ; then
|
2017-05-02 08:33:41 -07:00
|
|
|
|
mkdir -p "$tgt/build"
|
2017-05-02 11:53:16 -07:00
|
|
|
|
(
|
|
|
|
|
cd "$tgt/build"
|
2017-05-02 08:24:29 -07:00
|
|
|
|
|
2017-05-02 11:53:16 -07:00
|
|
|
|
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/root"
|
2017-06-24 22:52:21 -07:00
|
|
|
|
make -j"$(get_jobs_num)"
|
2017-05-02 11:53:16 -07:00
|
|
|
|
)
|
2017-05-02 08:24:29 -07:00
|
|
|
|
else
|
2017-05-02 11:53:16 -07:00
|
|
|
|
(
|
|
|
|
|
cd "$tgt"
|
2017-05-02 08:08:48 -07:00
|
|
|
|
|
2017-06-24 22:52:21 -07:00
|
|
|
|
make -j"$(get_jobs_num)" CMAKE_EXTRA_FLAGS=" -DCMAKE_INSTALL_PREFIX=$PWD/root -DCMAKE_BUILD_TYPE=Debug "
|
2017-05-02 11:53:16 -07:00
|
|
|
|
)
|
2017-05-02 08:24:29 -07:00
|
|
|
|
fi
|
2017-05-02 11:53:16 -07:00
|
|
|
|
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"
|
2018-04-01 14:07:05 -07:00
|
|
|
|
local add=""
|
|
|
|
|
while ! cd "$dir" 2>/dev/null ; do
|
|
|
|
|
add="${dir##*/}/$add"
|
|
|
|
|
local new_dir="${dir%/*}"
|
|
|
|
|
if test "$new_dir" = "$dir" ; then
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
dir="$new_dir"
|
|
|
|
|
done
|
|
|
|
|
printf '%s\n' "$PWD/$add"
|
2017-05-02 07:56:30 -07:00
|
|
|
|
)}
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-05-02 08:08:48 -07:00
|
|
|
|
patch_sources() {(
|
|
|
|
|
local tgt="$1" ; shift
|
2022-10-23 01:17:45 -07:00
|
|
|
|
local only_build="${1}" ; shift
|
2017-05-02 08:08:48 -07:00
|
|
|
|
|
|
|
|
|
get_pvs_comment "$tgt"
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
|
|
|
|
local sh_script='
|
2017-04-19 09:04:00 -07:00
|
|
|
|
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
|
2017-04-10 03:24:31 -07:00
|
|
|
|
'
|
|
|
|
|
|
2017-05-02 08:08:48 -07:00
|
|
|
|
cd "$tgt"
|
|
|
|
|
|
|
|
|
|
if test "$only_build" != "--only-build" ; then
|
2017-04-19 09:08:27 -07:00
|
|
|
|
find \
|
|
|
|
|
src/nvim test/functional/fixtures test/unit/fixtures \
|
2020-11-10 07:52:45 -07:00
|
|
|
|
\( -name '*.c' -a '!' -path '*xdiff*' \) \
|
2017-04-19 09:08:27 -07:00
|
|
|
|
-exec /bin/sh -c "$sh_script" - '{}' \;
|
|
|
|
|
fi
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
|
|
|
|
find \
|
|
|
|
|
build/src/nvim/auto build/config \
|
2017-04-19 09:04:00 -07:00
|
|
|
|
-name '*.c' -not -name '*.test-include.c' \
|
2017-04-10 03:24:31 -07:00
|
|
|
|
-exec /bin/sh -c "$sh_script" - '{}' \;
|
2017-04-19 08:55:32 -07:00
|
|
|
|
|
|
|
|
|
rm pvs-comment
|
2017-05-02 08:08:48 -07:00
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
run_analysis() {(
|
|
|
|
|
local tgt="$1" ; shift
|
|
|
|
|
|
|
|
|
|
cd "$tgt"
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2020-11-10 07:42:28 -07:00
|
|
|
|
if [ ! -r PVS-Studio.lic ]; then
|
|
|
|
|
pvs-studio-analyzer credentials -o PVS-Studio.lic 'PVS-Studio Free' 'FREE-FREE-FREE-FREE'
|
|
|
|
|
fi
|
|
|
|
|
|
2018-03-11 15:01:44 -07:00
|
|
|
|
# pvs-studio-analyzer exits with a non-zero exit code when there are detected
|
|
|
|
|
# errors, so ignore its return
|
2017-04-10 04:07:26 -07:00
|
|
|
|
pvs-studio-analyzer \
|
|
|
|
|
analyze \
|
2020-11-10 07:42:28 -07:00
|
|
|
|
--lic-file PVS-Studio.lic \
|
2017-04-10 04:07:26 -07:00
|
|
|
|
--threads "$(get_jobs_num)" \
|
2021-10-05 05:02:49 -07:00
|
|
|
|
--exclude-path src/cjson \
|
2021-09-24 03:26:31 -07:00
|
|
|
|
--exclude-path src/xdiff \
|
2023-10-07 13:00:29 -07:00
|
|
|
|
--exclude-path build \
|
2017-04-10 04:07:26 -07:00
|
|
|
|
--output-file PVS-studio.log \
|
|
|
|
|
--file build/compile_commands.json \
|
2019-01-19 14:13:58 -07:00
|
|
|
|
--sourcetree-root . || true
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2018-04-16 15:14:55 -07:00
|
|
|
|
rm -rf PVS-studio.{xml,err,tsk,html.d}
|
2022-07-28 23:44:18 -07:00
|
|
|
|
local plog_args="PVS-studio.log --srcRoot . --excludedCodes V002,V011,V1028,V1042,V1051,V1074"
|
2018-04-22 10:54:17 -07:00
|
|
|
|
plog-converter $plog_args --renderTypes xml --output PVS-studio.xml
|
|
|
|
|
plog-converter $plog_args --renderTypes errorfile --output PVS-studio.err
|
|
|
|
|
plog-converter $plog_args --renderTypes tasklist --output PVS-studio.tsk
|
|
|
|
|
plog-converter $plog_args --renderTypes fullhtml --output PVS-studio.html.d
|
2017-05-02 08:08:48 -07:00
|
|
|
|
)}
|
2017-04-10 03:41:09 -07:00
|
|
|
|
|
2017-11-20 17:31:34 -07:00
|
|
|
|
detect_url() {
|
|
|
|
|
local url="${1:-detect}"
|
|
|
|
|
if test "$url" = detect ; then
|
2021-04-29 17:01:50 -07:00
|
|
|
|
curl --silent -L 'https://pvs-studio.com/en/pvs-studio/download-all/' \
|
2019-01-13 16:23:28 -07:00
|
|
|
|
| grep -o 'https\{0,1\}://[^"<>]\{1,\}/pvs-studio[^/"<>]*-x86_64\.tgz' \
|
2017-11-20 17:31:34 -07:00
|
|
|
|
|| echo FAILED
|
|
|
|
|
else
|
|
|
|
|
printf '%s' "$url"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 04:07:26 -07:00
|
|
|
|
do_check() {
|
2017-05-02 07:56:30 -07:00
|
|
|
|
local tgt="$1" ; shift
|
|
|
|
|
local branch="$1" ; shift
|
|
|
|
|
local pvs_url="$1" ; shift
|
2017-05-02 08:24:29 -07:00
|
|
|
|
local deps="$1" ; shift
|
2017-07-04 09:22:48 -07:00
|
|
|
|
local environment_cc="$1" ; shift
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-11-20 17:31:34 -07:00
|
|
|
|
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
|
|
|
|
|
|
2017-04-10 03:47:31 -07:00
|
|
|
|
git clone --branch="$branch" . "$tgt"
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-05-02 08:08:48 -07:00
|
|
|
|
install_pvs "$tgt" "$pvs_url"
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2018-04-16 15:35:59 -07:00
|
|
|
|
do_recheck "$tgt" "$deps" "$environment_cc" ""
|
2017-05-19 17:35:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_recheck() {
|
|
|
|
|
local tgt="$1" ; shift
|
2017-06-09 13:42:43 -07:00
|
|
|
|
local deps="$1" ; shift
|
2017-07-04 09:22:48 -07:00
|
|
|
|
local environment_cc="$1" ; shift
|
2018-04-16 15:35:59 -07:00
|
|
|
|
local update="$1" ; shift
|
|
|
|
|
|
|
|
|
|
if test -n "$update" ; then
|
|
|
|
|
(
|
|
|
|
|
cd "$tgt"
|
|
|
|
|
local branch="$(git rev-parse --abbrev-ref HEAD)"
|
|
|
|
|
git checkout --detach
|
|
|
|
|
git fetch -f origin "${branch}:${branch}"
|
|
|
|
|
git checkout -f "$branch"
|
|
|
|
|
)
|
|
|
|
|
fi
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-07-04 09:22:48 -07:00
|
|
|
|
create_compile_commands "$tgt" "$deps" "$environment_cc"
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-05-19 17:35:50 -07:00
|
|
|
|
do_analysis "$tgt"
|
2017-04-10 04:07:26 -07:00
|
|
|
|
}
|
2017-04-10 03:24:31 -07:00
|
|
|
|
|
2017-05-19 17:35:50 -07:00
|
|
|
|
do_analysis() {
|
|
|
|
|
local tgt="$1" ; shift
|
2017-04-10 04:07:26 -07:00
|
|
|
|
|
2017-06-15 10:01:11 -07:00
|
|
|
|
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
|
2017-04-10 04:07:26 -07:00
|
|
|
|
|
2017-05-02 08:08:48 -07:00
|
|
|
|
run_analysis "$tgt"
|
2017-04-10 04:07:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
2017-05-02 07:56:30 -07:00
|
|
|
|
eval "$(
|
|
|
|
|
getopts_long \
|
|
|
|
|
help store_const \
|
2017-11-20 17:31:34 -07:00
|
|
|
|
pvs 'modify detect_url pvs_url' \
|
2017-05-02 07:56:30 -07:00
|
|
|
|
patch store_const \
|
|
|
|
|
only-build 'store_const --only-build' \
|
|
|
|
|
recheck store_const \
|
2017-05-19 17:35:50 -07:00
|
|
|
|
only-analyse store_const \
|
2017-05-02 08:17:12 -07:00
|
|
|
|
pvs-install store_const \
|
2017-05-02 08:24:29 -07:00
|
|
|
|
deps store_const \
|
2017-07-04 09:22:48 -07:00
|
|
|
|
environment-cc store_const \
|
2018-04-16 15:35:59 -07:00
|
|
|
|
update store_const \
|
2017-05-02 07:56:30 -07:00
|
|
|
|
-- \
|
2017-05-02 11:53:16 -07:00
|
|
|
|
'modify realdir tgt "$PWD/../neovim-pvs"' \
|
2017-05-02 07:56:30 -07:00
|
|
|
|
'store branch master' \
|
|
|
|
|
-- "$@"
|
|
|
|
|
)"
|
|
|
|
|
|
|
|
|
|
if test -n "$help" ; then
|
2017-04-10 04:07:26 -07:00
|
|
|
|
help
|
2017-05-02 07:56:30 -07:00
|
|
|
|
return 0
|
2017-04-10 04:07:26 -07:00
|
|
|
|
fi
|
|
|
|
|
|
2017-05-02 07:56:30 -07:00
|
|
|
|
if test -n "$patch" ; then
|
2017-05-19 19:06:16 -07:00
|
|
|
|
patch_sources "$tgt" "$only_build"
|
2017-05-02 08:17:12 -07:00
|
|
|
|
elif test -n "$pvs_install" ; then
|
|
|
|
|
install_pvs "$tgt" "$pvs_url"
|
|
|
|
|
elif test -n "$recheck" ; then
|
2018-04-16 15:35:59 -07:00
|
|
|
|
do_recheck "$tgt" "$deps" "$environment_cc" "$update"
|
2017-05-19 17:35:50 -07:00
|
|
|
|
elif test -n "$only_analyse" ; then
|
|
|
|
|
do_analysis "$tgt"
|
2017-05-02 08:17:12 -07:00
|
|
|
|
else
|
2017-07-04 09:22:48 -07:00
|
|
|
|
do_check "$tgt" "$branch" "$pvs_url" "$deps" "$environment_cc"
|
2017-04-10 04:07:26 -07:00
|
|
|
|
fi
|
2017-04-10 03:24:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main "$@"
|