1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-14 06:13:53 -05:00

Support GEM_HOME, add limited support for user-installed gems (#1436)

The rehash process will now discover executables in additional locations:
- `~/.gem/ruby/<version>/bin/*`
- `$GEM_HOME/bin`

The `rbenv which` (and thus `rbenv exec`) command will also search these locations when looking up a command. This enables shims to dispatch calls to executables added by `gem install --user-install`.

Note that this support is limited:
- It will only work with C Ruby, as it's difficult to guess the `~/.gem/<engine>/<version>` directory for other Rubies without actually loading Ruby;
- It will only work for RBENV_VERSION values in the format `X.Y.Z` and not "system".
This commit is contained in:
Mislav Marohnić
2022-09-26 02:57:15 +02:00
committed by GitHub
parent 009ef3a2db
commit 959968c46d
5 changed files with 86 additions and 5 deletions

View File

@@ -3,10 +3,11 @@
load test_helper
create_executable() {
local bin="${RBENV_ROOT}/versions/${1}/bin"
mkdir -p "$bin"
touch "${bin}/$2"
chmod +x "${bin}/$2"
local exe="${RBENV_ROOT}/versions/${1}/bin/${2}"
[ -n "$2" ] || exe="$1"
mkdir -p "${exe%/*}"
touch "$exe"
chmod +x "$exe"
}
@test "empty rehash" {
@@ -104,6 +105,42 @@ ruby
OUT
}
@test "user-install" {
create_executable "${HOME}/.gem/ruby/3.0.0/bin/lolcat"
create_executable "${HOME}/.gem/ruby/3.1.0/bin/pinecone"
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
run rbenv-rehash
assert_success ""
run ls "${RBENV_ROOT}/shims"
assert_success
assert_output <<OUT
lolcat
pinecone
OUT
}
@test "explicit gem home" {
create_executable "${HOME}/mygems/bin/lolcat"
create_executable "${HOME}/mygems/bin/pinecone"
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
GEM_HOME="${HOME}/mygems" run rbenv-rehash
assert_success ""
run ls "${RBENV_ROOT}/shims"
assert_success
assert_output <<OUT
lolcat
pinecone
OUT
}
@test "carries original IFS within hooks" {
create_hook rehash hello.bash <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))

View File

@@ -98,6 +98,21 @@ The \`rspec' command exists in these Ruby versions:
OUT
}
@test "executable found in user gems" {
create_executable "2.7.6" "ruby"
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
GEM_HOME='' RBENV_VERSION=2.7.6 run rbenv-which rake
assert_success "${HOME}/.gem/ruby/2.7.0/bin/rake"
}
@test "executable found in gem home" {
create_executable "2.7.6" "ruby"
create_executable "${HOME}/mygems/bin" "rake"
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
GEM_HOME="${HOME}/mygems" RBENV_VERSION=2.7.6 run rbenv-which rake
assert_success "${HOME}/mygems/bin/rake"
}
@test "carries original IFS within hooks" {
create_hook which hello.bash <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))
@@ -118,6 +133,6 @@ SH
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
RBENV_VERSION= run rbenv-which ruby
RBENV_VERSION='' run rbenv-which ruby
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
}