mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Revert to using exec when running a shim
This commit is contained in:
parent
f359548381
commit
450660018c
@ -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
|
||||
|
||||
|
@ -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 $?
|
||||
|
59
lib/utils.sh
59
lib/utils.sh
@ -489,49 +489,36 @@ 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"
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$version" = "system" ]; then
|
||||
# execute as is for system
|
||||
"$callback"
|
||||
exit $?
|
||||
fi
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
# add the plugin listed exec paths to PATH
|
||||
local path
|
||||
path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH"
|
||||
|
||||
# add the plugin listed exec paths to PATH
|
||||
local path
|
||||
path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH"
|
||||
# If no custom exec-env transform, just execute callback
|
||||
if [ ! -f "${plugin_path}/bin/exec-env" ]; then
|
||||
PATH=$path "$callback"
|
||||
return $?
|
||||
fi
|
||||
|
||||
# If no custom exec-env transform, just execute callback
|
||||
if [ ! -f "${plugin_path}/bin/exec-env" ]; then
|
||||
PATH=$path "$callback"
|
||||
exit $?
|
||||
fi
|
||||
# Load the plugin custom environment
|
||||
local install_path
|
||||
install_path=$(find_install_path "$plugin_name" "$full_version")
|
||||
|
||||
# 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
|
||||
# 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 $?
|
||||
)
|
||||
PATH=$path "$callback"
|
||||
}
|
||||
|
||||
plugin_executables() {
|
||||
|
@ -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" == "" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user