Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 1f254edcb192369895e89a8052ca437af025698e 1 parent a267192
tomhuda authored
View
25 lib/bundler.rb
@@ -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
3  lib/bundler/cli.rb
@@ -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
22 lib/bundler/runtime.rb
@@ -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
8 lib/bundler/settings.rb
@@ -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)
View
11 spec/install/gems/simple_case_spec.rb
@@ -315,8 +315,9 @@
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}"
@@ -324,18 +325,24 @@
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
View
14 spec/runtime/with_clean_env_spec.rb
@@ -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'
Please sign in to comment.
Something went wrong with that request. Please try again.