diff options
author | Homu <homu@barosl.com> | 2016-02-04 10:22:35 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-02-04 10:22:35 +0900 |
commit | 46c89b3a72a6e4abcf82b2e790bc63395eef05a6 (patch) | |
tree | 6e3bf7de4c588597fda30d574211b9227ee24aeb | |
parent | 0647f9645add95a9ec522b0f8a880b1745d67112 (diff) | |
parent | b0ee2bbb5faade27bf1e3c35c7428e788d5bf239 (diff) | |
download | bundler-46c89b3a72a6e4abcf82b2e790bc63395eef05a6.tar.gz |
Auto merge of #4265 - bundler:seg-simplify-exec, r=indirect
[Exec] Avoid loading the definition before exec-ing
Closes #2951, #2952.
@indirect it feels like I'm missing something?
-rw-r--r-- | lib/bundler.rb | 6 | ||||
-rw-r--r-- | lib/bundler/cli/exec.rb | 12 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 15 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 12 |
4 files changed, 19 insertions, 26 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 2e7f324002..b0f166040f 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -293,12 +293,12 @@ module Bundler def which(executable) if File.file?(executable) && File.executable?(executable) executable - elsif ENV["PATH"] - path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |p| + elsif path = ENV["PATH"] + executable_path = path.split(File::PATH_SEPARATOR).find do |p| abs_path = File.join(p, executable) File.file?(abs_path) && File.executable?(abs_path) end - path && File.expand_path(executable, path) + executable_path && File.expand_path(executable, executable_path) end end diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 4ccc4ba55a..77e75580f5 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -21,18 +21,12 @@ module Bundler ui = Bundler.ui raise ArgumentError if cmd.nil? - # First, try to exec directly to something in PATH SharedHelpers.set_bundle_environment bin_path = Bundler.which(@cmd) - if bin_path - Bundler.ui = nil - Kernel.exec([bin_path, @cmd], *args) - end - - # If that didn't work, set up the whole bundle - Bundler.definition.validate_ruby! - Bundler.load.setup_environment Bundler.ui = nil + # First, try to exec directly to something in PATH + Kernel.exec([bin_path, @cmd], *args) if bin_path + # Just exec using the given command Kernel.exec(@cmd, *args) rescue Errno::EACCES, Errno::ENOEXEC Bundler.ui = ui diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 6ef476b9dc..c2d5ad4b0a 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -13,7 +13,7 @@ module Bundler specs = groups.any? ? @definition.specs_for(groups) : requested_specs - setup_environment + SharedHelpers.set_bundle_environment Bundler.rubygems.replace_entrypoints(specs) # Activate the specs @@ -205,19 +205,6 @@ module Bundler output 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("../../../exe/bundle", __FILE__) - end - - # Set BUNDLE_GEMFILE - ENV["BUNDLE_GEMFILE"] = default_gemfile.to_s - - SharedHelpers.set_bundle_environment - end - private def prune_gem_cache(resolve, cache_path) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index ca26f7b4bf..654359d1ed 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -75,6 +75,7 @@ module Bundler end def set_bundle_environment + set_bundle_variables set_path set_rubyopt set_rubylib @@ -155,6 +156,17 @@ module Bundler end end + def set_bundle_variables + begin + ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.bin_path("bundler", "bundle", VERSION) + rescue Gem::GemNotFoundException + ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../exe/bundle", __FILE__) + end + + # Set BUNDLE_GEMFILE + ENV["BUNDLE_GEMFILE"] = find_gemfile.to_s + end + def set_path paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR) paths.unshift "#{Bundler.bundle_path}/bin" |