Commit c4d10fb9 authored by Valentin Perrelle's avatar Valentin Perrelle
Browse files

Merge branch 'fix/andre/improve-shell-scripts' into 'master'

[bin/analysis-scripts] improve shell scripts thanks to shellcheck

See merge request frama-c/frama-c!3106
parents c6cd5d04 bc481d38
......@@ -17,19 +17,10 @@ fi
version_via_opam() {
v=$(opam info -f installed-version "$1" 2>/dev/null)
if [ "$v" = "" -o "$v" = "--" ]; then
if [ "$v" = "" ] || [ "$v" = "--" ]; then
echo "NOT"
else
echo $v
fi
}
version_via_ocamlfind() {
v=$(ocamlfind query -format "$1" 2>/dev/null)
if [ "$v" = "" ]; then
echo "NOT"
else
echo $v
echo "$v"
fi
}
......@@ -54,13 +45,11 @@ all_packages=""
for package in $packages; do
name=${package%%.*}
all_packages+=" $package"
working_version=$(echo $package | sed 's/^[^.]*\.//')
working_version=$(echo "$package" | sed 's/^[^.]*\.//')
if [ "$opam" != "NOT" ]; then
actual_version=$(version_via_opam $name)
elif [ "$ocamlfind" != "NOT" ]; then
actual_version=$(version_via_ocamlfind $name)
actual_version=$(version_via_opam "$name")
else
echo "error: neither opam nor ocamlfind found."
echo "error: opam not found."
exit 1
fi
if [ "$working_version" != "$actual_version" ]; then
......
......@@ -19,19 +19,18 @@ is_likely_text_file() {
errors=0
IFS=''
file -f "$1" --mime | grep '\btext' | cut -d: -f1 |
while read file
do
if [ -n "$(is_likely_text_file "$file")" ]; then
x=$(tail -c 1 "$file")
if [ "$x" != "" -a "$file" != "VERSION" -a "$file" != "VERSION_CODENAME" ]; then
if [ "$x" != "" ] && [ "$file" != "VERSION" ] && [ "$file" != "VERSION_CODENAME" ]; then
echo "error: no newline at end of file: $file"
errors=$((errors+1))
fi
fi
done
done < <(file -f "$1" --mime | grep '\btext' | cut -d: -f1)
if [ $errors -gt 0 ]; then
echo "Found $error(s) files with errors."
echo "Found $errors file(s) with errors."
exit 0
fi
......@@ -22,7 +22,7 @@
##########################################################################
# Accept '-check' to avoid issues with ptests
while [ $# -ge 1 -a "$1" = "-check" ]; do
while [ $# -ge 1 ] && [ "$1" = "-check" ]; do
shift
done
......@@ -78,7 +78,7 @@ usage() {
echo " Applies some transformations to an existing compile_commands.json"
echo " (such as relativizing paths) to improve portability."
echo " [default: ./compile_commands.json]"
exit $1
exit "$1"
}
if [ $# -lt 1 ]; then
......@@ -141,11 +141,7 @@ flamegraph() {
dir="$FRAMAC_SESSION"
fi
if [ ! -d "$dir" ]; then
mkdir "$dir"
if [ $? -ne 0 ]; then
echo "error: could not create '$dir'"
exit 1
fi
mkdir "$dir" || { echo "error: could not create '$dir'"; exit 1; }
fi
out_svg="$dir/flamegraph.svg"
"${FRAMAC_SHARE}/analysis-scripts/flamegraph.pl" \
......@@ -179,7 +175,7 @@ configure_for_frama_c() {
echo "error: 'configure' command requires a machdep";
exit 1
fi
MACHDEP="$(echo $1 | tr a-z A-Z)"
MACHDEP=${1^^} # to uppercase
shift
CPP="gcc -E -nostdinc -fno-builtin -I${FRAMAC_SHARE}/libc -D__FC_MACHDEP_${MACHDEP}" ./configure "$@"
}
......@@ -190,22 +186,22 @@ case "$command" in
;;
"make-template")
shift;
${FRAMAC_SHARE}/analysis-scripts/make_template.py "$@";
"${FRAMAC_SHARE}"/analysis-scripts/make_template.py "$@";
;;
"list-files")
shift;
${FRAMAC_SHARE}/analysis-scripts/list_files.py "$@";
"${FRAMAC_SHARE}"/analysis-scripts/list_files.py "$@";
;;
"list-functions")
shift;
# to avoid a slow startup, we only load plugins which perform syntactic
# transformations. This may trigger annotation errors due to missing
# plugins, so we disable those
${DIR}/frama-c "$@" -no-autoload-plugins -load-module variadic,instantiate,${FRAMAC_SHARE}/analysis-scripts/list_functions.ml -kernel-warn-key annot-error=inactive -kernel-verbose 0;
"${DIR}"/frama-c "$@" -no-autoload-plugins -load-module variadic,instantiate,"${FRAMAC_SHARE}"/analysis-scripts/list_functions.ml -kernel-warn-key annot-error=inactive -kernel-verbose 0;
;;
"find-fun")
shift;
${FRAMAC_SHARE}/analysis-scripts/find_fun.py "$@";
"${FRAMAC_SHARE}"/analysis-scripts/find_fun.py "$@";
;;
"flamegraph")
shift;
......@@ -213,7 +209,7 @@ case "$command" in
;;
"summary")
shift;
${FRAMAC_SHARE}/analysis-scripts/summary.py "$@";
"${FRAMAC_SHARE}"/analysis-scripts/summary.py "$@";
;;
"configure")
shift;
......@@ -221,11 +217,11 @@ case "$command" in
;;
"make-wrapper")
shift;
${FRAMAC_SHARE}/analysis-scripts/make_wrapper.py "$0" "$@";
"${FRAMAC_SHARE}"/analysis-scripts/make_wrapper.py "$0" "$@";
;;
"normalize-jcdb")
shift;
${FRAMAC_SHARE}/analysis-scripts/normalize_jcdb.py "$@";
"${FRAMAC_SHARE}"/analysis-scripts/normalize_jcdb.py "$@";
;;
*)
echo "error: unrecognized command: $command";
......
......@@ -6,7 +6,7 @@ then
(
echo "usage: $0 FILE STRING"
echo "Test whether the contents of FILE are different from STRING." \
"If it does, FILE is updated to match STRING. The file" \
"If it does, FILE is updated to match STRING. The file" \
"name is always printed."
) >&2
exit 1
......@@ -17,11 +17,11 @@ shift
STRING=$*
if
[ ! -e $FILE ] ||
! (diff --brief --ignore-space-change $FILE - >/dev/null <<< "$STRING")
[ ! -e "$FILE" ] ||
! (diff --brief --ignore-space-change "$FILE" - >/dev/null <<< "$STRING")
then
mkdir -p $(dirname "$FILE")
echo $STRING > "$FILE"
mkdir -p "$(dirname "$FILE")"
echo "$STRING" > "$FILE"
fi
echo $FILE
echo "$FILE"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment