diff options
author | Richard Samuels <richard.l.samuels@gmail.com> | 2021-05-18 16:19:17 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-27 18:26:29 +0000 |
commit | 6135750dab50a54e40929913fa043d33f2d6f26e (patch) | |
tree | b6ee72b6b72ed152d2c35b71517ef524d7ff301d /evergreen | |
parent | d7c69eb4c0453f77047fcc95ed4ab76a6580718c (diff) | |
download | mongo-6135750dab50a54e40929913fa043d33f2d6f26e.tar.gz |
SERVER-57047 Remove requirement to specify workdir when subprocess.exec'ing shell scripts
Diffstat (limited to 'evergreen')
-rw-r--r-- | evergreen/functions/venv_setup.sh | 9 | ||||
-rwxr-xr-x | evergreen/prelude.sh | 13 | ||||
-rw-r--r-- | evergreen/prelude_venv.sh | 5 | ||||
-rw-r--r-- | evergreen/prelude_workdir.sh | 26 |
4 files changed, 38 insertions, 15 deletions
diff --git a/evergreen/functions/venv_setup.sh b/evergreen/functions/venv_setup.sh index 7eb6c3d14a2..0a901296aee 100644 --- a/evergreen/functions/venv_setup.sh +++ b/evergreen/functions/venv_setup.sh @@ -1,10 +1,11 @@ # exit immediately if virtualenv is not found set -o errexit -evergreen_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -. "$evergreen_dir/../prelude_python.sh" +evergreen_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/.." +. "$evergreen_dir/prelude_workdir.sh" +. "$evergreen_dir/prelude_python.sh" -python_loc=$(which ${python:-/opt/mongodbtoolchain/v3/bin/python3}) +python_loc=$(which ${python}) venv_dir="${workdir}/venv" if [ -d "$venv_dir" ]; then exit 0 @@ -34,7 +35,7 @@ toolchain_txt="$pip_dir/toolchain-requirements.txt" # the whole prelude cannot be imported because it requires pyyaml to be # installed, which happens just below. -. "$evergreen_dir/../prelude_venv.sh" +. "$evergreen_dir/prelude_venv.sh" activate_venv echo "Upgrading pip to 21.0.1" diff --git a/evergreen/prelude.sh b/evergreen/prelude.sh index 86f41a53c44..a44b69e7a0a 100755 --- a/evergreen/prelude.sh +++ b/evergreen/prelude.sh @@ -2,20 +2,12 @@ if [[ "$0" == *"/evergreen/prelude.sh" ]]; then echo "ERROR: do not execute this script. source it instead. ie: . prelude.sh" exit 1 fi +set -o errexit # path the directory that contains this script. evergreen_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -# bootstrapping python assumes that the user has not cd'd before the prelude. -# Ensure that here. -calculated_workdir=$(cd "$evergreen_dir/../.." && echo $PWD) -if [ "$PWD" != "$calculated_workdir" ]; then - echo "ERROR: Your script changed directory before loading prelude.sh. Don't do that" - echo "\$PWD: $PWD" - echo "\$calculated_workdir: $calculated_workdir" - exit 1 -fi - +. "$evergreen_dir/prelude_workdir.sh" . "$evergreen_dir/prelude_python.sh" . "$evergreen_dir/prelude_venv.sh" @@ -79,3 +71,4 @@ function set_sudo { set -o errexit fi } +set +o errexit diff --git a/evergreen/prelude_venv.sh b/evergreen/prelude_venv.sh index 953f4e63d02..728e097ffe0 100644 --- a/evergreen/prelude_venv.sh +++ b/evergreen/prelude_venv.sh @@ -13,7 +13,10 @@ function activate_venv { fi python=python else - python=${python:-/opt/mongodbtoolchain/v3/bin/python3} + if [ -z "$python" ]; then + echo "\$python is unset. This should never happen" + fi + python=${python} fi if [ "Windows_NT" = "$OS" ]; then diff --git a/evergreen/prelude_workdir.sh b/evergreen/prelude_workdir.sh new file mode 100644 index 00000000000..2e39ba1f3b8 --- /dev/null +++ b/evergreen/prelude_workdir.sh @@ -0,0 +1,26 @@ +calculated_workdir=$(cd "$evergreen_dir/../.." && echo "$PWD") +pwd_cygpath="$PWD" +if [ "Windows_NT" = "$OS" ]; then + calculated_workdir=$(cygpath -w "$calculated_workdir") + pwd_cygpath=$(cygpath -w "$pwd_cygpath") +fi +if [ -z "$workdir" ]; then + workdir="$calculated_workdir" + +# skip this test on Windows. The directories will never match due to the many +# different path types present on Windows+Cygwin +elif [ "$workdir" != "$calculated_workdir" ] && [ "Windows_NT" != "$OS" ]; then + # if you move the checkout directory (ex: simple project config project), + # then this assertion will fail in the future. You need to update + # calculated_workdir, and all the relative directories in this file. + echo "\$workdir was specified, but didn't match \$calculated_workdir. Did the directory structure change? Update prelude.sh" + echo "\$workdir: $workdir" + echo "\$calculated_workdir: $calculated_workdir" + exit 1 +fi +if [ "$pwd_cygpath" != "$calculated_workdir" ]; then + echo "ERROR: Your script changed directory before loading prelude.sh. Don't do that" + echo "\$PWD: $PWD" + echo "\$calculated_workdir: $calculated_workdir" + exit 1 +fi |