Revert to using exec when running a shim

This commit is contained in:
Daniel Perez 2019-03-26 17:36:08 +00:00
parent f359548381
commit 450660018c
4 changed files with 28 additions and 73 deletions

View File

@ -5,10 +5,12 @@
Features
* Add documentation about using multiple versions of the same plugin
* Remove post_COMMAND hooks
Fixed Bugs
* Restore support for legacy file version
* Run executable using `exec`
## 0.7.0

View File

@ -20,15 +20,10 @@ shim_exec_command() {
asdf_run_hook "pre_${plugin_name}_${shim_name}" "${shim_args[@]}"
pre_status=$?
if [ "$pre_status" -eq 0 ]; then
"$executable_path" "${shim_args[@]}"
exit_status=$?
if [ "$pre_status" -ne 0 ]; then
return "$pre_status"
fi
if [ "${exit_status:-${pre_status}}" -eq 0 ]; then
asdf_run_hook "post_${plugin_name}_${shim_name}" "${shim_args[@]}"
post_status=$?
fi
exit "${post_status:-${exit_status:-${pre_status}}}"
exec "$executable_path" "${shim_args[@]}"
}
with_shim_executable "$shim_name" exec_shim || exit $?

View File

@ -489,13 +489,10 @@ with_plugin_env() {
local version="${version_info[0]}"
fi
# create a new subshell to keep env
(
if [ "$version" = "system" ]; then
# execute as is for system
"$callback"
exit $?
return $?
fi
local plugin_path
@ -508,30 +505,20 @@ with_plugin_env() {
# If no custom exec-env transform, just execute callback
if [ ! -f "${plugin_path}/bin/exec-env" ]; then
PATH=$path "$callback"
exit $?
return $?
fi
# Load the plugin custom environment
local install_path
install_path=$(find_install_path "$plugin_name" "$full_version")
ASDF_INSTALL_TYPE=$install_type
ASDF_INSTALL_VERSION=$version
ASDF_INSTALL_PATH=$install_path
export ASDF_INSTALL_TYPE
export ASDF_INSTALL_VERSION
export ASDF_INSTALL_PATH
# shellcheck source=/dev/null
ASDF_INSTALL_TYPE=$install_type \
ASDF_INSTALL_VERSION=$version \
ASDF_INSTALL_PATH=$install_path \
source "${plugin_path}/bin/exec-env"
unset ASDF_INSTALL_TYPE
unset ASDF_INSTALL_VERSION
unset ASDF_INSTALL_PATH
PATH=$path "$callback"
exit $?
)
}
plugin_executables() {

View File

@ -406,32 +406,3 @@ EOM
[ "$status" -eq 1 ]
}
@test "shim exec executes configured post-hook if command was successful" {
run asdf install dummy 1.0
echo dummy 1.0 > $PROJECT_DIR/.tool-versions
cat > $HOME/.asdfrc <<-'EOM'
post_dummy_dummy = echo POST $version $1 $2
EOM
run $ASDF_DIR/shims/dummy hello world
[ "$status" -eq 0 ]
echo "$output" | grep "This is Dummy 1.0! world hello"
echo "$output" | grep "POST 1.0 hello world"
}
@test "shim exec does not executes configured post-hook if command failed" {
run asdf install dummy 1.0
echo dummy 1.0 > $PROJECT_DIR/.tool-versions
cat > $HOME/.asdfrc <<-'EOM'
post_dummy_dummy = echo POST
EOM
echo "false" > $ASDF_DIR/installs/dummy/1.0/bin/dummy
chmod +x $ASDF_DIR/installs/dummy/1.0/bin/dummy
run $ASDF_DIR/shims/dummy hello world
[ "$status" -eq 1 ]
[ "$output" == "" ]
}