diff options
author | Terence Lee <hone02@gmail.com> | 2013-03-10 16:19:49 -0700 |
---|---|---|
committer | Terence Lee <hone02@gmail.com> | 2013-03-10 16:24:15 -0700 |
commit | 7dd7e49f0d831c804b1db9aa3a0459f43387efa7 (patch) | |
tree | a5291eef67cb0c89408f0a203f8e432b64fc561b | |
parent | 4f2ea14a1123a6a746100a61bd2527dcf6738611 (diff) | |
download | bundler-checksum.tar.gz |
initial spike generating some checksums for Gemfile.lockchecksum
-rw-r--r-- | lib/bundler/definition.rb | 13 | ||||
-rw-r--r-- | lib/bundler/dependency.rb | 4 | ||||
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 6 | ||||
-rw-r--r-- | spec/install/gems/simple_case_spec.rb | 22 |
4 files changed, 43 insertions, 2 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 76d477f3d3..0f5a2a3dfc 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -281,6 +281,16 @@ module Bundler def checksum(file) contents = "" + handled = [] + dependencies.map {|d| + d.all_deps(d) }.flatten. + sort_by { |d| d.to_s }. + each do |dep| + next if handled.include?(dep.name) + contents << dep.to_checksum + contents << "\n" + handled << dep.name + end File.open(file, 'wb'){|f| f.puts(contents) } rescue Errno::EACCES @@ -290,6 +300,9 @@ module Bundler "#{File.expand_path(file)}" end + def to_checksum + end + def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false) changes = false diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 7f153f236c..01c3a68059 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -79,6 +79,10 @@ module Bundler out << "\n" end + def to_checksum + out = super + end + private def on_18? diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 3a41be0187..177c477d83 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -92,6 +92,7 @@ module Gem end class Dependency + require 'digest/sha2' attr_accessor :source, :groups alias eql? == @@ -115,6 +116,11 @@ module Gem out end + def to_checksum + spec = to_spec + "#{spec.full_name}:#{Digest::SHA256.hexdigest(File.read(spec.cache_file))}" + end + def all_deps(dep = self) deps = dep.to_spec.dependencies.select {|d| d.type == :runtime } diff --git a/spec/install/gems/simple_case_spec.rb b/spec/install/gems/simple_case_spec.rb index 8ee4b0f97a..5ca917f82d 100644 --- a/spec/install/gems/simple_case_spec.rb +++ b/spec/install/gems/simple_case_spec.rb @@ -340,14 +340,32 @@ describe "bundle install with gem sources" do end context "Gemfile.lock.asc" do + require 'digest/sha2' + it "creates a Gemfile.lock.asc" do - install_gemfile(<<-G) + gemfile(<<-G) source "file://#{gem_repo1}" - gem 'foo' + gem 'thin' G + bundle "install --path vendor/bundle" + + ruby_version = Bundler::SystemRubyVersion.new + ruby_abi = RbConfig::CONFIG['ruby_version'] + cache_dir = "vendor/bundle/#{ruby_version.engine}/#{ruby_abi}/cache" + hashes = {} + ['thin-1.0', 'rack-1.0.0'].each do |gem| + hashes[gem] = Digest::SHA256.hexdigest(File.read(bundled_app("#{cache_dir}/#{gem}.gem"))) + end + expect(bundled_app("Gemfile.lock.asc")).to exist + + contents = File.read(bundled_app("Gemfile.lock.asc")).split("\n") + contents.each do |line| + gem, checksum = line.split(":") + expect(hashes[gem]).to eq(checksum) + end end context "on empty Gemfile" do |