Skip to content

Commit 4506600

Browse files
committed
Revert to using exec when running a shim
1 parent f359548 commit 4506600

4 files changed

Lines changed: 28 additions & 73 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
Features
66

77
* Add documentation about using multiple versions of the same plugin
8+
* Remove post_COMMAND hooks
89

910
Fixed Bugs
1011

1112
* Restore support for legacy file version
13+
* Run executable using `exec`
1214

1315
## 0.7.0
1416

lib/commands/shim-exec.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ shim_exec_command() {
2020

2121
asdf_run_hook "pre_${plugin_name}_${shim_name}" "${shim_args[@]}"
2222
pre_status=$?
23-
if [ "$pre_status" -eq 0 ]; then
24-
"$executable_path" "${shim_args[@]}"
25-
exit_status=$?
23+
if [ "$pre_status" -ne 0 ]; then
24+
return "$pre_status"
2625
fi
27-
if [ "${exit_status:-${pre_status}}" -eq 0 ]; then
28-
asdf_run_hook "post_${plugin_name}_${shim_name}" "${shim_args[@]}"
29-
post_status=$?
30-
fi
31-
exit "${post_status:-${exit_status:-${pre_status}}}"
26+
exec "$executable_path" "${shim_args[@]}"
3227
}
3328

3429
with_shim_executable "$shim_name" exec_shim || exit $?

lib/utils.sh

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -489,49 +489,36 @@ with_plugin_env() {
489489
local version="${version_info[0]}"
490490
fi
491491

492-
# create a new subshell to keep env
493-
(
494-
495-
if [ "$version" = "system" ]; then
496-
# execute as is for system
497-
"$callback"
498-
exit $?
499-
fi
500-
501-
local plugin_path
502-
plugin_path=$(get_plugin_path "$plugin_name")
492+
if [ "$version" = "system" ]; then
493+
# execute as is for system
494+
"$callback"
495+
return $?
496+
fi
503497

504-
# add the plugin listed exec paths to PATH
505-
local path
506-
path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH"
498+
local plugin_path
499+
plugin_path=$(get_plugin_path "$plugin_name")
507500

508-
# If no custom exec-env transform, just execute callback
509-
if [ ! -f "${plugin_path}/bin/exec-env" ]; then
510-
PATH=$path "$callback"
511-
exit $?
512-
fi
501+
# add the plugin listed exec paths to PATH
502+
local path
503+
path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH"
513504

514-
# Load the plugin custom environment
515-
local install_path
516-
install_path=$(find_install_path "$plugin_name" "$full_version")
505+
# If no custom exec-env transform, just execute callback
506+
if [ ! -f "${plugin_path}/bin/exec-env" ]; then
507+
PATH=$path "$callback"
508+
return $?
509+
fi
517510

518-
ASDF_INSTALL_TYPE=$install_type
519-
ASDF_INSTALL_VERSION=$version
520-
ASDF_INSTALL_PATH=$install_path
521-
export ASDF_INSTALL_TYPE
522-
export ASDF_INSTALL_VERSION
523-
export ASDF_INSTALL_PATH
511+
# Load the plugin custom environment
512+
local install_path
513+
install_path=$(find_install_path "$plugin_name" "$full_version")
524514

525-
# shellcheck source=/dev/null
515+
# shellcheck source=/dev/null
516+
ASDF_INSTALL_TYPE=$install_type \
517+
ASDF_INSTALL_VERSION=$version \
518+
ASDF_INSTALL_PATH=$install_path \
526519
source "${plugin_path}/bin/exec-env"
527520

528-
unset ASDF_INSTALL_TYPE
529-
unset ASDF_INSTALL_VERSION
530-
unset ASDF_INSTALL_PATH
531-
532-
PATH=$path "$callback"
533-
exit $?
534-
)
521+
PATH=$path "$callback"
535522
}
536523

537524
plugin_executables() {

test/shim_exec.bats

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -406,32 +406,3 @@ EOM
406406
[ "$status" -eq 1 ]
407407
}
408408

409-
@test "shim exec executes configured post-hook if command was successful" {
410-
run asdf install dummy 1.0
411-
echo dummy 1.0 > $PROJECT_DIR/.tool-versions
412-
413-
cat > $HOME/.asdfrc <<-'EOM'
414-
post_dummy_dummy = echo POST $version $1 $2
415-
EOM
416-
417-
run $ASDF_DIR/shims/dummy hello world
418-
[ "$status" -eq 0 ]
419-
echo "$output" | grep "This is Dummy 1.0! world hello"
420-
echo "$output" | grep "POST 1.0 hello world"
421-
}
422-
423-
@test "shim exec does not executes configured post-hook if command failed" {
424-
run asdf install dummy 1.0
425-
echo dummy 1.0 > $PROJECT_DIR/.tool-versions
426-
427-
cat > $HOME/.asdfrc <<-'EOM'
428-
post_dummy_dummy = echo POST
429-
EOM
430-
431-
echo "false" > $ASDF_DIR/installs/dummy/1.0/bin/dummy
432-
chmod +x $ASDF_DIR/installs/dummy/1.0/bin/dummy
433-
434-
run $ASDF_DIR/shims/dummy hello world
435-
[ "$status" -eq 1 ]
436-
[ "$output" == "" ]
437-
}

0 commit comments

Comments
 (0)