Skip to content

Commit

Permalink
Merge RubyGems 3.5.9 and Bundler 2.5.9 (Fixed CI at Ruby 3.3) (ruby#1…
Browse files Browse the repository at this point in the history
…0348)

* Merge RubyGems-3.5.6 and Bundler-2.5.6

* Merge RubyGems-3.5.7 and Bundler-2.5.7

* Merge RubyGems-3.5.8 and Bundler-2.5.8

* Partly reverted about rubygems/rubygems#7483

* Merge RubyGems-3.5.9 and Bundler-2.5.9
  • Loading branch information
hsbt authored Apr 16, 2024
1 parent 2f65458 commit 7227b85
Show file tree
Hide file tree
Showing 282 changed files with 6,697 additions and 927 deletions.
5 changes: 3 additions & 2 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@ def environment
#
# @param unlock [Hash, Boolean, nil] Gems that have been requested
# to be updated or true if all gems should be updated
# @param lockfile [Pathname] Path to Gemfile.lock
# @return [Bundler::Definition]
def definition(unlock = nil)
def definition(unlock = nil, lockfile = default_lockfile)
@definition = nil if unlock
@definition ||= begin
configure
Definition.build(default_gemfile, default_lockfile, unlock)
Definition.build(default_gemfile, lockfile, unlock)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def inject(name, version)
method_option "major", type: :boolean, banner: "If updating, prefer updating to next major version (default)"
method_option "pre", type: :boolean, banner: "If updating, always choose the highest allowed version, regardless of prerelease status"
method_option "strict", type: :boolean, banner: "If updating, do not allow any gem to be updated past latest --patch | --minor | --major"
method_option "conservative", type: :boolean, banner: "If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated"
method_option "conservative", type: :boolean, banner: "If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated"
method_option "bundler", type: :string, lazy_default: "> 0.a", banner: "Update the locked version of bundler"
def lock
require_relative "cli/lock"
Expand Down Expand Up @@ -785,7 +785,7 @@ def warn_on_outdated_bundler
return unless SharedHelpers.md5_available?

latest = Fetcher::CompactIndex.
new(nil, Source::Rubygems::Remote.new(Bundler::URI("https://rubygems.org")), nil, nil).
new(nil, Source::Rubygems::Remote.new(Gem::URI("https://rubygems.org")), nil, nil).
send(:compact_index_client).
instance_variable_get(:@cache).
dependencies("bundler").
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/binstubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run
next
end

Bundler.settings.temporary(path: (Bundler.settings[:path] || Bundler.root)) do
Bundler.settings.temporary(path: Bundler.settings[:path] || Bundler.root) do
installer.generate_standalone_bundler_executable_stubs(spec, installer_opts)
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def rust_builder_required_rubygems_version
end

def required_ruby_version
"2.6.0"
"3.0.0"
end

def rubocop_version
Expand Down
9 changes: 5 additions & 4 deletions lib/bundler/cli/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ def run
update = { bundler: bundler }
end

file = options[:lockfile]
file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile

Bundler.settings.temporary(frozen: false) do
definition = Bundler.definition(update)
definition = Bundler.definition(update, file)

Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]

Expand All @@ -60,10 +63,8 @@ def run
if print
puts definition.to_lock
else
file = options[:lockfile]
file = file ? File.expand_path(file) : Bundler.default_lockfile
puts "Writing lockfile to #{file}"
definition.lock(file)
definition.lock
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/bundler/cli/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ module Bundler
class CLI::Plugin < Thor
desc "install PLUGINS", "Install the plugin from the source"
long_desc <<-D
Install plugins either from the rubygems source provided (with --source option) or from a git source provided with --git (for remote repos) or --local_git (for local repos). If no sources are provided, it uses Gem.sources
Install plugins either from the rubygems source provided (with --source option), from a git source provided with --git, or a local path provided with --path. If no sources are provided, it uses Gem.sources
D
method_option "source", type: :string, default: nil, banner: "URL of the RubyGems source to fetch the plugin from"
method_option "version", type: :string, default: nil, banner: "The version of the plugin to fetch"
method_option "git", type: :string, default: nil, banner: "URL of the git repo to fetch from"
method_option "local_git", type: :string, default: nil, banner: "Path of the local git repo to fetch from"
method_option "local_git", type: :string, default: nil, banner: "Path of the local git repo to fetch from (deprecated)"
method_option "branch", type: :string, default: nil, banner: "The git branch to checkout"
method_option "ref", type: :string, default: nil, banner: "The git revision to check out"
method_option "path", type: :string, default: nil, banner: "Path of a local gem to directly use"
def install(*plugins)
Bundler::Plugin.install(plugins, options)
end
Expand Down
82 changes: 54 additions & 28 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,38 +320,26 @@ def groups
dependencies.map(&:groups).flatten.uniq
end

def lock(file, preserve_unknown_sections = false)
return if Definition.no_lock

contents = to_lock

# Convert to \r\n if the existing lock has them
# i.e., Windows with `git config core.autocrlf=true`
contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match?("\r\n")

if @locked_bundler_version
locked_major = @locked_bundler_version.segments.first
current_major = bundler_version_to_lock.segments.first

updating_major = locked_major < current_major
end
def lock(file_or_preserve_unknown_sections = false, preserve_unknown_sections_or_unused = false)
if [true, false, nil].include?(file_or_preserve_unknown_sections)
target_lockfile = lockfile || Bundler.default_lockfile
preserve_unknown_sections = file_or_preserve_unknown_sections
else
target_lockfile = file_or_preserve_unknown_sections
preserve_unknown_sections = preserve_unknown_sections_or_unused

preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler))
suggestion = if target_lockfile == lockfile
"To fix this warning, remove it from the `Definition#lock` call."
else
"Instead, instantiate a new definition passing `#{target_lockfile}`, and call `lock` without a file argument on that definition"
end

if file && File.exist?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
return if Bundler.frozen_bundle?
SharedHelpers.filesystem_access(file) { FileUtils.touch(file) }
return
end
msg = "`Definition#lock` was passed a target file argument. #{suggestion}"

if Bundler.frozen_bundle?
Bundler.ui.error "Cannot write a changed lockfile while frozen."
return
Bundler::SharedHelpers.major_deprecation 2, msg
end

SharedHelpers.filesystem_access(file) do |p|
File.open(p, "wb") {|f| f.puts(contents) }
end
write_lock(target_lockfile, preserve_unknown_sections)
end

def locked_ruby_version
Expand Down Expand Up @@ -518,7 +506,45 @@ def should_add_extra_platforms?
end

def lockfile_exists?
lockfile && File.exist?(lockfile)
file_exists?(lockfile)
end

def file_exists?(file)
file && File.exist?(file)
end

def write_lock(file, preserve_unknown_sections)
return if Definition.no_lock

contents = to_lock

# Convert to \r\n if the existing lock has them
# i.e., Windows with `git config core.autocrlf=true`
contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match?("\r\n")

if @locked_bundler_version
locked_major = @locked_bundler_version.segments.first
current_major = bundler_version_to_lock.segments.first

updating_major = locked_major < current_major
end

preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler))

if file_exists?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
return if Bundler.frozen_bundle?
SharedHelpers.filesystem_access(file) { FileUtils.touch(file) }
return
end

if Bundler.frozen_bundle?
Bundler.ui.error "Cannot write a changed lockfile while frozen."
return
end

SharedHelpers.filesystem_access(file) do |p|
File.open(p, "wb") {|f| f.puts(contents) }
end
end

def resolver
Expand Down
17 changes: 16 additions & 1 deletion lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def self.evaluate(gemfile, lockfile, unlock)
platform platforms type source install_if gemfile force_ruby_platform].freeze

GITHUB_PULL_REQUEST_URL = %r{\Ahttps://github\.com/([A-Za-z0-9_\-\.]+/[A-Za-z0-9_\-\.]+)/pull/(\d+)\z}
GITLAB_MERGE_REQUEST_URL = %r{\Ahttps://gitlab\.com/([A-Za-z0-9_\-\./]+)/-/merge_requests/(\d+)\z}

attr_reader :gemspecs, :gemfile
attr_accessor :dependencies
Expand Down Expand Up @@ -46,7 +47,7 @@ def eval_gemfile(gemfile, contents = nil)
@gemfile = expanded_gemfile_path
@gemfiles << expanded_gemfile_path
contents ||= Bundler.read_file(@gemfile.to_s)
instance_eval(contents, gemfile.to_s, 1)
instance_eval(contents, @gemfile.to_s, 1)
rescue Exception => e # rubocop:disable Lint/RescueException
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
Expand Down Expand Up @@ -308,6 +309,20 @@ def add_git_sources
repo_name ||= user_name
"https://#{user_name}@bitbucket.org/#{user_name}/#{repo_name}.git"
end

git_source(:gitlab) do |repo_name|
if repo_name =~ GITLAB_MERGE_REQUEST_URL
{
"git" => "https://gitlab.com/#{$1}.git",
"branch" => nil,
"ref" => "refs/merge-requests/#{$2}/head",
"tag" => nil,
}
else
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://gitlab.com/#{repo_name}.git"
end
end
end

def with_source(source)
Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/environment_preserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def backup
env = @original.clone
@keys.each do |key|
value = env[key]
if !value.nil? && !value.empty?
if !value.nil?
env[@prefix + key] ||= value
elsif value.nil?
else
env[@prefix + key] ||= INTENTIONALLY_NIL
end
end
Expand All @@ -72,7 +72,7 @@ def restore
env = @original.clone
@keys.each do |key|
value_original = env[@prefix + key]
next if value_original.nil? || value_original.empty?
next if value_original.nil?
if value_original == INTENTIONALLY_NIL
env.delete(key)
else
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def fetch_spec(spec)
spec -= [nil, "ruby", ""]
spec_file_name = "#{spec.join "-"}.gemspec"

uri = Bundler::URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
uri = Gem::URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
spec = if uri.scheme == "file"
path = Gem::Util.correct_for_windows_path(uri.path)
Bundler.safe_load_marshal Bundler.rubygems.inflate(Gem.read_binary(path))
Expand Down Expand Up @@ -255,7 +255,7 @@ def connection

con = Gem::Net::HTTP::Persistent.new name: "bundler", proxy: :ENV
if gem_proxy = Gem.configuration[:http_proxy]
con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy
con.proxy = Gem::URI.parse(gem_proxy) if gem_proxy != :no_proxy
end

if remote_uri.scheme == "https"
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/fetcher/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def fetch(uri, headers = {}, counter = 0)
when Gem::Net::HTTPSuccess, Gem::Net::HTTPNotModified
response
when Gem::Net::HTTPRedirection
new_uri = Bundler::URI.parse(response["location"])
new_uri = Gem::URI.parse(response["location"])
if new_uri.host == uri.host
new_uri.user = uri.user
new_uri.password = uri.password
Expand Down
80 changes: 42 additions & 38 deletions lib/bundler/gem_version_promoter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,37 @@ def level=(value)

# Given a Resolver::Package and an Array of Specifications of available
# versions for a gem, this method will return the Array of Specifications
# sorted (and possibly truncated if strict is true) in an order to give
# preference to the current level (:major, :minor or :patch) when resolution
# is deciding what versions best resolve all dependencies in the bundle.
# sorted in an order to give preference to the current level (:major, :minor
# or :patch) when resolution is deciding what versions best resolve all
# dependencies in the bundle.
# @param package [Resolver::Package] The package being resolved.
# @param specs [Specification] An array of Specifications for the package.
# @return [Specification] A new instance of the Specification Array sorted and
# possibly filtered.
# @return [Specification] A new instance of the Specification Array sorted.
def sort_versions(package, specs)
specs = filter_dep_specs(specs, package) if strict
locked_version = package.locked_version

sort_dep_specs(specs, package)
result = specs.sort do |a, b|
unless package.prerelease_specified? || pre?
a_pre = a.prerelease?
b_pre = b.prerelease?

next 1 if a_pre && !b_pre
next -1 if b_pre && !a_pre
end

if major? || locked_version.nil?
b <=> a
elsif either_version_older_than_locked?(a, b, locked_version)
b <=> a
elsif segments_do_not_match?(a, b, :major)
a <=> b
elsif !minor? && segments_do_not_match?(a, b, :minor)
a <=> b
else
b <=> a
end
end
post_sort(result, package.unlock?, locked_version)
end

# @return [bool] Convenience method for testing value of level variable.
Expand All @@ -73,9 +93,18 @@ def pre?
pre == true
end

private
# Given a Resolver::Package and an Array of Specifications of available
# versions for a gem, this method will truncate the Array if strict
# is true. That means filtering out downgrades from the version currently
# locked, and filtering out upgrades that go past the selected level (major,
# minor, or patch).
# @param package [Resolver::Package] The package being resolved.
# @param specs [Specification] An array of Specifications for the package.
# @return [Specification] A new instance of the Specification Array
# truncated.
def filter_versions(package, specs)
return specs unless strict

def filter_dep_specs(specs, package)
locked_version = package.locked_version
return specs if locked_version.nil? || major?

Expand All @@ -89,32 +118,7 @@ def filter_dep_specs(specs, package)
end
end

def sort_dep_specs(specs, package)
locked_version = package.locked_version

result = specs.sort do |a, b|
unless package.prerelease_specified? || pre?
a_pre = a.prerelease?
b_pre = b.prerelease?

next -1 if a_pre && !b_pre
next 1 if b_pre && !a_pre
end

if major? || locked_version.nil?
a <=> b
elsif either_version_older_than_locked?(a, b, locked_version)
a <=> b
elsif segments_do_not_match?(a, b, :major)
b <=> a
elsif !minor? && segments_do_not_match?(a, b, :minor)
b <=> a
else
a <=> b
end
end
post_sort(result, package.unlock?, locked_version)
end
private

def either_version_older_than_locked?(a, b, locked_version)
a.version < locked_version || b.version < locked_version
Expand All @@ -133,13 +137,13 @@ def post_sort(result, unlock, locked_version)
if unlock || locked_version.nil?
result
else
move_version_to_end(result, locked_version)
move_version_to_beginning(result, locked_version)
end
end

def move_version_to_end(result, version)
def move_version_to_beginning(result, version)
move, keep = result.partition {|s| s.version.to_s == version.to_s }
keep.concat(move)
move.concat(keep)
end
end
end
Loading

0 comments on commit 7227b85

Please sign in to comment.