From 48089338b337cdd1af6f07373e9e9ce0a41f90f1 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Fri, 2 Jul 2010 14:24:01 -0700 Subject: Improve bundling bundler logic --- lib/bundler/definition.rb | 10 +++++++++- lib/bundler/runtime.rb | 1 + lib/bundler/source.rb | 21 ++++++++++++--------- lib/bundler/spec_set.rb | 12 ++++++++++++ spec/install/gems/simple_case_spec.rb | 10 ++++++++++ spec/runtime/load_spec.rb | 2 +- spec/runtime/setup_spec.rb | 2 +- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index ad0f1952b3..7170276273 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -70,7 +70,15 @@ module Bundler end def specs - @specs ||= resolve.materialize(requested_dependencies) + @specs ||= begin + specs = resolve.materialize(requested_dependencies) + + unless specs["bundler"].any? + specs["bundler"] = index.search(Gem::Dependency.new('bundler', VERSION)).last + end + + specs + end end def missing_specs diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index a1df6e3aaf..99f72bc7d2 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -77,6 +77,7 @@ module Bundler Bundler.ui.info "Updating .gem files in vendor/cache" specs.each do |spec| + next if spec.name == 'bundler' spec.source.cache(spec) if spec.source.respond_to?(:cache) end end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 79bb62595d..d6aebae5ec 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -146,21 +146,24 @@ module Bundler def installed_specs @installed_specs ||= begin idx = Index.new + have_bundler = false Gem::SourceIndex.from_installed_gems.to_a.reverse.each do |name, spec| - next if name == 'bundler' + have_bundler = true if name == 'bundler' && spec.version.to_s == VERSION spec.source = self idx << spec end # Always have bundler locally - bundler = Gem::Specification.new do |s| - s.name = 'bundler' - s.version = VERSION - s.platform = Gem::Platform::RUBY - s.source = self - # TODO: Remove this - s.loaded_from = 'w0t' + unless have_bundler + bundler = Gem::Specification.new do |s| + s.name = 'bundler' + s.version = VERSION + s.platform = Gem::Platform::RUBY + s.source = self + # TODO: Remove this + s.loaded_from = 'w0t' + end + idx << bundler end - idx << bundler idx end end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 193b0f4307..36faf1a6d5 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -18,6 +18,7 @@ module Bundler def for(dependencies, skip = [], check = false, match_current_platform = false) handled, deps, specs = {}, dependencies.dup, [] + skip << 'bundler' until deps.empty? dep = deps.shift @@ -44,6 +45,10 @@ module Bundler end end + if spec = lookup['bundler'].first + specs << spec + end + check ? true : SpecSet.new(specs) end @@ -56,6 +61,13 @@ module Bundler lookup[key].reverse end + def []=(key, value) + @specs << value + @lookup = nil + @sorted = nil + value + end + def to_a sorted.dup end diff --git a/spec/install/gems/simple_case_spec.rb b/spec/install/gems/simple_case_spec.rb index edc0ae6bec..41ecd797ed 100644 --- a/spec/install/gems/simple_case_spec.rb +++ b/spec/install/gems/simple_case_spec.rb @@ -478,6 +478,16 @@ describe "bundle install with gem sources" do out.should == "WIN" end + it "allows gem 'bundler' when Bundler is not in the Gemfile or its dependencies" do + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "rack" + G + + run "begin; gem 'bundler'; puts 'WIN'; rescue Gem::LoadError => e; puts e.backtrace; end" + out.should == "WIN" + end + it "causes a conflict if child dependencies conflict" do install_gemfile <<-G source "file://#{gem_repo2}" diff --git a/spec/runtime/load_spec.rb b/spec/runtime/load_spec.rb index b611ce7f09..2dd92308e8 100644 --- a/spec/runtime/load_spec.rb +++ b/spec/runtime/load_spec.rb @@ -29,7 +29,7 @@ describe "Bundler.load" do G env = Bundler.load - env.gems.should have_gem("rack-1.0.0") + env.gems.should have_gem("rack-1.0.0", "bundler-#{Bundler::VERSION}") end it "raises an exception if the default gemfile is not found" do diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 9d8f4f23c2..f7b69ace33 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -79,7 +79,7 @@ describe "Bundler.setup" do it "removes system gems from Gem.source_index" do run "require 'yard'" - out.should == "yard-1.0" + out.should == "bundler-#{Bundler::VERSION}\nyard-1.0" end end end -- cgit v1.2.1