mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Fix legacy version and multi versions handling
This commit is contained in:
parent
741a731043
commit
c06799cfca
60
lib/utils.sh
60
lib/utils.sh
@ -589,28 +589,52 @@ asdf_run_hook() {
|
||||
}
|
||||
|
||||
with_shim_executable() {
|
||||
tool_versions() {
|
||||
env | awk -F= '/^ASDF_[A-Z]+_VERSION/ {print $1" "$2}' | sed -e "s/^ASDF_//" | sed -e "s/_VERSION / /" | tr "[:upper:]_" "[:lower:]-"
|
||||
local asdf_versions_path
|
||||
asdf_versions_path="$(find_tool_versions)"
|
||||
[ -f "${asdf_versions_path}" ] && cat "${asdf_versions_path}"
|
||||
}
|
||||
|
||||
shim_versions() {
|
||||
get_shim_versions() {
|
||||
shim_plugin_versions "${shim_name}"
|
||||
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | awk '{print$1" system"}'
|
||||
}
|
||||
|
||||
select_from_tool_versions() {
|
||||
grep -f <(shim_versions) <(tool_versions) | head -n 1 | xargs echo
|
||||
}
|
||||
|
||||
preset_versions() {
|
||||
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c "source $(asdf_dir)/lib/utils.sh; echo PLUGIN \$(get_preset_version_for PLUGIN)"
|
||||
}
|
||||
|
||||
select_from_preset_version() {
|
||||
grep -f <(shim_versions) <(preset_versions) | head -n 1 | xargs echo
|
||||
grep -f <(get_shim_versions) <(preset_versions) | head -n 1 | xargs echo
|
||||
}
|
||||
|
||||
select_version() {
|
||||
# First, we get the all the plugin/version pairs where the
|
||||
# current shim is available.
|
||||
# Then, we iterate on these and check if the version of the current
|
||||
# plugin is the one currently set.
|
||||
# Note that multiple plugin versions can be set for a single plugin.
|
||||
# These are separated by a space. e.g. python 3.7.2 2.7.15
|
||||
# Therefore, we iterate on all the versions set for the plugin
|
||||
# and return if we find a version which matches the shim plugin/version pair
|
||||
local search_path
|
||||
search_path=$(pwd)
|
||||
local shim_versions
|
||||
IFS=$'\n' read -rd '' -a shim_versions <<< "$(get_shim_versions)"
|
||||
|
||||
for plugin_and_version in "${shim_versions[@]}"; do
|
||||
local plugin_name
|
||||
local plugin_shim_version
|
||||
IFS=' ' read -r plugin_name plugin_shim_version <<< "$plugin_and_version"
|
||||
|
||||
local version_and_path
|
||||
local version_string
|
||||
local usable_plugin_versions
|
||||
local _path
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
IFS='|' read -r version_string _path <<< "$version_and_path"
|
||||
IFS=' ' read -r -a usable_plugin_versions <<< "$version_string"
|
||||
for plugin_version in "${usable_plugin_versions[@]}"; do
|
||||
if [ "$plugin_version" = "$plugin_shim_version" ]; then
|
||||
echo "$plugin_name $plugin_version"
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
local shim_name
|
||||
@ -622,15 +646,19 @@ with_shim_executable() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
selected_version=$(select_from_tool_versions)
|
||||
local selected_version
|
||||
selected_version="$(select_version)"
|
||||
|
||||
if [ -z "$selected_version" ]; then
|
||||
selected_version=$(select_from_preset_version)
|
||||
fi
|
||||
|
||||
if [ -n "$selected_version" ]; then
|
||||
plugin_name=$(cut -d ' ' -f 1 <<< "$selected_version");
|
||||
full_version=$(cut -d ' ' -f 2- <<< "$selected_version");
|
||||
local plugin_name
|
||||
local full_version
|
||||
local plugin_path
|
||||
|
||||
IFS=' ' read -r plugin_name full_version <<< "$selected_version"
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
|
||||
run_within_env() {
|
||||
|
@ -116,9 +116,19 @@ teardown() {
|
||||
@test "shim exec should execute first plugin that is installed and set" {
|
||||
run asdf install dummy 3.0
|
||||
|
||||
echo "dummy 1.0" > $PROJECT_DIR/.tool-versions
|
||||
echo "dummy 3.0" >> $PROJECT_DIR/.tool-versions
|
||||
echo "dummy 2.0" >> $PROJECT_DIR/.tool-versions
|
||||
echo "dummy 1.0 3.0 2.0" > $PROJECT_DIR/.tool-versions
|
||||
|
||||
run $ASDF_DIR/shims/dummy world hello
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
echo "$output" | grep -q "This is Dummy 3.0! hello world" 2>/dev/null
|
||||
}
|
||||
|
||||
@test "shim exec should only use the first version found for a plugin" {
|
||||
run asdf install dummy 3.0
|
||||
|
||||
echo "dummy 3.0" > $PROJECT_DIR/.tool-versions
|
||||
echo "dummy 1.0" >> $PROJECT_DIR/.tool-versions
|
||||
|
||||
run $ASDF_DIR/shims/dummy world hello
|
||||
[ "$status" -eq 0 ]
|
||||
|
@ -9,6 +9,7 @@ setup() {
|
||||
setup_asdf_dir
|
||||
install_dummy_plugin
|
||||
run asdf install dummy 1.0
|
||||
run asdf install dummy 1.1
|
||||
|
||||
PROJECT_DIR=$HOME/project
|
||||
mkdir $PROJECT_DIR
|
||||
@ -85,3 +86,16 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/custom/dummy" ]
|
||||
}
|
||||
|
||||
@test "which should return the path set by the legacy file" {
|
||||
cd $PROJECT_DIR
|
||||
|
||||
echo 'dummy 1.0' >> $HOME/.tool-versions
|
||||
echo '1.1' >> $PROJECT_DIR/.dummy-version
|
||||
rm $PROJECT_DIR/.tool-versions
|
||||
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
||||
|
||||
run asdf which "dummy"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$ASDF_DIR/installs/dummy/1.1/bin/dummy" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user