aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/cli.rb16
-rw-r--r--lib/bundler/runtime.rb24
-rw-r--r--lib/bundler/setup.rb2
-rw-r--r--lib/bundler/shared_helpers.rb6
-rw-r--r--spec/other/exec_spec.rb31
-rw-r--r--spec/support/helpers.rb3
-rw-r--r--spec/support/rubygems_ext.rb4
7 files changed, 64 insertions, 22 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index c882677f..3493f697 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 c7d6cbf7..fabda11b 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 68020dd2..9650f07e 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 0353055d..e15716b0 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 67bb1d4b..d18026b8 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 13de0508..b1940d33 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 0827fabc..d51fe70b 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