Skip to content

Commit 9e6d07f

Browse files
committed
Merge rubygems/bundler HEAD
Merge from rubygems/rubygems@2af2520
1 parent b404a5f commit 9e6d07f

17 files changed

+199
-98
lines changed

lib/bundler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module Bundler
5353
autoload :GemHelpers, File.expand_path("bundler/gem_helpers", __dir__)
5454
autoload :GemVersionPromoter, File.expand_path("bundler/gem_version_promoter", __dir__)
5555
autoload :Graph, File.expand_path("bundler/graph", __dir__)
56+
autoload :IncompleteSpecification, File.expand_path("bundler/incomplete_specification", __dir__)
5657
autoload :Index, File.expand_path("bundler/index", __dir__)
5758
autoload :Injector, File.expand_path("bundler/injector", __dir__)
5859
autoload :Installer, File.expand_path("bundler/installer", __dir__)
@@ -455,7 +456,7 @@ def unbundled_exec(*args)
455456
end
456457

457458
def local_platform
458-
return Gem::Platform::RUBY if settings[:force_ruby_platform]
459+
return Gem::Platform::RUBY if settings[:force_ruby_platform] || Gem.platforms == [Gem::Platform::RUBY]
459460
Gem::Platform.local
460461
end
461462

lib/bundler/definition.rb

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
138138
@unlock[:gems] ||= @dependencies.map(&:name)
139139
else
140140
eager_unlock = expand_dependencies(@unlock[:gems] || [], true)
141-
@unlock[:gems] = @locked_specs.for(eager_unlock, false, false).map(&:name)
141+
@unlock[:gems] = @locked_specs.for(eager_unlock, false, platforms).map(&:name)
142142
end
143143

144144
@dependency_changes = converge_dependencies
145145
@local_changes = converge_locals
146146

147-
@locked_specs_incomplete_for_platform = !@locked_specs.for(requested_dependencies & expand_dependencies(locked_dependencies), true, true)
147+
@reresolve = nil
148148

149149
@requires = compute_requires
150150
end
@@ -279,11 +279,8 @@ def resolve
279279
end
280280
end
281281
else
282-
last_resolve = converge_locked_specs
283-
# Run a resolve against the locally available gems
284282
Bundler.ui.debug("Found changes from the lockfile, re-resolving dependencies because #{change_reason}")
285-
expanded_dependencies = expand_dependencies(dependencies + metadata_dependencies, true)
286-
Resolver.resolve(expanded_dependencies, source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms)
283+
@reresolve = reresolve
287284
end
288285
end
289286

@@ -468,7 +465,7 @@ def most_specific_locked_platform
468465
private :sources
469466

470467
def nothing_changed?
471-
!@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@locked_specs_incomplete_for_platform
468+
!@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes
472469
end
473470

474471
def unlocking?
@@ -477,8 +474,14 @@ def unlocking?
477474

478475
private
479476

477+
def reresolve
478+
last_resolve = converge_locked_specs
479+
expanded_dependencies = expand_dependencies(dependencies + metadata_dependencies, true)
480+
Resolver.resolve(expanded_dependencies, source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms)
481+
end
482+
480483
def filter_specs(specs, deps)
481-
SpecSet.new(specs).for(expand_dependencies(deps, true), false, false)
484+
SpecSet.new(specs).for(expand_dependencies(deps, true), false, platforms)
482485
end
483486

484487
def materialize(dependencies)
@@ -502,6 +505,17 @@ def materialize(dependencies)
502505
raise GemNotFound, "Could not find #{missing_specs_list.join(" nor ")}"
503506
end
504507

508+
if @reresolve.nil?
509+
incomplete_specs = specs.incomplete_specs
510+
511+
if incomplete_specs.any?
512+
Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies")
513+
@unlock[:gems].concat(incomplete_specs.map(&:name))
514+
@resolve = reresolve
515+
specs = resolve.materialize(dependencies)
516+
end
517+
end
518+
505519
unless specs["bundler"].any?
506520
bundler = sources.metadata_source.specs.search(Gem::Dependency.new("bundler", VERSION)).last
507521
specs["bundler"] = bundler
@@ -549,7 +563,6 @@ def change_reason
549563
[@new_platform, "you added a new platform to your gemfile"],
550564
[@path_changes, "the gemspecs for path gems changed"],
551565
[@local_changes, "the gemspecs for git local gems changed"],
552-
[@locked_specs_incomplete_for_platform, "the lockfile does not have all gems needed for the current platform"],
553566
].select(&:first).map(&:last).join(", ")
554567
end
555568

@@ -725,7 +738,7 @@ def converge_specs(specs)
725738
# if we won't need the source (according to the lockfile),
726739
# don't error if the path/git source isn't available
727740
next if specs.
728-
for(requested_dependencies, false, true).
741+
for(requested_dependencies, false).
729742
none? {|locked_spec| locked_spec.source == s.source }
730743

731744
raise

lib/bundler/dependency.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# frozen_string_literal: true
22

33
require "rubygems/dependency"
4-
require_relative "force_platform"
54
require_relative "shared_helpers"
65
require_relative "rubygems_ext"
76

87
module Bundler
98
class Dependency < Gem::Dependency
10-
include ForcePlatform
11-
129
attr_reader :autorequire
1310
attr_reader :groups, :platforms, :gemfile, :git, :github, :branch, :ref, :force_ruby_platform
1411

@@ -112,7 +109,7 @@ def initialize(name, version, options = {}, &blk)
112109
@env = options["env"]
113110
@should_include = options.fetch("should_include", true)
114111
@gemfile = options["gemfile"]
115-
@force_ruby_platform = options.fetch("force_ruby_platform", default_force_ruby_platform)
112+
@force_ruby_platform = options["force_ruby_platform"]
116113

117114
@autorequire = Array(options["require"] || []) if options.key?("require")
118115
end

lib/bundler/force_platform.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module Bundler
4+
class IncompleteSpecification
5+
attr_reader :name, :platform
6+
7+
def initialize(name, platform)
8+
@name = name
9+
@platform = platform
10+
end
11+
end
12+
end

lib/bundler/lazy_specification.rb

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# frozen_string_literal: true
22

3-
require_relative "force_platform"
43
require_relative "match_platform"
54

65
module Bundler
76
class LazySpecification
8-
include ForcePlatform
97
include MatchPlatform
108

119
attr_reader :name, :version, :dependencies, :platform
12-
attr_writer :force_ruby_platform
13-
attr_accessor :source, :remote
10+
attr_accessor :source, :remote, :force_ruby_platform
1411

1512
def initialize(name, version, platform, source = nil)
1613
@name = name
@@ -19,23 +16,16 @@ def initialize(name, version, platform, source = nil)
1916
@platform = platform || Gem::Platform::RUBY
2017
@source = source
2118
@specification = nil
22-
@force_ruby_platform = nil
2319
end
2420

2521
def full_name
26-
if platform == Gem::Platform::RUBY || platform.nil?
22+
if platform == Gem::Platform::RUBY
2723
"#{@name}-#{@version}"
2824
else
2925
"#{@name}-#{@version}-#{platform}"
3026
end
3127
end
3228

33-
def force_ruby_platform
34-
return @force_ruby_platform unless @force_ruby_platform.nil?
35-
36-
default_force_ruby_platform
37-
end
38-
3929
def ==(other)
4030
identifier == other.identifier
4131
end
@@ -71,7 +61,7 @@ def satisfies?(dependency)
7161
def to_lock
7262
out = String.new
7363

74-
if platform == Gem::Platform::RUBY || platform.nil?
64+
if platform == Gem::Platform::RUBY
7565
out << " #{name} (#{version})\n"
7666
else
7767
out << " #{name} (#{version}-#{platform})\n"
@@ -85,7 +75,17 @@ def to_lock
8575
out
8676
end
8777

88-
def __materialize__
78+
def materialize_for_installation
79+
__materialize__(ruby_platform_materializes_to_ruby_platform? ? platform : Bundler.local_platform)
80+
end
81+
82+
def materialize_for_resolution
83+
return self unless Gem::Platform.match_spec?(self)
84+
85+
__materialize__(platform)
86+
end
87+
88+
def __materialize__(platform)
8989
@specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name
9090
source.gemspec.tap {|s| s.source = source }
9191
else
@@ -94,10 +94,9 @@ def __materialize__
9494
else
9595
ruby_platform_materializes_to_ruby_platform? ? self : Dependency.new(name, version)
9696
end
97-
platform_object = ruby_platform_materializes_to_ruby_platform? ? Gem::Platform.new(platform) : Gem::Platform.local
9897
candidates = source.specs.search(search_object)
9998
same_platform_candidates = candidates.select do |spec|
100-
MatchPlatform.platforms_match?(spec.platform, platform_object)
99+
MatchPlatform.platforms_match?(spec.platform, platform)
101100
end
102101
installable_candidates = same_platform_candidates.select do |spec|
103102
spec.is_a?(StubSpecification) ||
@@ -115,7 +114,7 @@ def respond_to?(*args)
115114
end
116115

117116
def to_s
118-
@__to_s ||= if platform == Gem::Platform::RUBY || platform.nil?
117+
@__to_s ||= if platform == Gem::Platform::RUBY
119118
"#{name} (#{version})"
120119
else
121120
"#{name} (#{version}-#{platform})"

lib/bundler/remote_specification.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class RemoteSpecification
1616
def initialize(name, version, platform, spec_fetcher)
1717
@name = name
1818
@version = Gem::Version.create version
19-
@platform = platform
19+
@original_platform = platform || Gem::Platform::RUBY
20+
@platform = Gem::Platform.new(platform)
2021
@spec_fetcher = spec_fetcher
2122
@dependencies = nil
2223
end
@@ -35,10 +36,10 @@ def required_rubygems_version
3536
end
3637

3738
def full_name
38-
if platform == Gem::Platform::RUBY || platform.nil?
39+
if @original_platform == Gem::Platform::RUBY
3940
"#{@name}-#{@version}"
4041
else
41-
"#{@name}-#{@version}-#{platform}"
42+
"#{@name}-#{@version}-#{@original_platform}"
4243
end
4344
end
4445

@@ -105,7 +106,7 @@ def to_ary
105106
end
106107

107108
def _remote_specification
108-
@_remote_specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform])
109+
@_remote_specification ||= @spec_fetcher.fetch_spec([@name, @version, @original_platform])
109110
@_remote_specification || raise(GemspecError, "Gemspec data for #{full_name} was" \
110111
" missing from the server! Try installing with `--full-index` as a workaround.")
111112
end

lib/bundler/resolver.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ def self.resolve(requirements, source_requirements = {}, base = [], gem_version_
2222
metadata_requirements, regular_requirements = requirements.partition {|dep| dep.name.end_with?("\0") }
2323
resolver = new(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms, metadata_requirements)
2424
result = resolver.start(requirements)
25-
SpecSet.new(SpecSet.new(result).for(regular_requirements))
25+
SpecSet.new(SpecSet.new(result).for(regular_requirements, false, platforms))
2626
end
2727

2828
def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms, metadata_requirements)
2929
@source_requirements = source_requirements
3030
@metadata_requirements = metadata_requirements
31-
@base = base
3231
@resolver = Molinillo::Resolver.new(self, self)
3332
@search_for = {}
3433
@base_dg = Molinillo::DependencyGraph.new
35-
@base.each do |ls|
34+
@base = base.materialized_for_resolution do |ls|
3635
dep = Dependency.new(ls.name, ls.version)
3736
@base_dg.add_vertex(ls.name, DepProxy.get_proxy(dep, ls.platform), true)
3837
end

lib/bundler/rubygems_ext.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,27 @@ class Platform
222222
MINGW = Gem::Platform.new("x86-mingw32")
223223
X64_MINGW = [Gem::Platform.new("x64-mingw32"),
224224
Gem::Platform.new("x64-mingw-ucrt")].freeze
225+
end
226+
227+
Platform.singleton_class.module_eval do
228+
unless Platform.singleton_methods.include?(:match_spec?)
229+
def match_spec?(spec)
230+
match_gem?(spec.platform, spec.name)
231+
end
232+
233+
def match_gem?(platform, gem_name)
234+
match_platforms?(platform, Gem.platforms)
235+
end
236+
237+
private
225238

226-
if RUBY_ENGINE == "truffleruby" && !defined?(REUSE_AS_BINARY_ON_TRUFFLERUBY)
227-
REUSE_AS_BINARY_ON_TRUFFLERUBY = %w[libv8 sorbet-static].freeze
239+
def match_platforms?(platform, platforms)
240+
platforms.any? do |local_platform|
241+
platform.nil? ||
242+
local_platform == platform ||
243+
(local_platform != Gem::Platform::RUBY && local_platform =~ platform)
244+
end
245+
end
228246
end
229247
end
230248

0 commit comments

Comments
 (0)