Class: Bundler::Patch::DefinitionPrep

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/patch/conservative_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundler_def, gem_patches, options) ⇒ DefinitionPrep

Returns a new instance of DefinitionPrep.



65
66
67
68
69
# File 'lib/bundler/patch/conservative_definition.rb', line 65

def initialize(bundler_def, gem_patches, options)
  @bundler_def = bundler_def
  @gems_to_update = GemsToPatch.new(gem_patches)
  @options = options
end

Instance Attribute Details

#bundler_defObject (readonly)

Returns the value of attribute bundler_def.



63
64
65
# File 'lib/bundler/patch/conservative_definition.rb', line 63

def bundler_def
  @bundler_def
end

Instance Method Details

#fixup_empty_remotesObject

This came out a real-life case with sidekiq and sidekiq-pro where the sidekiq-pro gem is served from their gem server and depends on the open-source sidekiq gem served from rubygems.org, and when patching those, without the appropriate remotes being set in rubygems_aggregrate, it won’t work.

The underlying issue in Bundler 1.10 appears to be when the Definition constructor receives ‘true` as the `unlock` parameter, then @locked_sources is initialized to empty array, and the related rubygems_aggregrate source instance ends up with no @remotes set in it, which I think happens during converge_sources. Without those set, then the index will list no gem versions in some cases. (It was complicated enough to discover this patch, I haven’t fully worked out the flaw, though I believe I recreated the problem with plain ol ‘bundle update`).



98
99
100
101
102
103
104
105
106
# File 'lib/bundler/patch/conservative_definition.rb', line 98

def fixup_empty_remotes
  STDERR.puts 'fixing empty remotes' if ENV['DEBUG_PATCH_RESOLVER']
  b_sources = @bundler_def.send(:sources)
  empty_remotes = b_sources.rubygems_sources.detect { |s| s.remotes.empty? }
  STDERR.puts "empty_remotes: <#{empty_remotes}>" if ENV['DEBUG_PATCH_RESOLVER']
  empty_remotes.remotes.push(*b_sources.rubygems_remotes) if empty_remotes
  empty_remotes = b_sources.rubygems_sources.detect { |s| s.remotes.empty? }
  STDERR.puts "empty_remotes after fixed: <#{empty_remotes}>" if ENV['DEBUG_PATCH_RESOLVER']
end

#prepObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bundler/patch/conservative_definition.rb', line 71

def prep
  @bundler_def ||= Bundler.definition(@gems_to_update.to_bundler_definition)
  @bundler_def.extend ConservativeDefinition

  # Starting with 1.17, this method has to be called externally, which isn't
  # ideal in my opinion since the Definition class depends on it.
  # https://github.com/bundler/bundler/commit/22f15209b87e0b0792c8a393549e1a10c963d59c
  @bundler_def.gem_version_promoter if @bundler_def.respond_to?(:gem_version_promoter)

  @bundler_def.gems_to_update = @gems_to_update
  @bundler_def.strict = @options[:strict]
  @bundler_def.minor_preferred = @options[:minor]
  @bundler_def.prefer_minimal = @options[:minimal]
  fixup_empty_remotes if @gems_to_update.to_bundler_definition === true
  @bundler_def
end