summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2015-01-19 13:05:04 -0800
committerAndre Arko <andre@arko.net>2015-01-19 13:10:43 -0800
commit4251a1bfe29a7980f80bcaf3dc28fa0f4d3992b0 (patch)
tree16812ebba9af684353fec0c1e7d81e9b05bc76df
parentd3922e972570f6bd1144dfeade35d81b5830ac6e (diff)
downloadbundler-4251a1bfe29a7980f80bcaf3dc28fa0f4d3992b0.tar.gz
share bundle env setup between exec and Runtime
this means we only have to maintain setting up Bundler environment variables in one place
-rw-r--r--lib/bundler/cli/exec.rb69
-rw-r--r--lib/bundler/runtime.rb17
-rw-r--r--lib/bundler/shared_helpers.rb19
3 files changed, 37 insertions, 68 deletions
diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb
index 0ffd4f0bdf..7713906f26 100644
--- a/lib/bundler/cli/exec.rb
+++ b/lib/bundler/cli/exec.rb
@@ -15,64 +15,29 @@ module Bundler
end
def run
- begin
- if cmd.nil?
- raise ArgumentError.new
- end
+ raise ArgumentError if cmd.nil?
- execute_within_path
- rescue Errno::EACCES
- Bundler.ui.error "bundler: not executable: #{cmd}"
- exit 126
- rescue Errno::ENOENT
- Bundler.ui.error "bundler: command not found: #{cmd}"
- Bundler.ui.warn "Install missing gem executables with `bundle install`"
- exit 127
- rescue ArgumentError
- Bundler.ui.error "bundler: exec needs a command to run"
- exit 128
- end
- end
-
- private
-
- def execute_within_path
- if RUBY_VERSION >= "1.9"
- path.each do |path|
- bin_path = File.join(path, @cmd)
- if bin_path == Bundler.which(@cmd)
- Kernel.exec(build_env, bin_path, *args)
- end
- end
+ # First, try to exec directly to something in PATH
+ SharedHelpers.set_bundle_environment
+ bin_path = Bundler.which(@cmd)
+ if bin_path
+ Kernel.exec(bin_path, *args)
end
- # fallback
+ # If that didn't work, set up the whole bundle
Bundler.definition.validate_ruby!
Bundler.load.setup_environment
Kernel.exec(@cmd, *args)
- end
-
- def path
- ENV['PATH'].split(":").map { |p| File.expand_path(p) }
- end
-
- def build_env
- rubyopt = [ENV["RUBYOPT"]].compact
- if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/
- rubyopt << %|-rbundler/setup|
- end
-
- rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR)
- rubylib.unshift File.expand_path('../../..', __FILE__)
-
- {
- 'RUBYOPT' => rubyopt.join(' '),
- 'RUBYLIB' => rubylib.uniq.join(File::PATH_SEPARATOR)
- }
- end
-
- def env_string
- build_env.to_a.map { |k| "#{k[0]}=#{k[1]}"}.join(" ")
+ rescue Errno::EACCES
+ Bundler.ui.error "bundler: not executable: #{cmd}"
+ exit 126
+ rescue Errno::ENOENT
+ Bundler.ui.error "bundler: command not found: #{cmd}"
+ Bundler.ui.warn "Install missing gem executables with `bundle install`"
+ exit 127
+ rescue ArgumentError
+ Bundler.ui.error "bundler: exec needs a command to run"
+ exit 128
end
end
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 52377d270e..85299015d2 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -220,25 +220,10 @@ module Bundler
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|
- ENV["RUBYOPT"] = rubyopt.join(' ')
- end
-
- # Set RUBYLIB
- rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR)
- rubylib.unshift File.expand_path('../..', __FILE__)
- ENV["RUBYLIB"] = rubylib.uniq.join(File::PATH_SEPARATOR)
+ SharedHelpers.set_bundle_environment
end
private
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index b4c73f69bc..b7fdee1eb8 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -74,6 +74,25 @@ module Bundler
keys.each {|key| ENV[key] = old_env[key] }
end
+ def set_bundle_environment
+ # Set PATH
+ paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
+ paths.unshift "#{Bundler.bundle_path}/bin"
+ ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR)
+
+ # Set RUBYOPT
+ rubyopt = [ENV["RUBYOPT"]].compact
+ if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/
+ rubyopt.unshift %|-rbundler/setup|
+ ENV["RUBYOPT"] = rubyopt.join(' ')
+ end
+
+ # Set RUBYLIB
+ rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR)
+ rubylib.unshift File.expand_path('../..', __FILE__)
+ ENV["RUBYLIB"] = rubylib.uniq.join(File::PATH_SEPARATOR)
+ end
+
private
def find_gemfile