mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Merge pull request #638 from sstephenson/gem-rehash
Bring rbenv-gem-rehash functionality to core
This commit is contained in:
commit
d1a0398fdb
6 changed files with 64 additions and 5 deletions
|
@ -71,15 +71,20 @@ shopt -s nullglob
|
|||
|
||||
bin_path="$(abs_dirname "$0")"
|
||||
for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
|
||||
bin_path="${bin_path}:${plugin_bin}"
|
||||
PATH="${plugin_bin}:${PATH}"
|
||||
done
|
||||
export PATH="${bin_path}:${PATH}"
|
||||
|
||||
hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d"
|
||||
if [ "${bin_path%/*}" != "$RBENV_ROOT" ]; then
|
||||
# Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${bin_path%/*}/rbenv.d"
|
||||
fi
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
|
||||
hook_path="${hook_path}:${plugin_hook}"
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}"
|
||||
done
|
||||
export RBENV_HOOK_PATH="$hook_path"
|
||||
export RBENV_HOOK_PATH
|
||||
|
||||
shopt -u nullglob
|
||||
|
||||
|
|
Binary file not shown.
1
rbenv.d/exec/gem-rehash.bash
Normal file
1
rbenv.d/exec/gem-rehash.bash
Normal file
|
@ -0,0 +1 @@
|
|||
export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB"
|
18
rbenv.d/exec/gem-rehash/rubygems_plugin.rb
Normal file
18
rbenv.d/exec/gem-rehash/rubygems_plugin.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
hook = lambda do |installer|
|
||||
begin
|
||||
# Ignore gems that aren't installed in locations that rbenv searches for binstubs
|
||||
if installer.spec.executables.any? &&
|
||||
[Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir)
|
||||
system "rbenv", "rehash"
|
||||
end
|
||||
rescue
|
||||
warn "rbenv: error in gem-rehash (#{$!})"
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
Gem.post_install(&hook)
|
||||
Gem.post_uninstall(&hook)
|
||||
rescue
|
||||
warn "rbenv: error installing gem-rehash hooks (#{$!})"
|
||||
end
|
|
@ -1,2 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
eval "echo \$$1"
|
||||
# Usage: rbenv echo [-F<char>] VAR
|
||||
|
||||
if [[ $1 == -F* ]]; then
|
||||
sep="${1:2}"
|
||||
echo "${!2}" | tr "${sep:-:}" $'\n'
|
||||
else
|
||||
echo "${!1}"
|
||||
fi
|
||||
|
|
|
@ -45,3 +45,31 @@ load test_helper
|
|||
assert_failure
|
||||
assert_output "rbenv: cannot change working directory to \`$dir'"
|
||||
}
|
||||
|
||||
@test "adds its own libexec to PATH" {
|
||||
run rbenv echo "PATH"
|
||||
assert_success "${BATS_TEST_DIRNAME%/*}/libexec:$PATH"
|
||||
}
|
||||
|
||||
@test "adds plugin bin dirs to PATH" {
|
||||
mkdir -p "$RBENV_ROOT"/plugins/ruby-build/bin
|
||||
mkdir -p "$RBENV_ROOT"/plugins/rbenv-each/bin
|
||||
run rbenv echo -F: "PATH"
|
||||
assert_success
|
||||
assert_line 0 "${BATS_TEST_DIRNAME%/*}/libexec"
|
||||
assert_line 1 "${RBENV_ROOT}/plugins/ruby-build/bin"
|
||||
assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin"
|
||||
}
|
||||
|
||||
@test "RBENV_HOOK_PATH preserves value from environment" {
|
||||
RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH"
|
||||
assert_success
|
||||
assert_line 0 "/my/hook/path"
|
||||
assert_line 1 "/other/hooks"
|
||||
assert_line 2 "${RBENV_ROOT}/rbenv.d"
|
||||
}
|
||||
|
||||
@test "RBENV_HOOK_PATH includes rbenv built-in plugins" {
|
||||
run rbenv echo "RBENV_HOOK_PATH"
|
||||
assert_success ":${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue