Skip to content

Commit 4f05aac

Browse files
authored
Support ruby version paths that include the '+0' suffix observed when installing from ruby head. Also support gem paths used by bundler when installing gems from Github rather than RubyGems. (#28)
1 parent 85ba963 commit 4f05aac

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ load("@system_ruby_custom//:bundle.bzl", "ruby_bundle")
120120

121121
ruby_bundle(
122122
name = "bundle",
123-
bundler_version = "2.1.4",
123+
bundler_version = "2.4.22",
124124
excludes = {
125125
"mini_portile": ["test/**/*"],
126126
},

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
#
6969
# Library path differs across implementations as `lib/ruby` on MRI and `lib/jruby` on JRuby.
7070
GEM_PATH = ->(ruby_version, gem_name, gem_version) do
71-
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/gems/#{gem_name}-#{gem_version}*").first
71+
glob = Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/gems/#{gem_name}-#{gem_version}*").first
72+
alt_glob = Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/bundler/gems/#{gem_name}-*").first
73+
glob || alt_glob
7274
end
7375

7476
# For ordinary gems, this path is like 'lib/ruby/3.0.0/specifications/rspec-3.10.0.gemspec'.
@@ -81,7 +83,9 @@
8183
#
8284
# Library path differs across implementations as `lib/ruby` on MRI and `lib/jruby` on JRuby.
8385
SPEC_PATH = ->(ruby_version, gem_name, gem_version) do
84-
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/specifications/#{gem_name}-#{gem_version}*.gemspec").first
86+
glob = Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/specifications/#{gem_name}-#{gem_version}*.gemspec").first
87+
alt_glob = Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/bundler/gems/#{gem_name}-*/**/*.gemspec").first
88+
glob || alt_glob
8589
end
8690

8791
HERE = File.absolute_path '.'
@@ -193,7 +197,18 @@ def initialize(workspace_name:,
193197
# This attribute returns 0 as the third minor version number, which happens to be
194198
# what Ruby uses in the PATH to gems, eg. ruby 2.6.5 would have a folder called
195199
# ruby/2.6.0/gems for all minor versions of 2.6.*
196-
@ruby_version ||= (RUBY_VERSION.split('.')[0..1] << 0).join('.')
200+
@ruby_version ||= begin
201+
version_string = (RUBY_VERSION.split('.')[0..1] << 0).join('.')
202+
if File.exist?("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{version_string}")
203+
version_string
204+
else
205+
if File.exist?("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{version_string}+0")
206+
version_string + "+0"
207+
else
208+
raise "Cannot find directory named #{version_string} within lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
209+
end
210+
end
211+
end
197212
end
198213

199214
def generate!

0 commit comments

Comments
 (0)