Skip to content

Commit

Permalink
Vendor RubyDigest to no longer depends on the digest gem
Browse files Browse the repository at this point in the history
Ref: https://bugs.ruby-lang.org/issues/17873

Ruby 3.1. is making `digest` a default gem, because of this if bundler
depends on it, it might cause already activated issues.

This currently happens if your Gemfile contains a git gem, because
the GitSource makes an MD5 of the repository URL.
  • Loading branch information
byroot committed Oct 15, 2021
1 parent c9f072a commit e4dcb33
Show file tree
Hide file tree
Showing 9 changed files with 865 additions and 23 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb
bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb
bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb
bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb
bundler/lib/bundler/vendor/digest.rb
bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb
bundler/lib/bundler/vendor/molinillo/lib/molinillo.rb
bundler/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb
Expand Down
2 changes: 0 additions & 2 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,6 @@ def warn_on_outdated_bundler
command_name = current_command.name
return if PARSEABLE_COMMANDS.include?(command_name)

return unless SharedHelpers.md5_available?

latest = Fetcher::CompactIndex.
new(nil, Source::Rubygems::Remote.new(Bundler::URI("https://rubygems.org")), nil).
send(:compact_index_client).
Expand Down
4 changes: 0 additions & 4 deletions bundler/lib/bundler/fetcher/compact_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ def fetch_spec(spec)
compact_index_request :fetch_spec

def available?
unless SharedHelpers.md5_available?
Bundler.ui.debug("FIPS mode is enabled, bundler can't use the CompactIndex API")
return nil
end
if fetch_uri.scheme == "file"
Bundler.ui.debug("Using a local server, bundler won't use the CompactIndex API")
return false
Expand Down
24 changes: 9 additions & 15 deletions bundler/lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ def print_major_deprecations!
Bundler.ui.warn message
end

def trap(signal, override = false, &block)
prior = Signal.trap(signal) do
block.call
prior.call unless override
end
end

def ensure_same_dependencies(spec, old_deps, new_deps)
new_deps = new_deps.reject {|d| d.type == :development }
old_deps = old_deps.reject {|d| d.type == :development }
Expand Down Expand Up @@ -176,22 +183,9 @@ def pretty_dependency(dep, print_source = false)
msg
end

def md5_available?
return @md5_available if defined?(@md5_available)
@md5_available = begin
require "openssl"
::OpenSSL::Digest.digest("MD5", "")
true
rescue LoadError
true
rescue ::OpenSSL::Digest::DigestError
false
end
end

def digest(name)
require "digest"
Digest(name)
require "bundler/vendor/digest"
Digest.const_get(name)
end

def write_to_gemfile(gemfile_path, contents)
Expand Down
2 changes: 0 additions & 2 deletions bundler/lib/bundler/source/rubygems/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def initialize(uri)
#
def cache_slug
@cache_slug ||= begin
return nil unless SharedHelpers.md5_available?

cache_uri = original_uri || uri

host = cache_uri.to_s.start_with?("file://") ? nil : cache_uri.host
Expand Down
Loading

0 comments on commit e4dcb33

Please sign in to comment.