Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ def converge_sources
end
end

sources.metadata_source.checksum_store.merge!(@locked_gems.metadata_source.checksum_store) if @locked_gems

changes
end

Expand Down
15 changes: 14 additions & 1 deletion bundler/lib/bundler/lockfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def add_checksums
checksums = definition.resolve.map do |spec|
spec.source.checksum_store.to_lock(spec)
end
add_section("CHECKSUMS", checksums)

add_section("CHECKSUMS", checksums + bundler_checksum)
end

def add_locked_ruby_version
Expand Down Expand Up @@ -100,5 +101,17 @@ def add_section(name, value)
raise ArgumentError, "#{value.inspect} can't be serialized in a lockfile"
end
end

def bundler_checksum
return [] if Bundler.gem_version.to_s.end_with?(".dev")

require "rubygems/package"

bundler_spec = definition.sources.metadata_source.specs.search(["bundler", Bundler.gem_version]).last
package = Gem::Package.new(bundler_spec.cache_file)
definition.sources.metadata_source.checksum_store.register(bundler_spec, Checksum.from_gem_package(package))

[definition.sources.metadata_source.checksum_store.to_lock(bundler_spec)]
end
end
end
9 changes: 8 additions & 1 deletion bundler/lib/bundler/lockfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def to_s

attr_reader(
:sources,
:metadata_source,
:dependencies,
:specs,
:platforms,
Expand Down Expand Up @@ -97,6 +98,7 @@ def self.bundled_with
def initialize(lockfile, strict: false)
@platforms = []
@sources = []
@metadata_source = Source::Metadata.new
@dependencies = {}
@parse_method = nil
@specs = {}
Expand Down Expand Up @@ -252,7 +254,12 @@ def parse_checksum(line)
version = Gem::Version.new(version)
platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
full_name = Gem::NameTuple.new(name, version, platform).full_name
return unless spec = @specs[full_name]
spec = @specs[full_name]

if name == "bundler"
spec ||= LazySpecification.new(name, version, platform, @metadata_source)
end
return unless spec

if checksums
checksums.split(",") do |lock_checksum|
Expand Down
4 changes: 4 additions & 0 deletions bundler/lib/bundler/source/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def hash
def version_message(spec)
"#{spec.name} #{spec.version}"
end

def checksum_store
@checksum_store ||= Checksum::Store.new
end
end
end
end
3 changes: 3 additions & 0 deletions bundler/spec/commands/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@

checksums = checksums_section do |c|
c.checksum(gem_repo4, "myrack", "1.0")
c.checksum(gem_repo4, "bundler", "999.0.0")
end

install_gemfile <<-G
Expand Down Expand Up @@ -1621,6 +1622,7 @@

checksums = checksums_section do |c|
c.checksum(gem_repo4, "myrack", "1.0")
c.checksum(gem_repo4, "bundler", "9.9.9")
end

install_gemfile <<-G
Expand Down Expand Up @@ -1745,6 +1747,7 @@
# Only updates properly on modern RubyGems.
checksums = checksums_section_when_enabled do |c|
c.checksum(gem_repo4, "myrack", "1.0")
c.checksum(local_gem_path, "bundler", "9.0.0", Gem::Platform::RUBY, "cache")
end

expect(lockfile).to eq <<~L
Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/support/checksums.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def initialize_copy(original)
@checksums = @checksums.dup
end

def checksum(repo, name, version, platform = Gem::Platform::RUBY)
def checksum(repo, name, version, platform = Gem::Platform::RUBY, folder = "gems")
name_tuple = Gem::NameTuple.new(name, version, platform)
gem_file = File.join(repo, "gems", "#{name_tuple.full_name}.gem")
gem_file = File.join(repo, folder, "#{name_tuple.full_name}.gem")
File.open(gem_file, "rb") do |f|
register(name_tuple, Bundler::Checksum.from_gem(f, "#{gem_file} (via ChecksumsBuilder#checksum)"))
end
Expand Down
Loading