Skip to content

Commit

Permalink
Support ruby version paths that include the '+0' suffix observed when…
Browse files Browse the repository at this point in the history
… installing from ruby head. Also support gem paths used by bundler when installing gems from Github rather than RubyGems. (#28)
  • Loading branch information
JasonLunn authored Apr 4, 2024
1 parent 85ba963 commit 4f05aac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ load("@system_ruby_custom//:bundle.bzl", "ruby_bundle")

ruby_bundle(
name = "bundle",
bundler_version = "2.1.4",
bundler_version = "2.4.22",
excludes = {
"mini_portile": ["test/**/*"],
},
Expand Down
21 changes: 18 additions & 3 deletions ruby/private/bundle/create_bundle_build_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
#
# Library path differs across implementations as `lib/ruby` on MRI and `lib/jruby` on JRuby.
GEM_PATH = ->(ruby_version, gem_name, gem_version) do
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/gems/#{gem_name}-#{gem_version}*").first
glob = Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/gems/#{gem_name}-#{gem_version}*").first
alt_glob = Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/bundler/gems/#{gem_name}-*").first
glob || alt_glob
end

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

HERE = File.absolute_path '.'
Expand Down Expand Up @@ -193,7 +197,18 @@ def initialize(workspace_name:,
# This attribute returns 0 as the third minor version number, which happens to be
# what Ruby uses in the PATH to gems, eg. ruby 2.6.5 would have a folder called
# ruby/2.6.0/gems for all minor versions of 2.6.*
@ruby_version ||= (RUBY_VERSION.split('.')[0..1] << 0).join('.')
@ruby_version ||= begin
version_string = (RUBY_VERSION.split('.')[0..1] << 0).join('.')
if File.exist?("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{version_string}")
version_string
else
if File.exist?("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{version_string}+0")
version_string + "+0"
else
raise "Cannot find directory named #{version_string} within lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
end
end
end
end

def generate!
Expand Down

0 comments on commit 4f05aac

Please sign in to comment.