From 2e0c9f496daca6499f2865a307a92e8a8f4b9996 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 2 Sep 2024 12:13:16 -0700 Subject: [PATCH] Use `exit 2` for script failure --- Makefile | 18 +++++++++--------- run.sh | 10 +++++----- src/scripts/merge_tools/git_hires_merge.sh | 2 +- src/scripts/merge_tools/gitmerge.sh | 6 +++--- src/scripts/merge_tools/gitmerge_resolve.sh | 2 +- src/scripts/merge_tools/intellimerge.sh | 6 +++--- .../merge_tools/merge_git_then_plumelib.sh | 2 +- src/scripts/merge_tools/spork.sh | 6 +++--- src/scripts/run_repo_tests.sh | 16 ++++++++-------- src/scripts/run_with_timeout.sh | 2 +- src/scripts/utils/run_multiple_machines.sh | 6 +++--- src/scripts/utils/run_remotely.sh | 2 +- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 09c8335517..b3ddc25880 100644 --- a/Makefile +++ b/Makefile @@ -68,36 +68,36 @@ clean-everything: clean clean-cache clean-test-cache clean-stored-hashes # Compresses the cache. compress-cache: - if [ ! -d cache ]; then echo "cache does not exist"; exit 1; fi + if [ ! -d cache ]; then echo "cache does not exist"; exit 2; fi if [ -f cache.tar.gz ]; then rm -f cache.tar.gz; fi tar --exclude="lock" -czf cache.tar.gz cache # Compresses the cache without logs. compress-cache-without-logs: - if [ ! -d cache ]; then echo "cache does not exist"; exit 1; fi + if [ ! -d cache ]; then echo "cache does not exist"; exit 2; fi if [ -f cache_without_logs.tar.gz ]; then rm -f cache_without_logs.tar.gz; fi tar --exclude="lock" --exclude="logs" -czf cache_without_logs.tar.gz cache compress-small-cache: - if [ ! -d cache-small ]; then echo "cache-small does not exist"; exit 1; fi + if [ ! -d cache-small ]; then echo "cache-small does not exist"; exit 2; fi if [ -f cache-small.tar ]; then rm -f cache-small.tar; fi tar --exclude="lock" -czf cache-small.tar cache-small # Decompresses the cache. decompress-cache: - if [ ! -f cache.tar.gz ]; then echo "cache.tar.gz does not exist"; exit 1; fi - if [ -d cache ]; then echo "cache already exists"; exit 1; fi + if [ ! -f cache.tar.gz ]; then echo "cache.tar.gz does not exist"; exit 2; fi + if [ -d cache ]; then echo "cache already exists"; exit 2; fi tar -xzf cache.tar.gz # Decompresses the cache without logs. decompress-cache-without-logs: - if [ ! -f cache_without_logs.tar.gz ]; then echo "cache_without_logs.tar.gz does not exist"; exit 1; fi - if [ -d cache ]; then echo "cache already exists"; exit 1; fi + if [ ! -f cache_without_logs.tar.gz ]; then echo "cache_without_logs.tar.gz does not exist"; exit 2; fi + if [ -d cache ]; then echo "cache already exists"; exit 2; fi tar -xzf cache_without_logs.tar.gz decompress-small-cache: - if [ ! -f cache-small.tar ]; then echo "cache-small.tar does not exist"; exit 1; fi - if [ -d cache-small ]; then echo "cache-small already exists"; exit 1; fi + if [ ! -f cache-small.tar ]; then echo "cache-small.tar does not exist"; exit 2; fi + if [ -d cache-small ]; then echo "cache-small already exists"; exit 2; fi tar -xzf cache-small.tar # Copy tables and plots to the paper. diff --git a/run.sh b/run.sh index 507dcc99be..5c3436e9ed 100755 --- a/run.sh +++ b/run.sh @@ -27,7 +27,7 @@ CACHE_DIR="${4}" # backend=$(uname -s) # if [ "$backend" = "Darwin" ]; then # echo "Error: MacOS is not supported. Please run the script on a Linux machine. This is due to the use of readarray in certain merge tools." -# exit 1 +# exit 2 # fi comparator_flags="" @@ -120,10 +120,10 @@ if [ -f cache_without_logs.tar.gz ] && [ ! -d cache_without_logs ]; then fi fi -mvn -v | head -n 1 | cut -c 14-18 | grep -q 3.9. || { echo "Maven 3.9.* is required"; mvn -v; echo "PATH=$PATH"; exit 1; } -if [ -z "${JAVA8_HOME:+isset}" ] ; then echo "JAVA8_HOME is not set"; exit 1; fi -if [ -z "${JAVA11_HOME:+isset}" ] ; then echo "JAVA11_HOME is not set"; exit 1; fi -if [ -z "${JAVA17_HOME:+isset}" ] ; then echo "JAVA17_HOME is not set"; exit 1; fi +mvn -v | head -n 1 | cut -c 14-18 | grep -q 3.9. || { echo "Maven 3.9.* is required"; mvn -v; echo "PATH=$PATH"; exit 2; } +if [ -z "${JAVA8_HOME:+isset}" ] ; then echo "JAVA8_HOME is not set"; exit 2; fi +if [ -z "${JAVA11_HOME:+isset}" ] ; then echo "JAVA11_HOME is not set"; exit 2; fi +if [ -z "${JAVA17_HOME:+isset}" ] ; then echo "JAVA17_HOME is not set"; exit 2; fi if [ -z "${machine_id:+isset}" ] ; then machine_id=0; fi if [ -z "${num_machines:+isset}" ] ; then num_machines=1; fi diff --git a/src/scripts/merge_tools/git_hires_merge.sh b/src/scripts/merge_tools/git_hires_merge.sh index a91d69cda1..71df96a76d 100755 --- a/src/scripts/merge_tools/git_hires_merge.sh +++ b/src/scripts/merge_tools/git_hires_merge.sh @@ -9,7 +9,7 @@ branch2=$3 # Print the current PATH echo "PATH: $PATH" -cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 1) +cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 2) git checkout "$branch1" --force diff --git a/src/scripts/merge_tools/gitmerge.sh b/src/scripts/merge_tools/gitmerge.sh index d32e741299..d2c7c8659f 100755 --- a/src/scripts/merge_tools/gitmerge.sh +++ b/src/scripts/merge_tools/gitmerge.sh @@ -4,14 +4,14 @@ # must contain a clone of a repository. # is arguments to `git merge`, including -s and possibly -X. # Merges branch2 into branch1, in , using merge strategy . -# Return code is 0 for merge success, 1 for merge failure. +# Return code is 0 for merge success, 1 for merge failure, 2 for script failure. # For merge failure, also outputs "Conflict" and aborts the merge. set -o nounset if [ "$#" -ne 4 ]; then echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2 GIT_STRATEGY" >&2 - exit 1 + exit 2 fi clone_dir=$1 @@ -21,7 +21,7 @@ git_strategy=$4 ## Perform merge -cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 1) +cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 2) git checkout "$branch1" --force git config --local merge.conflictstyle zdiff3 diff --git a/src/scripts/merge_tools/gitmerge_resolve.sh b/src/scripts/merge_tools/gitmerge_resolve.sh index c2485d076a..14b7dd8219 100755 --- a/src/scripts/merge_tools/gitmerge_resolve.sh +++ b/src/scripts/merge_tools/gitmerge_resolve.sh @@ -12,7 +12,7 @@ status=$? if [ "$status" -ne 0 ]; then echo "Removing filenames from conflict markers." - cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 1) + cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 2) readarray -t files < <(grep -l -r '^\(<<<<<<<\||||||||\|>>>>>>>\) .merge_file_') for file in "${files[@]}" ; do echo "Removing filenames from conflict markers in $file" diff --git a/src/scripts/merge_tools/intellimerge.sh b/src/scripts/merge_tools/intellimerge.sh index f1d9deaff8..72c10f0352 100755 --- a/src/scripts/merge_tools/intellimerge.sh +++ b/src/scripts/merge_tools/intellimerge.sh @@ -3,14 +3,14 @@ # usage: ./intellimerge.sh # must contain a clone of a repository. # Merges branch2 into branch1, in . -# Return code is 0 for merge success, 1 for merge failure. +# Return code is 0 for merge success, 1 for merge failure, 2 for script failure. # For merge failure, also outputs "Conflict" and aborts the merge. set -o nounset if [ "$#" -ne 3 ]; then echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2" >&2 - exit 1 + exit 2 fi SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" @@ -34,7 +34,7 @@ echo "Temp dir: $temp_out_dir" clone_dir_absolutepath=$(realpath "$clone_dir") # run intellimerge -cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 1) +cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 2) java -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.io.tmpdir="$temp_intellimerge_dir" -jar "$intellimerge_absolutepath" -r "$clone_dir_absolutepath" -b "$branch1" "$branch2" -o $temp_out_dir diff --git a/src/scripts/merge_tools/merge_git_then_plumelib.sh b/src/scripts/merge_tools/merge_git_then_plumelib.sh index 4ba5c4a9ca..9c7c98289b 100755 --- a/src/scripts/merge_tools/merge_git_then_plumelib.sh +++ b/src/scripts/merge_tools/merge_git_then_plumelib.sh @@ -12,7 +12,7 @@ plumelib_strategy=$5 #"--only-adjacent" echo "$0: Merging $branch1 and $branch2 with git_strategy=$git_strategy and plumelib_strategy=$plumelib_strategy" -cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 1) +cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 2) git checkout "$branch1" --force diff --git a/src/scripts/merge_tools/spork.sh b/src/scripts/merge_tools/spork.sh index b652dad3a6..42182223ce 100755 --- a/src/scripts/merge_tools/spork.sh +++ b/src/scripts/merge_tools/spork.sh @@ -3,14 +3,14 @@ # usage: ./spork.sh # must contain a clone of a repository. # Merges branch2 into branch1, in . -# Return code is 0 for merge success, 1 for merge failure. +# Return code is 0 for merge success, 1 for merge failure, 2 for script failure. # For merge failure, also outputs "Conflict" and aborts the merge. set -o nounset if [ "$#" -ne 3 ]; then echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2" >&2 - exit 1 + exit 2 fi # Kill all Java processes that are running for over an hour (to avoid memory leaks). @@ -26,7 +26,7 @@ clone_dir=$1 branch1=$2 branch2=$3 -cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 1) +cd "$clone_dir" || (echo "$0: cannot cd to $clone_dir" ; exit 2) # set up spork driver git config --local merge.spork.name "spork" diff --git a/src/scripts/run_repo_tests.sh b/src/scripts/run_repo_tests.sh index 749c51ccda..7660a4b49f 100755 --- a/src/scripts/run_repo_tests.sh +++ b/src/scripts/run_repo_tests.sh @@ -14,11 +14,11 @@ find /tmp -maxdepth 1 -user "$(whoami)" -mmin +120 -exec rm -rf {} \; if [ "$#" -ne 1 ]; then echo "Usage: $0 REPO_DIR" >&2 - exit 1 + exit 2 fi REPO_DIR=$1 CURR_PATH=$(pwd) -cd "$REPO_DIR" || exit 1 +cd "$REPO_DIR" || exit 2 if [ -f "gradlew" ] ; then # Append JaCoCo plugin and task to build.gradle @@ -40,12 +40,12 @@ else exit 1 fi -if [ -z "${JAVA8_HOME:+isset}" ] ; then echo "JAVA8_HOME is not set"; exit 1; fi -if [ ! -d "${JAVA8_HOME}" ] ; then echo "JAVA8_HOME is set to a nonexistent directory: ${JAVA8_HOME}"; exit 1; fi -if [ -z "${JAVA11_HOME:+isset}" ] ; then echo "JAVA11_HOME is not set"; exit 1; fi -if [ ! -d "${JAVA11_HOME}" ] ; then echo "JAVA11_HOME is set to a nonexistent directory: ${JAVA11_HOME}"; exit 1; fi -if [ -z "${JAVA17_HOME:+isset}" ] ; then echo "JAVA17_HOME is not set"; exit 1; fi -if [ ! -d "${JAVA17_HOME}" ] ; then echo "JAVA17_HOME is set to a nonexistent directory: ${JAVA17_HOME}"; exit 1; fi +if [ -z "${JAVA8_HOME:+isset}" ] ; then echo "JAVA8_HOME is not set"; exit 2; fi +if [ ! -d "${JAVA8_HOME}" ] ; then echo "JAVA8_HOME is set to a nonexistent directory: ${JAVA8_HOME}"; exit 2; fi +if [ -z "${JAVA11_HOME:+isset}" ] ; then echo "JAVA11_HOME is not set"; exit 2; fi +if [ ! -d "${JAVA11_HOME}" ] ; then echo "JAVA11_HOME is set to a nonexistent directory: ${JAVA11_HOME}"; exit 2; fi +if [ -z "${JAVA17_HOME:+isset}" ] ; then echo "JAVA17_HOME is not set"; exit 2; fi +if [ ! -d "${JAVA17_HOME}" ] ; then echo "JAVA17_HOME is set to a nonexistent directory: ${JAVA17_HOME}"; exit 2; fi ORIG_PATH="${PATH}" diff --git a/src/scripts/run_with_timeout.sh b/src/scripts/run_with_timeout.sh index ac251b4759..b48e21c206 100755 --- a/src/scripts/run_with_timeout.sh +++ b/src/scripts/run_with_timeout.sh @@ -5,7 +5,7 @@ # Check if the correct number of arguments was provided if [ "$#" -ne 2 ]; then echo "Usage: $0 " - exit 1 + exit 2 fi # Read the timeout and command from arguments diff --git a/src/scripts/utils/run_multiple_machines.sh b/src/scripts/utils/run_multiple_machines.sh index af56357de5..78b53ace25 100755 --- a/src/scripts/utils/run_multiple_machines.sh +++ b/src/scripts/utils/run_multiple_machines.sh @@ -8,7 +8,7 @@ # Check arguments if [ "$#" -ne 3 ]; then echo "Usage: ./run_multiple_machines.sh " - exit 1 + exit 2 fi BRANCH="$1" @@ -26,7 +26,7 @@ NUM_MACHINES=${#MACHINE_ADDRESSES[@]} # Check that the number of machines is at least 1 if [ "$NUM_MACHINES" -lt 1 ]; then echo "Error: number of machines is less than 1" - exit 1 + exit 2 fi # Check that machines are reachable @@ -35,7 +35,7 @@ for i in "${!MACHINE_ADDRESSES[@]}"; do echo "Checking if machine $i with address $MACHINE_ADDRESS is reachable" if ! ssh -o ConnectTimeout=1 "$MACHINE_ADDRESS" exit >/dev/null 2>&1; then echo "Error: machine $i with address $MACHINE_ADDRESS is not reachable" - exit 1 + exit 2 fi done echo "Success: all machines are reachable" diff --git a/src/scripts/utils/run_remotely.sh b/src/scripts/utils/run_remotely.sh index 57c1cb75ee..b1684b899c 100755 --- a/src/scripts/utils/run_remotely.sh +++ b/src/scripts/utils/run_remotely.sh @@ -11,7 +11,7 @@ # Check arguments if [ "$#" -ne 5 ]; then echo "Usage: ./run_remotely.sh " - exit 1 + exit 2 fi BRANCH=$1