Skip to content

Commit

Permalink
Use RUBY_ENGINE_VERSION to decide the GEM_HOME
Browse files Browse the repository at this point in the history
* Such that each installed Ruby has its own GEM_HOME, even if RUBY_VERSION
  remains the same for multiple releases of a non-MRI Ruby implementation.
* This is particularly important for TruffleRuby, where different releases
  with the same RUBY_VERSION might compile C extensions differently, and
  each release should have a different GEM_HOME.
  • Loading branch information
eregon committed Feb 8, 2019
1 parent 4c46722 commit 5dfbf52
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions share/chruby/chruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function chruby_reset()
fi

PATH="${PATH#:}"; PATH="${PATH%:}"
unset RUBY_ROOT RUBY_ENGINE RUBY_VERSION RUBYOPT GEM_ROOT
unset RUBY_ROOT RUBY_ENGINE RUBY_VERSION RUBY_ENGINE_VERSION RUBYOPT GEM_ROOT
hash -r
}

Expand All @@ -46,13 +46,14 @@ function chruby_use()
eval "$(RUBYGEMS_GEMDEPS="" "$RUBY_ROOT/bin/ruby" - <<EOF
puts "export RUBY_ENGINE=#{Object.const_defined?(:RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'};"
puts "export RUBY_VERSION=#{RUBY_VERSION};"
puts "export RUBY_ENGINE_VERSION=#{defined?(RUBY_ENGINE_VERSION) ? RUBY_ENGINE_VERSION : RUBY_VERSION};"
begin; require 'rubygems'; puts "export GEM_ROOT=#{Gem.default_dir.inspect};"; rescue LoadError; end
EOF
)"
export PATH="${GEM_ROOT:+$GEM_ROOT/bin:}$PATH"

if (( UID != 0 )); then
export GEM_HOME="$HOME/.gem/$RUBY_ENGINE/$RUBY_VERSION"
export GEM_HOME="$HOME/.gem/$RUBY_ENGINE/$RUBY_ENGINE_VERSION"
export GEM_PATH="$GEM_HOME${GEM_ROOT:+:$GEM_ROOT}${GEM_PATH:+:$GEM_PATH}"
export PATH="$GEM_HOME/bin:$PATH"
fi
Expand Down

0 comments on commit 5dfbf52

Please sign in to comment.