diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-07-21 14:58:51 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-07-21 14:58:51 -0700 |
commit | 2dabdc36ed2f0d725a5c7930fe492f48755b675e (patch) | |
tree | 3101ddbe6b68d08358df83761db23a8b51a8da0c | |
parent | 424e233b9849d7ebf074e2405e3ad3dc180d7147 (diff) | |
download | bundler-2dabdc36ed2f0d725a5c7930fe492f48755b675e.tar.gz |
Fix a bug where `bundle exec bundle *` and shelling out to bundle from inside a bundle failed in some cases
-rw-r--r-- | lib/bundler/cli.rb | 16 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 24 | ||||
-rw-r--r-- | lib/bundler/setup.rb | 2 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 6 | ||||
-rw-r--r-- | spec/other/exec_spec.rb | 31 | ||||
-rw-r--r-- | spec/support/helpers.rb | 3 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 4 |
7 files changed, 64 insertions, 22 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index c882677f82..3493f69770 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -212,21 +212,7 @@ module Bundler def exec(*) ARGV.delete("exec") - # Set PATH - paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR) - paths.unshift "#{Bundler.bundle_path}/bin" - ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR) - - # Set BUNDLE_GEMFILE - ENV["BUNDLE_GEMFILE"] = Bundler::SharedHelpers.default_gemfile.to_s - - # Set RUBYOPT - rubyopt = [ENV["RUBYOPT"]].compact - if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/ - rubyopt.unshift "-rbundler/setup" - rubyopt.unshift "-I#{File.expand_path('../..', __FILE__)}" - ENV["RUBYOPT"] = rubyopt.join(' ') - end + Bundler.setup begin # Run diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index c7d6cbf728..fabda11b80 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -10,6 +10,7 @@ module Bundler specs = groups.any? ? @definition.specs_for(groups) : requested_specs + setup_environment cripple_rubygems(specs) # Activate the specs @@ -120,5 +121,28 @@ module Bundler root.join("vendor/cache") end + def setup_environment + begin + ENV["BUNDLE_BIN_PATH"] = Gem.bin_path("bundler", "bundle", VERSION) + rescue Gem::GemNotFoundException + ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../bin/bundle", __FILE__) + end + + # Set PATH + paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR) + paths.unshift "#{Bundler.bundle_path}/bin" + ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR) + + # Set BUNDLE_GEMFILE + ENV["BUNDLE_GEMFILE"] = default_gemfile.to_s + + # Set RUBYOPT + rubyopt = [ENV["RUBYOPT"]].compact + if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/ + rubyopt.unshift "-rbundler/setup" + rubyopt.unshift "-I#{File.expand_path('../..', __FILE__)}" + ENV["RUBYOPT"] = rubyopt.join(' ') + end + end end end diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index 68020dd2b5..9650f07ea7 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -12,4 +12,4 @@ if Bundler::SharedHelpers.in_bundle? # Add bundler to the load path after disabling system gems bundler_lib = File.expand_path("../..", __FILE__) $LOAD_PATH.unshift(bundler_lib) unless $LOAD_PATH.include?(bundler_lib) -end
\ No newline at end of file +end diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 0353055d3d..e15716b008 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -121,6 +121,10 @@ module Bundler gem_class.send(:define_method, :bin_path) do |name, *args| exec_name, *reqs = args + if exec_name == 'bundle' + return ENV['BUNDLE_BIN_PATH'] + end + spec = nil if exec_name @@ -141,4 +145,4 @@ module Bundler extend self end -end
\ No newline at end of file +end diff --git a/spec/other/exec_spec.rb b/spec/other/exec_spec.rb index 67bb1d4bf6..d18026b816 100644 --- a/spec/other/exec_spec.rb +++ b/spec/other/exec_spec.rb @@ -207,4 +207,33 @@ describe "bundle exec" do end end -end
\ No newline at end of file + + describe "bundling bundler" do + before(:each) do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "install vendor --disable-shared-gems" + end + + it "does not explode with --disable-shared-gems" do + bundle "exec bundle check", :exit_status => true + exitstatus.should == 0 + end + + it "does not explode when starting with Bundler.setup" do + ruby <<-R + require "rubygems" + require "bundler" + Bundler.setup + puts `bundle check` + puts $? + R + + out.should include("satisfied") + out.should include("\n0") + end + end +end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 13de050865..b1940d33a2 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -64,8 +64,7 @@ module Spec def ruby(ruby, options = {}) expect_err = options.delete(:expect_err) - ruby.gsub!(/(?=")/, "\\") - ruby.gsub!('$', '\\$') + ruby.gsub!(/["`\$]/) {|m| "\\#{m}" } sys_exec(%'#{Gem.ruby} -I#{lib} -e "#{ruby}"', expect_err) end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index 0827fabcf0..d51fe70b2d 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -5,7 +5,7 @@ module Spec ENV['BUNDLE_PATH'] = nil ENV['GEM_HOME'] = ENV['GEM_PATH'] = Path.base_system_gems.to_s - ENV['PATH'] = "#{Path.home}/.bundle/bin:#{Path.system_gem_path}/bin:#{ENV['PATH']}" + ENV['PATH'] = "#{Path.root}/bin:#{Path.system_gem_path}/bin:#{ENV['PATH']}" unless File.exist?("#{Path.base_system_gems}") FileUtils.mkdir_p(Path.base_system_gems) @@ -27,4 +27,4 @@ module Spec %x{#{Gem.ruby} -I#{lib} -rubygems -S gem --backtrace #{command} #{args}}.strip end end -end
\ No newline at end of file +end |