summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2024-09-19 17:53:09 +0200
committergit <svn-admin@ruby-lang.org>2024-11-08 12:06:30 +0000
commit4d83f37ff75bc5819c02e37aafd403a00433ec96 (patch)
treebffeaf95c25e23579f5c80c185e552823de409d8 /lib
parentebf07f7a9c2988848424e2acc6cd5a5bb90ba9c4 (diff)
[rubygems/rubygems] Reduce global state
https://github.com/rubygems/rubygems/commit/43c0c41c6b
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler.rb6
-rw-r--r--lib/bundler/definition.rb6
-rw-r--r--lib/bundler/gem_helpers.rb4
-rw-r--r--lib/bundler/lazy_specification.rb16
-rw-r--r--lib/bundler/spec_set.rb12
5 files changed, 19 insertions, 25 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index cbe9eee89c..c1d7c46e4d 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -255,12 +255,6 @@ module Bundler
end
end
- def most_specific_locked_platform?(platform)
- return false unless defined?(@definition) && @definition
-
- definition.most_specific_locked_platform == platform
- end
-
def ruby_scope
"#{Bundler.rubygems.ruby_engine}/#{RbConfig::CONFIG["ruby_version"]}"
end
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index a1a813b375..b8708e1843 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -211,7 +211,7 @@ module Bundler
end
def missing_specs
- resolve.materialize(requested_dependencies).missing_specs
+ resolve.materialize(requested_dependencies, most_specific_locked_platform).missing_specs
end
def missing_specs?
@@ -593,7 +593,7 @@ module Bundler
incorrect_spec = nil
specs = begin
- resolve.materialize(dependencies)
+ resolve.materialize(dependencies, most_specific_locked_platform)
rescue IncorrectLockfileDependencies => e
spec = e.spec
raise "Infinite loop while fixing lockfile dependencies" if incorrect_spec == spec
@@ -639,7 +639,7 @@ module Bundler
Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies")
sources.remote!
reresolve_without(incomplete_specs)
- specs = resolve.materialize(dependencies)
+ specs = resolve.materialize(dependencies, most_specific_locked_platform)
still_incomplete_specs = specs.incomplete_specs
diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb
index 70ccceb491..18fb7bc7c3 100644
--- a/lib/bundler/gem_helpers.rb
+++ b/lib/bundler/gem_helpers.rb
@@ -62,8 +62,8 @@ module Bundler
end
module_function :select_best_platform_match
- def select_best_local_platform_match(specs, force_ruby: false)
- select_best_platform_match(specs, local_platform, force_ruby: force_ruby).map(&:materialize_for_installation).compact
+ def select_best_local_platform_match(specs, force_ruby: false, most_specific_locked_platform: nil)
+ select_best_platform_match(specs, local_platform, force_ruby: force_ruby).map {|spec| spec.materialize_for_installation(most_specific_locked_platform) }.compact
end
module_function :select_best_local_platform_match
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index e05f30e328..ff942df503 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -99,16 +99,16 @@ module Bundler
out
end
- def materialize_for_installation
+ def materialize_for_installation(most_specific_locked_platform = nil)
source.local!
- matching_specs = source.specs.search(use_exact_resolved_specifications? ? self : [name, version])
+ matching_specs = source.specs.search(use_exact_resolved_specifications?(most_specific_locked_platform) ? self : [name, version])
return self if matching_specs.empty?
- candidates = if use_exact_resolved_specifications?
+ candidates = if use_exact_resolved_specifications?(most_specific_locked_platform)
matching_specs
else
- target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform
+ target_platform = ruby_platform_materializes_to_ruby_platform?(most_specific_locked_platform) ? platform : local_platform
installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform)
@@ -165,8 +165,8 @@ module Bundler
private
- def use_exact_resolved_specifications?
- @use_exact_resolved_specifications ||= !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform?
+ def use_exact_resolved_specifications?(most_specific_locked_platform)
+ !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform?(most_specific_locked_platform)
end
#
@@ -179,10 +179,10 @@ module Bundler
# on newer bundlers unless users generate the lockfile from scratch or
# explicitly add a more specific platform.
#
- def ruby_platform_materializes_to_ruby_platform?
+ def ruby_platform_materializes_to_ruby_platform?(most_specific_locked_platform)
generic_platform = generic_local_platform == Gem::Platform::JAVA ? Gem::Platform::JAVA : Gem::Platform::RUBY
- !Bundler.most_specific_locked_platform?(generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
+ (most_specific_locked_platform != generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
end
end
end
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb
index fac1bea1ea..fb0a4f784b 100644
--- a/lib/bundler/spec_set.rb
+++ b/lib/bundler/spec_set.rb
@@ -14,7 +14,7 @@ module Bundler
@incomplete_specs = incomplete_specs
end
- def for(dependencies, check = false, platforms = [nil])
+ def for(dependencies, check = false, platforms = [nil], most_specific_locked_platform = nil)
handled = ["bundler"].product(platforms).map {|k| [k, true] }.to_h
deps = dependencies.product(platforms)
specs = []
@@ -31,7 +31,7 @@ module Bundler
handled[key] = true
- specs_for_dep = specs_for_dependency(*dep)
+ specs_for_dep = specs_for_dependency(*dep, most_specific_locked_platform)
if specs_for_dep.any?
specs.concat(specs_for_dep)
@@ -130,8 +130,8 @@ module Bundler
lookup.dup
end
- def materialize(deps)
- materialized = self.for(deps, true)
+ def materialize(deps, most_specific_locked_platform = nil)
+ materialized = self.for(deps, true, [nil], most_specific_locked_platform)
SpecSet.new(materialized, incomplete_specs)
end
@@ -291,14 +291,14 @@ module Bundler
@specs.sort_by(&:name).each {|s| yield s }
end
- def specs_for_dependency(dep, platform)
+ def specs_for_dependency(dep, platform, most_specific_locked_platform)
specs_for_name = lookup[dep.name]
return [] unless specs_for_name
if platform
GemHelpers.select_best_platform_match(specs_for_name, platform, force_ruby: dep.force_ruby_platform)
else
- GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform || dep.default_force_ruby_platform)
+ GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform || dep.default_force_ruby_platform, most_specific_locked_platform: most_specific_locked_platform)
end
end