Permalink
Browse files

bundle exec does less work

It isn't necessary for bundle exec to load up
and test the entire environment, when the process
it is exec'ing into has to do the same work
anyway.

This change makes bundle exec do the minimal env
setup work, and defer the checking to the
subprocess it is `exec`ing to.
  • Loading branch information...
1 parent 4449672 commit f96d7e75121563bf2a3a45db9d4d9d775ab0be56 tomhuda committed with hone May 20, 2012
View
@@ -216,6 +216,31 @@ def clean_exec(*args)
with_clean_env { Kernel.exec(*args) }
end
+ def setup_environment
+ begin
+ ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.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
+
+
def default_gemfile
SharedHelpers.default_gemfile
end
View
@@ -419,8 +419,7 @@ def package
def exec(*)
ARGV.shift # remove "exec"
- Bundler.definition.validate_ruby!
- Bundler.load.setup_environment
+ Bundler.setup_environment
begin
# Run
View
@@ -201,27 +201,7 @@ def clean
end
def setup_environment
- begin
- ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.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
+ Bundler.setup_environment
end
private
View
@@ -2,8 +2,12 @@ module Bundler
class Settings
def initialize(root)
@root = root
- @local_config = (File.exist?(local_config_file) && yaml = YAML.load_file(local_config_file)) ? yaml : {}
- @global_config = (File.exist?(global_config_file) && yaml = YAML.load_file(global_config_file)) ? yaml : {}
+
+ local_config_exists = File.exists?(local_config_file) && File.size(local_config_file).nonzero?
+ @local_config = (local_config_exists && yaml = YAML.load_file(local_config_file)) ? yaml : {}
+
+ global_config_exists = File.exists?(global_config_file) && File.size(global_config_file).nonzero?
+ @global_config = (global_config_exists && yaml = YAML.load_file(global_config_file)) ? yaml : {}
end
def [](key)
@@ -315,27 +315,34 @@
end
it "doesn't blow up when the local .bundle/config is empty" do
+ config_file = bundled_app(".bundle/config")
FileUtils.mkdir_p(bundled_app(".bundle"))
- FileUtils.touch(bundled_app(".bundle/config"))
+ FileUtils.touch(config_file)
install_gemfile(<<-G, :exitstatus => true)
source "file://#{gem_repo1}"
gem 'foo'
G
exitstatus.should == 0
+ File.exists?(config_file).should be_true
+ File.size(config_file).should be_zero
end
it "doesn't blow up when the global .bundle/config is empty" do
+ config_file = "#{Bundler.rubygems.user_home}/.bundle/config"
FileUtils.mkdir_p("#{Bundler.rubygems.user_home}/.bundle")
- FileUtils.touch("#{Bundler.rubygems.user_home}/.bundle/config")
+ FileUtils.touch(config_file)
install_gemfile(<<-G, :exitstatus => true)
source "file://#{gem_repo1}"
gem 'foo'
G
+
exitstatus.should == 0
+ File.exists?(config_file).should be_true
+ File.size(config_file).should be_zero
end
end
@@ -25,6 +25,20 @@
it_should_behave_like "Bundler.with_*_env"
+ it "should keep the original GEM_PATH even in sub processes" do
+ gemfile ""
+ bundle "install --path vendor/bundle"
+
+ gem_path = ENV['GEM_PATH']
+
+ code = "Bundler.with_clean_env do;" +
+ " print ENV['GEM_PATH'] != '';" +
+ "end"
+
+ result = bundle "exec ruby -e #{code.inspect}"
+ result.should == "true"
+ end
+
it "should not pass any bundler environment variables" do
Bundler.with_clean_env do
`echo $BUNDLE_PATH`.strip.should_not == './Gemfile'

0 comments on commit f96d7e7

Please sign in to comment.