summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-01-10 13:53:41 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-01-10 15:53:07 +0900
commita43f1d90c2b3aed232d5f4ef9dfe226401cf5d81 (patch)
treedcb61dd3ab8434242b81d54e8e16b4c4d86d5b8c /lib/bundler
parent89fb61f9a3276121da2826b93f131e52d6449859 (diff)
Merge RubyGems and Bundler master
from https://github.com/rubygems/rubygems/commit/0635c1423db5d7c461d53bf0c3329bca75de7609
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7094
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/definition.rb11
-rw-r--r--lib/bundler/dsl.rb4
-rw-r--r--lib/bundler/environment_preserver.rb4
-rw-r--r--lib/bundler/index.rb4
-rw-r--r--lib/bundler/injector.rb2
-rw-r--r--lib/bundler/lazy_specification.rb61
-rw-r--r--lib/bundler/lockfile_generator.rb2
-rw-r--r--lib/bundler/lockfile_parser.rb18
-rw-r--r--lib/bundler/plugin.rb2
-rw-r--r--lib/bundler/resolver.rb11
-rw-r--r--lib/bundler/resolver/candidate.rb19
-rw-r--r--lib/bundler/source/path.rb2
-rw-r--r--lib/bundler/templates/newgem/Cargo.toml.tt2
-rw-r--r--lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb4
-rw-r--r--lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb2
-rw-r--r--lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb2
16 files changed, 80 insertions, 70 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 2f652cb5a7..09a756abc7 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -79,6 +79,7 @@ module Bundler
@locked_bundler_version = nil
@locked_ruby_version = nil
@new_platform = nil
+ @removed_platform = nil
if lockfile && File.exist?(lockfile)
@lockfile_contents = Bundler.read_file(lockfile)
@@ -129,7 +130,7 @@ module Bundler
end
@unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version)
- add_current_platform unless current_ruby_platform_locked? || Bundler.frozen_bundle?
+ add_current_platform unless Bundler.frozen_bundle?
converge_path_sources_to_gemspec_sources
@path_changes = converge_paths
@@ -267,7 +268,7 @@ module Bundler
SpecSet.new(filter_specs(@locked_specs, @dependencies - deleted_deps))
else
Bundler.ui.debug "Found no changes, using resolution from the lockfile"
- if @locked_gems.may_include_redundant_platform_specific_gems?
+ if @removed_platform || @locked_gems.may_include_redundant_platform_specific_gems?
SpecSet.new(filter_specs(@locked_specs, @dependencies))
else
@locked_specs
@@ -446,7 +447,9 @@ module Bundler
end
def remove_platform(platform)
- return if @platforms.delete(Gem::Platform.new(platform))
+ removed_platform = @platforms.delete(Gem::Platform.new(platform))
+ @removed_platform ||= removed_platform
+ return if removed_platform
raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}"
end
@@ -584,6 +587,8 @@ module Bundler
end
def add_current_platform
+ return if current_ruby_platform_locked?
+
add_platform(local_platform)
end
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 0492f52cfc..03c80a408c 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -277,8 +277,8 @@ module Bundler
if repo_name =~ GITHUB_PULL_REQUEST_URL
{
"git" => "https://github.com/#{$1}.git",
- "branch" => "refs/pull/#{$2}/head",
- "ref" => nil,
+ "branch" => nil,
+ "ref" => "refs/pull/#{$2}/head",
"tag" => nil,
}
else
diff --git a/lib/bundler/environment_preserver.rb b/lib/bundler/environment_preserver.rb
index 70967522af..57013f5d50 100644
--- a/lib/bundler/environment_preserver.rb
+++ b/lib/bundler/environment_preserver.rb
@@ -2,7 +2,7 @@
module Bundler
class EnvironmentPreserver
- INTENTIONALLY_NIL = "BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL".freeze
+ INTENTIONALLY_NIL = "BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL"
BUNDLER_KEYS = %w[
BUNDLE_BIN_PATH
BUNDLE_GEMFILE
@@ -16,7 +16,7 @@ module Bundler
RUBYLIB
RUBYOPT
].map(&:freeze).freeze
- BUNDLER_PREFIX = "BUNDLER_ORIG_".freeze
+ BUNDLER_PREFIX = "BUNDLER_ORIG_"
def self.from_env
new(env_to_hash(ENV), BUNDLER_KEYS)
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index 0301986ca9..b8c599f63a 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -13,8 +13,8 @@ module Bundler
attr_reader :specs, :all_specs, :sources
protected :specs, :all_specs
- RUBY = "ruby".freeze
- NULL = "\0".freeze
+ RUBY = "ruby"
+ NULL = "\0"
def initialize
@sources = []
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index c2edc9b43a..cb644a7f69 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -2,7 +2,7 @@
module Bundler
class Injector
- INJECTED_GEMS = "injected gems".freeze
+ INJECTED_GEMS = "injected gems"
def self.inject(new_deps, options = {})
injector = new(new_deps, options)
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index ca51691b5c..dccfe48bba 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -16,7 +16,6 @@ module Bundler
@dependencies = []
@platform = platform || Gem::Platform::RUBY
@source = source
- @specification = nil
@force_ruby_platform = default_force_ruby_platform
end
@@ -80,37 +79,41 @@ module Bundler
def materialize_for_installation
source.local!
- candidates = if source.is_a?(Source::Path) || !ruby_platform_materializes_to_ruby_platform?
- target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform
+ matching_specs = source.specs.search(use_exact_resolved_specifications? ? self : [name, version])
+ return self if matching_specs.empty?
- GemHelpers.select_best_platform_match(source.specs.search([name, version]), target_platform)
+ candidates = if use_exact_resolved_specifications?
+ matching_specs
else
- source.specs.search(self)
- end
+ target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform
- return self if candidates.empty?
+ installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform)
- __materialize__(candidates)
- end
+ specification = __materialize__(installable_candidates)
+ return specification unless specification.nil?
- def __materialize__(candidates)
- @specification = begin
- search = candidates.reverse.find do |spec|
- spec.is_a?(StubSpecification) ||
- (spec.matches_current_ruby? &&
- spec.matches_current_rubygems?)
- end
- if search.nil? && Bundler.frozen_bundle?
- search = candidates.last
- else
- search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification))
+ if target_platform != platform
+ installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform)
end
- search
+
+ installable_candidates
end
+
+ __materialize__(candidates)
end
- def respond_to?(*args)
- super || @specification ? @specification.respond_to?(*args) : nil
+ def __materialize__(candidates)
+ search = candidates.reverse.find do |spec|
+ spec.is_a?(StubSpecification) ||
+ (spec.matches_current_ruby? &&
+ spec.matches_current_rubygems?)
+ end
+ if search.nil? && Bundler.frozen_bundle?
+ search = candidates.last
+ else
+ search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification))
+ end
+ search
end
def to_s
@@ -132,16 +135,8 @@ module Bundler
private
- def to_ary
- nil
- end
-
- def method_missing(method, *args, &blk)
- raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification
-
- return super unless respond_to?(method)
-
- @specification.send(method, *args, &blk)
+ def use_exact_resolved_specifications?
+ @use_exact_resolved_specifications ||= !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform?
end
#
diff --git a/lib/bundler/lockfile_generator.rb b/lib/bundler/lockfile_generator.rb
index 23413dbdd6..a7ee026f67 100644
--- a/lib/bundler/lockfile_generator.rb
+++ b/lib/bundler/lockfile_generator.rb
@@ -45,7 +45,7 @@ module Bundler
# gems with the same name, but different platform
# are ordered consistently
specs.sort_by(&:full_name).each do |spec|
- next if spec.name == "bundler".freeze
+ next if spec.name == "bundler"
out << spec.to_lock
end
end
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index 0ec5b7de8a..237749c525 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -4,15 +4,15 @@ module Bundler
class LockfileParser
attr_reader :sources, :dependencies, :specs, :platforms, :bundler_version, :ruby_version
- BUNDLED = "BUNDLED WITH".freeze
- DEPENDENCIES = "DEPENDENCIES".freeze
- PLATFORMS = "PLATFORMS".freeze
- RUBY = "RUBY VERSION".freeze
- GIT = "GIT".freeze
- GEM = "GEM".freeze
- PATH = "PATH".freeze
- PLUGIN = "PLUGIN SOURCE".freeze
- SPECS = " specs:".freeze
+ BUNDLED = "BUNDLED WITH"
+ DEPENDENCIES = "DEPENDENCIES"
+ PLATFORMS = "PLATFORMS"
+ RUBY = "RUBY VERSION"
+ GIT = "GIT"
+ GEM = "GEM"
+ PATH = "PATH"
+ PLUGIN = "PLUGIN SOURCE"
+ SPECS = " specs:"
OPTIONS = /^ ([a-z]+): (.*)$/i.freeze
SOURCE = [GIT, GEM, PATH, PLUGIN].freeze
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 26458bd596..f3caff8963 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -15,7 +15,7 @@ module Bundler
class UnknownSourceError < PluginError; end
class PluginInstallError < PluginError; end
- PLUGIN_FILE_NAME = "plugins.rb".freeze
+ PLUGIN_FILE_NAME = "plugins.rb"
module_function
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 403ce825d3..df9ce2ff3f 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -337,7 +337,8 @@ module Bundler
def requirement_to_range(requirement)
ranges = requirement.requirements.map do |(op, version)|
- ver = Resolver::Candidate.new(version)
+ ver = Resolver::Candidate.new(version).generic!
+ platform_ver = Resolver::Candidate.new(version).platform_specific!
case op
when "~>"
@@ -345,17 +346,17 @@ module Bundler
bump = Resolver::Candidate.new(version.bump.to_s + ".A")
PubGrub::VersionRange.new(:name => name, :min => ver, :max => bump, :include_min => true)
when ">"
- PubGrub::VersionRange.new(:min => ver)
+ PubGrub::VersionRange.new(:min => platform_ver)
when ">="
PubGrub::VersionRange.new(:min => ver, :include_min => true)
when "<"
PubGrub::VersionRange.new(:max => ver)
when "<="
- PubGrub::VersionRange.new(:max => ver, :include_max => true)
+ PubGrub::VersionRange.new(:max => platform_ver, :include_max => true)
when "="
- PubGrub::VersionRange.new(:min => ver, :max => ver, :include_min => true, :include_max => true)
+ PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true)
when "!="
- PubGrub::VersionRange.new(:min => ver, :max => ver, :include_min => true, :include_max => true).invert
+ PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true).invert
else
raise "bad version specifier: #{op}"
end
diff --git a/lib/bundler/resolver/candidate.rb b/lib/bundler/resolver/candidate.rb
index cf5691ccc7..681f9aca73 100644
--- a/lib/bundler/resolver/candidate.rb
+++ b/lib/bundler/resolver/candidate.rb
@@ -41,6 +41,18 @@ module Bundler
@spec_group.to_specs(package.force_ruby_platform?)
end
+ def generic!
+ @ruby_only = true
+
+ self
+ end
+
+ def platform_specific!
+ @ruby_only = false
+
+ self
+ end
+
def prerelease?
@version.prerelease?
end
@@ -53,27 +65,20 @@ module Bundler
[@version, @ruby_only ? -1 : 1]
end
- def canonical?
- !@spec_group.empty?
- end
-
def <=>(other)
return unless other.is_a?(self.class)
- return @version <=> other.version unless canonical? && other.canonical?
sort_obj <=> other.sort_obj
end
def ==(other)
return unless other.is_a?(self.class)
- return @version == other.version unless canonical? && other.canonical?
sort_obj == other.sort_obj
end
def eql?(other)
return unless other.is_a?(self.class)
- return @version.eql?(other.version) unless canonical? || other.canonical?
sort_obj.eql?(other.sort_obj)
end
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index 20975e20ca..bdfcf8274a 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -11,7 +11,7 @@ module Bundler
protected :original_path
- DEFAULT_GLOB = "{,*,*/*}.gemspec".freeze
+ DEFAULT_GLOB = "{,*,*/*}.gemspec"
def initialize(options)
@options = options.dup
diff --git a/lib/bundler/templates/newgem/Cargo.toml.tt b/lib/bundler/templates/newgem/Cargo.toml.tt
index 7be7550cce..f5a460c9bb 100644
--- a/lib/bundler/templates/newgem/Cargo.toml.tt
+++ b/lib/bundler/templates/newgem/Cargo.toml.tt
@@ -1,5 +1,5 @@
# This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
-# a Rust project. Your extensions depedencies should be added to the Cargo.toml
+# a Rust project. Your extensions dependencies should be added to the Cargo.toml
# in the ext/ directory.
[workspace]
diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb
index c222542435..9133332d01 100644
--- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb
+++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb
@@ -20,6 +20,10 @@ module Bundler::PubGrub
range.eql?(other.range)
end
+ def ==(other)
+ package == other.package && range == other.range
+ end
+
class << self
def exact(package, version)
range = VersionRange.new(min: version, max: version, include_min: true, include_max: true)
diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb
index e384178973..506b447b36 100644
--- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb
+++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb
@@ -397,7 +397,7 @@ module Bundler::PubGrub
def constraints
return ["any"] if any?
- return ["= #{min}"] if min == max
+ return ["= #{min}"] if min.to_s == max.to_s
c = []
c << "#{include_min ? ">=" : ">"} #{min}" if min
diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb
index c898a6522d..bbc10c3804 100644
--- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb
+++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb
@@ -148,7 +148,7 @@ module Bundler::PubGrub
while !ranges.empty?
ne = []
range = ranges.shift
- while !ranges.empty? && ranges[0].min == range.max
+ while !ranges.empty? && ranges[0].min.to_s == range.max.to_s
ne << range.max
range = range.span(ranges.shift)
end