mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix: reshim
did not rewrite executable path (#1311)
Co-authored-by: James Hegedus <jthegedus@hey.com> Fixes https://github.com/asdf-vm/asdf/issues/1115 Fixes https://github.com/asdf-vm/asdf/issues/1231 Fixes https://github.com/asdf-vm/asdf/issues/1286
This commit is contained in:
parent
15faf93a0d
commit
5af7625769
@ -88,39 +88,30 @@ write_shim_script() {
|
||||
local shim_path
|
||||
shim_path="$(asdf_data_dir)/shims/$executable_name"
|
||||
|
||||
if [ -f "$shim_path" ]; then
|
||||
if ! grep -x "# asdf-plugin: ${plugin_name} ${version}" "$shim_path" >/dev/null; then
|
||||
sed -i.bak -e "s/exec /# asdf-plugin: ${plugin_name} ${version}\\"$'\n''exec /' "$shim_path"
|
||||
rm -f "$shim_path".bak
|
||||
fi
|
||||
else
|
||||
cat <<EOF >"$shim_path"
|
||||
#!/usr/bin/env bash
|
||||
local temp_dir
|
||||
temp_dir=${TMPDIR:-/tmp}
|
||||
|
||||
local temp_versions_path
|
||||
temp_versions_path=$(mktemp "$temp_dir/asdf-command-reshim-write-shims.XXXXXX")
|
||||
cat <<EOF >"$temp_versions_path"
|
||||
# asdf-plugin: ${plugin_name} ${version}
|
||||
EOF
|
||||
|
||||
if [ -f "$shim_path" ]; then
|
||||
grep '^#\sasdf-plugin:\s' <"$shim_path" >>"$temp_versions_path"
|
||||
fi
|
||||
|
||||
cat <<EOF >"$shim_path"
|
||||
#!/usr/bin/env bash
|
||||
$(sort -u <"$temp_versions_path")
|
||||
exec $(asdf_dir)/bin/asdf exec "${executable_name}" "\$@" # asdf_allow: ' asdf '
|
||||
EOF
|
||||
fi
|
||||
|
||||
rm "$temp_versions_path"
|
||||
|
||||
chmod +x "$shim_path"
|
||||
}
|
||||
|
||||
generate_shim_for_executable() {
|
||||
local plugin_name=$1
|
||||
local executable=$2
|
||||
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
|
||||
local version
|
||||
IFS=':' read -r -a version_info <<<"$full_version"
|
||||
if [ "${version_info[0]}" = "ref" ]; then
|
||||
version="${version_info[1]}"
|
||||
else
|
||||
version="${version_info[0]}"
|
||||
fi
|
||||
|
||||
write_shim_script "$plugin_name" "$version" "$executable"
|
||||
}
|
||||
|
||||
generate_shims_for_version() {
|
||||
local plugin_name=$1
|
||||
local full_version=$2
|
||||
|
@ -140,3 +140,19 @@ EOM
|
||||
run asdf reshim dummy 1.0
|
||||
[ "$output" == "RESHIM" ]
|
||||
}
|
||||
|
||||
# Fixes https://github.com/asdf-vm/asdf/issues/1115
|
||||
# (Issue with executable_name changing after homebre updates)
|
||||
@test "reshim should rewrite the shim file except the version list" {
|
||||
run asdf install dummy 1.0
|
||||
local dummy_shim
|
||||
dummy_shim="$ASDF_DIR/shims/dummy"
|
||||
|
||||
sed -i.bak -e 's/exec /exec \/borked_path_due_to_homebrew_update/' "$dummy_shim"
|
||||
run grep 'borked_path_due_to_homebrew_update' "$dummy_shim" # Sanity check
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run asdf reshim dummy "path:$ASDF_DIR/installs/dummy/path"
|
||||
run grep -v 'borked_path_due_to_homebrew_update' "$dummy_shim"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user