summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands/exec_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/commands/exec_command.rb')
-rw-r--r--lib/rubygems/commands/exec_command.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/rubygems/commands/exec_command.rb b/lib/rubygems/commands/exec_command.rb
index d588804290..1feafbdd35 100644
--- a/lib/rubygems/commands/exec_command.rb
+++ b/lib/rubygems/commands/exec_command.rb
@@ -57,8 +57,6 @@ to the same gem path as user-installed gems.
end
def execute
- gem_paths = { "GEM_HOME" => Gem.paths.home, "GEM_PATH" => Gem.paths.path.join(File::PATH_SEPARATOR), "GEM_SPEC_CACHE" => Gem.paths.spec_cache_dir }.compact
-
check_executable
print_command
@@ -74,9 +72,6 @@ to the same gem path as user-installed gems.
end
load!
- ensure
- ENV.update(gem_paths) if gem_paths
- Gem.clear_paths
end
private
@@ -143,7 +138,7 @@ to the same gem path as user-installed gems.
end
def set_gem_exec_install_paths
- home = File.join(Gem.dir, "gem_exec")
+ home = Gem.dir
ENV["GEM_PATH"] = ([home] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = home
@@ -178,6 +173,9 @@ to the same gem path as user-installed gems.
rescue Gem::InstallError => e
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
terminate_interaction 1
+ rescue Gem::DependencyResolutionError => e
+ alert_error "Error installing #{gem_name}:\n\t#{e.message}"
+ terminate_interaction 2
rescue Gem::GemNotFoundException => e
show_lookup_failure e.name, e.version, e.errors, false
@@ -200,7 +198,7 @@ to the same gem path as user-installed gems.
argv = ARGV.clone
ARGV.replace options[:args]
- exe = executable = options[:executable]
+ executable = options[:executable]
contains_executable = Gem.loaded_specs.values.select do |spec|
spec.executables.include?(executable)
@@ -211,13 +209,22 @@ to the same gem path as user-installed gems.
end
if contains_executable.empty?
- if (spec = Gem.loaded_specs[executable]) && (exe = spec.executable)
- contains_executable << spec
- else
+ spec = Gem.loaded_specs[executable]
+
+ if spec.nil? || spec.executables.empty?
alert_error "Failed to load executable `#{executable}`," \
" are you sure the gem `#{options[:gem_name]}` contains it?"
terminate_interaction 1
end
+
+ if spec.executables.size > 1
+ alert_error "Ambiguous which executable from gem `#{executable}` should be run: " \
+ "the options are #{spec.executables.sort}, specify one via COMMAND, and use `-g` and `-v` to specify gem and version"
+ terminate_interaction 1
+ end
+
+ contains_executable << spec
+ executable = spec.executable
end
if contains_executable.size > 1
@@ -227,8 +234,11 @@ to the same gem path as user-installed gems.
terminate_interaction 1
end
- load Gem.activate_bin_path(contains_executable.first.name, exe, ">= 0.a")
+ old_exe = $0
+ $0 = executable
+ load Gem.activate_bin_path(contains_executable.first.name, executable, ">= 0.a")
ensure
+ $0 = old_exe if old_exe
ARGV.replace argv
end