Skip to content
Snippets Groups Projects
Commit 2b82cd70 authored by Andre Maroneze's avatar Andre Maroneze
Browse files

[analysis-scripts] apply shellcheck suggestions and a few more improvements

parent 6fd8c1bc
No related branches found
No related tags found
No related merge requests found
...@@ -113,14 +113,14 @@ script_for_creduce="./script_for_creduce.sh" ...@@ -113,14 +113,14 @@ script_for_creduce="./script_for_creduce.sh"
if [ -z "${CREDUCE+x}" ]; then if [ -z "${CREDUCE+x}" ]; then
# Now some distributions have 'cvise' instead of 'creduce', so try it # Now some distributions have 'cvise' instead of 'creduce', so try it
# if found in PATH # if found in PATH
if command -v cvise 2>&1 >/dev/null; then if command -v cvise >/dev/null 2>&1; then
CREDUCE="cvise" CREDUCE="cvise"
else else
CREDUCE="creduce" CREDUCE="creduce"
fi fi
fi fi
if ! command -v "$CREDUCE" 2>&1 >/dev/null; then if ! command -v "$CREDUCE" >/dev/null 2>&1; then
echo "cvise/creduce not found; install it in the PATH or" echo "cvise/creduce not found; install it in the PATH or"
echo "put it in environment variable CREDUCE." echo "put it in environment variable CREDUCE."
exit 1 exit 1
...@@ -137,7 +137,7 @@ for f in "$@"; do ...@@ -137,7 +137,7 @@ for f in "$@"; do
too_many_sources+=" $f" too_many_sources+=" $f"
fi fi
done done
if [ ! -z "$too_many_sources" ]; then if [ -n "$too_many_sources" ]; then
echo "error: too many sources; only the first argument must be a file: $file" echo "error: too many sources; only the first argument must be a file: $file"
echo " remove these from the command-line:$too_many_sources" echo " remove these from the command-line:$too_many_sources"
exit 1 exit 1
...@@ -182,7 +182,7 @@ fi ...@@ -182,7 +182,7 @@ fi
# #
#### End of command-line and environment validation #### End of command-line and environment validation
if [[ ! "$@" =~ no-autoload-plugins ]]; then if [[ ! "$*" =~ no-autoload-plugins ]]; then
echo "********************************************************************" echo "********************************************************************"
echo "Hint: consider using -no-autoload-plugins -load-module [modules]" echo "Hint: consider using -no-autoload-plugins -load-module [modules]"
echo " for faster reduction" echo " for faster reduction"
...@@ -208,7 +208,7 @@ else ...@@ -208,7 +208,7 @@ else
cpp_retcode=$? cpp_retcode=$?
set -e set -e
if [ $cpp_retcode -ne 0 ]; then if [ $cpp_retcode -ne 0 ]; then
echo "error trying to get preprocessing flags (exit code: $cpp_retcode): $FRAMAC -print-cpp-commands $@ $file" echo "error trying to get preprocessing flags (exit code: $cpp_retcode): $FRAMAC -print-cpp-commands $* $file"
exit $cpp_retcode exit $cpp_retcode
fi fi
CPP=$(echo "$cpp_output" | \ CPP=$(echo "$cpp_output" | \
...@@ -269,7 +269,7 @@ else ...@@ -269,7 +269,7 @@ else
fi fi
"$SED" -i "s|@FRAMAC@|$FRAMAC|g" "$script_for_creduce" "$SED" -i "s|@FRAMAC@|$FRAMAC|g" "$script_for_creduce"
"$SED" -i "s|@BASE@|$base|g" "$script_for_creduce" "$SED" -i "s|@BASE@|$base|g" "$script_for_creduce"
"$SED" -i "s|@FCFLAGS@|$(echo $@ | tr "'" "\\'")|g" "$script_for_creduce" "$SED" -i "s|@FCFLAGS@|$(echo "$@" | tr "'" "\\'")|g" "$script_for_creduce"
chmod u+x "$script_for_creduce" chmod u+x "$script_for_creduce"
trap '{ echo "Creduce interrupted!"; echo ""; echo "(partially) reduced file: $dir_for_reduction/$base"; exit 0; }' SIGINT trap '{ echo "Creduce interrupted!"; echo ""; echo "(partially) reduced file: $dir_for_reduction/$base"; exit 0; }' SIGINT
...@@ -288,7 +288,7 @@ if [ $? -ne 0 ]; then ...@@ -288,7 +288,7 @@ if [ $? -ne 0 ]; then
echo " check the options given to Frama-C." echo " check the options given to Frama-C."
echo " If you edited '$script_for_creduce', check it as well." echo " If you edited '$script_for_creduce', check it as well."
echo "" echo ""
if [ $(wc -l /tmp/script_for_creduce.out | cut -d' ' -f1) -gt 20 ]; then if [ "$(wc -l /tmp/script_for_creduce.out | cut -d' ' -f1)" -gt 20 ]; then
echo "# Script output (first 20 lines):" echo "# Script output (first 20 lines):"
head -n 20 /tmp/script_for_creduce.out head -n 20 /tmp/script_for_creduce.out
echo "(...) [truncated; full output in /tmp/script_for_creduce.out]" echo "(...) [truncated; full output in /tmp/script_for_creduce.out]"
......
...@@ -29,10 +29,11 @@ ...@@ -29,10 +29,11 @@
set +e set +e
"@FRAMAC@" "@BASE@" @FCFLAGS@ "@FRAMAC@" "@BASE@" @FCFLAGS@
retcode=$? retcode=$?
set -e
# see cmdline.ml for the different exit codes returned by Frama-C # see cmdline.ml for the different exit codes returned by Frama-C
if [ $retcode -eq 125 -o $retcode -eq 4 ]; then if [ $retcode -eq 125 ] || [ $retcode -eq 4 ]; then
exit 0 exit 0
else else
exit 1 exit 1
fi fi
set -e
...@@ -32,7 +32,7 @@ fc_out=$(mktemp creduce_fc_XXXXXX.log) ...@@ -32,7 +32,7 @@ fc_out=$(mktemp creduce_fc_XXXXXX.log)
# We always check that the reduced file remains valid C code. # We always check that the reduced file remains valid C code.
set -o pipefail set -o pipefail
@CPP@ "@BASE@" 2>&1 | tee $cc_out @CPP@ "@BASE@" 2>&1 | tee "$cc_out"
set +o pipefail set +o pipefail
### Examples of conditions to be maintained by C-Reduce; copy and adapt ### Examples of conditions to be maintained by C-Reduce; copy and adapt
...@@ -49,10 +49,12 @@ set +o pipefail ...@@ -49,10 +49,12 @@ set +o pipefail
########## ##########
set +e # allow Frama-C to fail so we can retrieve its exit code
set -o pipefail set -o pipefail
"@FRAMAC@" "@BASE@" @FCFLAGS@ 2>&1 | tee $fc_out "@FRAMAC@" "@BASE@" @FCFLAGS@ 2>&1 | tee "$fc_out"
fc_retcode=$(echo ${PIPESTATUS[0]}) fc_retcode=${PIPESTATUS[0]}
set +o pipefail set +o pipefail
set -e
### Examples of conditions to be maintained by C-Reduce; copy and adapt ### Examples of conditions to be maintained by C-Reduce; copy and adapt
# #
...@@ -69,4 +71,4 @@ set +o pipefail ...@@ -69,4 +71,4 @@ set +o pipefail
########## ##########
### Cleanup ### Cleanup
rm -f $cc_out $fc_out rm -f "$cc_out" "$fc_out"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment