Skip to content

Commit 0daeffa

Browse files
committed
Update Truffle::GemUtil.gem_paths logic to be closer to RubyGems
* Notably it now works with: GEM_HOME=/usr/local/bundle jt test spec/truffle/rubygems/path_spec.rb GEM_PATH=/usr/local/bundle jt test spec/truffle/rubygems/path_spec.rb GEM_PATH=/usr/local/bundle: jt test spec/truffle/rubygems/path_spec.rb
1 parent a0c75e8 commit 0daeffa

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/main/ruby/truffleruby/core/truffle/gem_util.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ module Truffle::GemUtil
5959
'zlib' => true
6060
}
6161

62-
6362
MARKER_NAME = 'truffleruby_gem_dir_marker.txt'
6463

6564
def self.upgraded_default_gem?(feature)
@@ -115,19 +114,28 @@ def self.bad_gem_dirs(dirs)
115114

116115
# Gem.path, without needing to load RubyGems
117116
def self.gem_paths
118-
@gem_paths ||= begin
119-
if gem_path = ENV['GEM_PATH']
120-
paths = gem_path.split(File::PATH_SEPARATOR)
117+
@gem_paths ||= compute_gem_path
118+
end
119+
120+
def self.compute_gem_path
121+
user_dir = "#{Dir.home}/.gem/truffleruby/#{abi_version}"
122+
default_dir = "#{Truffle::Boot.ruby_home}/lib/gems"
123+
home = ENV['GEM_HOME'] || default_dir
124+
# There is also vendor_dir, but it does not exist on TruffleRuby
125+
default_path = [user_dir, default_dir, home]
126+
127+
if gem_path = ENV['GEM_PATH']
128+
paths = gem_path.split(File::PATH_SEPARATOR)
129+
if gem_path.end_with?(File::PATH_SEPARATOR)
130+
paths += default_path
121131
else
122-
user_dir = "#{Dir.home}/.gem/truffleruby/#{abi_version}"
123-
paths = [user_dir]
132+
paths << home
124133
end
125-
126-
home = ENV['GEM_HOME'] || "#{Truffle::Boot.ruby_home}/lib/gems"
127-
paths << home
128-
129-
paths.map { |path| expand(path) }.uniq
134+
else
135+
paths = default_path
130136
end
137+
138+
paths.map { |path| expand(path) }.uniq
131139
end
132140

133141
def self.abi_version

0 commit comments

Comments
 (0)