Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge RubyGems 3.5.11 and Bundler 2.5.11 for Ruby 3.3 #10870

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Bundler
SUDO_MUTEX = Thread::Mutex.new

autoload :Checksum, File.expand_path("bundler/checksum", __dir__)
autoload :CLI, File.expand_path("bundler/cli", __dir__)
autoload :CIDetector, File.expand_path("bundler/ci_detector", __dir__)
autoload :Definition, File.expand_path("bundler/definition", __dir__)
autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
Expand Down Expand Up @@ -165,6 +166,25 @@ def setup(*groups)
end
end

# Automatically install dependencies if Bundler.settings[:auto_install] exists.
# This is set through config cmd `bundle config set --global auto_install 1`.
#
# Note that this method `nil`s out the global Definition object, so it
# should be called first, before you instantiate anything like an
# `Installer` that'll keep a reference to the old one instead.
def auto_install
return unless settings[:auto_install]

begin
definition.specs
rescue GemNotFound, GitError
ui.info "Automatically installing missing gems."
reset!
CLI::Install.new({}).run
reset!
end
end

# Setups Bundler environment (see Bundler.setup) if it is not already set,
# and loads all gems from groups specified. Unlike ::setup, can be called
# multiple times with different groups (if they were allowed by setup).
Expand Down
27 changes: 5 additions & 22 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Bundler
class CLI < Thor
require_relative "cli/common"
require_relative "cli/install"

package_name "Bundler"

Expand Down Expand Up @@ -69,7 +70,7 @@ def initialize(*args)
Bundler.settings.set_command_option_if_given :retry, options[:retry]

current_cmd = args.last[:current_command].name
auto_install if AUTO_INSTALL_CMDS.include?(current_cmd)
Bundler.auto_install if AUTO_INSTALL_CMDS.include?(current_cmd)
rescue UnknownArgumentError => e
raise InvalidOption, e.message
ensure
Expand Down Expand Up @@ -114,6 +115,8 @@ def cli_help
class_option "verbose", type: :boolean, desc: "Enable verbose output mode", aliases: "-V"

def help(cli = nil)
cli = self.class.all_aliases[cli] if self.class.all_aliases[cli]

case cli
when "gemfile" then command = "gemfile"
when nil then command = "bundle"
Expand Down Expand Up @@ -347,6 +350,7 @@ def binstubs(*gems)
method_option "github", type: :string
method_option "branch", type: :string
method_option "ref", type: :string
method_option "glob", type: :string, banner: "The location of a dependency's .gemspec, expanded within Ruby (single quotes recommended)"
method_option "skip-install", type: :boolean, banner: "Adds gem to the Gemfile but does not install it"
method_option "optimistic", type: :boolean, banner: "Adds optimistic declaration of version to gem"
method_option "strict", type: :boolean, banner: "Adds strict declaration of version to gem"
Expand Down Expand Up @@ -682,7 +686,6 @@ def self.reformatted_help_args(args)
exec_used = args.index {|a| exec_commands.include? a }

command = args.find {|a| bundler_commands.include? a }
command = all_aliases[command] if all_aliases[command]

if exec_used && help_used
if exec_used + help_used == 1
Expand Down Expand Up @@ -735,26 +738,6 @@ def self.deprecated_ext_value?(arguments)

private

# Automatically invoke `bundle install` and resume if
# Bundler.settings[:auto_install] exists. This is set through config cmd
# `bundle config set --global auto_install 1`.
#
# Note that this method `nil`s out the global Definition object, so it
# should be called first, before you instantiate anything like an
# `Installer` that'll keep a reference to the old one instead.
def auto_install
return unless Bundler.settings[:auto_install]

begin
Bundler.definition.specs
rescue GemNotFound, GitError
Bundler.ui.info "Automatically installing missing gems."
Bundler.reset!
invoke :install, []
Bundler.reset!
end
end

def current_command
_, _, config = @_initializer
config[:current_command]
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run

Bundler.self_manager.install_locked_bundler_and_restart_with_it_if_needed

Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Bundler::FREEBSD
Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Gem.freebsd_platform?

# Disable color in deployment mode
Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment]
Expand Down
23 changes: 16 additions & 7 deletions lib/bundler/compact_index_client/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@ def versions_etag_path
end

def checksums
checksums = {}

lines(versions_path).each do |line|
name, _, checksum = line.split(" ", 3)
checksums[name] = checksum
lines(versions_path).each_with_object({}) do |line, checksums|
parse_version_checksum(line, checksums)
end

checksums
end

def dependencies(name)
Expand Down Expand Up @@ -106,6 +101,20 @@ def parse_gem(line)
@dependency_parser.parse(line)
end

# This is mostly the same as `split(" ", 3)` but it avoids allocating extra objects.
# This method gets called at least once for every gem when parsing versions.
def parse_version_checksum(line, checksums)
line.freeze # allows slicing into the string to not allocate a copy of the line
name_end = line.index(" ")
checksum_start = line.index(" ", name_end + 1) + 1
checksum_end = line.size - checksum_start
# freeze name since it is used as a hash key
# pre-freezing means a frozen copy isn't created
name = line[0, name_end].freeze
checksum = line[checksum_start, checksum_end]
checksums[name] = checksum
end

def info_roots
[
directory.join("info"),
Expand Down
9 changes: 8 additions & 1 deletion lib/bundler/constants.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# frozen_string_literal: true

require "rbconfig"

module Bundler
WINDOWS = RbConfig::CONFIG["host_os"] =~ /(msdos|mswin|djgpp|mingw)/
deprecate_constant :WINDOWS

FREEBSD = RbConfig::CONFIG["host_os"].to_s.include?("bsd")
NULL = File::NULL
deprecate_constant :FREEBSD

NULL = File::NULL
deprecate_constant :NULL
end
Loading
Loading