lib/bundler/lazy_specification.rb in bundler-2.3.26 vs lib/bundler/lazy_specification.rb in bundler-2.3.27

- old
+ new

@@ -11,11 +11,10 @@ @name = name @version = version @dependencies = [] @platform = platform || Gem::Platform::RUBY @source = source - @specification = nil end def full_name if platform == Gem::Platform::RUBY "#{@name}-#{@version}" @@ -74,41 +73,50 @@ end 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(Dependency.new(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, :fallback_to_non_installable => false) + 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?) + if target_platform != platform + installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform) 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 + + installable_candidates end + + __materialize__(candidates) end - def respond_to?(*args) - super || @specification ? @specification.respond_to?(*args) : nil + # If in frozen mode, we fallback to a non-installable candidate because by + # doing this we avoid re-resolving and potentially end up changing the + # lock file, which is not allowed. In that case, we will give a proper error + # about the mismatch higher up the stack, right before trying to install the + # bad gem. + def __materialize__(candidates, fallback_to_non_installable: Bundler.frozen_bundle?) + search = candidates.reverse.find do |spec| + spec.is_a?(StubSpecification) || + (spec.matches_current_ruby? && + spec.matches_current_rubygems?) + end + if search.nil? && fallback_to_non_installable + 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 @__to_s ||= if platform == Gem::Platform::RUBY "#{name} (#{version})" @@ -126,19 +134,11 @@ " #{source.revision[0..6]}" end 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 # # For backwards compatibility with existing lockfiles, if the most specific # locked platform is not a specific platform like x86_64-linux or