diff options
Diffstat (limited to 'lib/rubygems/core_ext')
-rw-r--r-- | lib/rubygems/core_ext/kernel_gem.rb | 9 | ||||
-rwxr-xr-x | lib/rubygems/core_ext/kernel_require.rb | 34 |
2 files changed, 20 insertions, 23 deletions
diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb index 3405233ab1..edce4ee10b 100644 --- a/lib/rubygems/core_ext/kernel_gem.rb +++ b/lib/rubygems/core_ext/kernel_gem.rb @@ -26,6 +26,11 @@ module Kernel # Kernel#gem should be called *before* any require statements (otherwise # RubyGems may load a conflicting library version). # + # Kernel#gem only loads prerelease versions when prerelease +requirements+ + # are given: + # + # gem 'rake', '>= 1.1.a', '< 2' + # # In older RubyGems versions, the environment variable GEM_SKIP could be # used to skip activation of specified gems, for example to test out changes # that haven't been installed yet. Now RubyGems defers to -I and the @@ -51,7 +56,9 @@ module Kernel end spec = Gem::Dependency.new(gem_name, *requirements).to_spec - spec.activate if spec + Gem::LOADED_SPECS_MUTEX.synchronize { + spec.activate + } if spec end private :gem diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 84bb03f67d..bf9618d3bf 100755 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -50,12 +50,8 @@ module Kernel # normal require handle loading a gem from the rescue below. if Gem::Specification.unresolved_deps.empty? then - begin - RUBYGEMS_ACTIVATION_MONITOR.exit - return gem_original_require(path) - ensure - RUBYGEMS_ACTIVATION_MONITOR.enter - end + RUBYGEMS_ACTIVATION_MONITOR.exit + return gem_original_require(path) end # If +path+ is for a gem that has already been loaded, don't @@ -71,8 +67,6 @@ module Kernel begin RUBYGEMS_ACTIVATION_MONITOR.exit return gem_original_require(path) - ensure - RUBYGEMS_ACTIVATION_MONITOR.enter end if spec # Attempt to find +path+ in any unresolved gems... @@ -105,6 +99,7 @@ module Kernel names = found_specs.map(&:name).uniq if names.size > 1 then + RUBYGEMS_ACTIVATION_MONITOR.exit raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}" end @@ -115,32 +110,27 @@ module Kernel unless valid then le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate" le.name = names.first + RUBYGEMS_ACTIVATION_MONITOR.exit raise le end valid.activate end - begin - RUBYGEMS_ACTIVATION_MONITOR.exit - return gem_original_require(path) - ensure - RUBYGEMS_ACTIVATION_MONITOR.enter - end + RUBYGEMS_ACTIVATION_MONITOR.exit + return gem_original_require(path) rescue LoadError => load_error + RUBYGEMS_ACTIVATION_MONITOR.enter + if load_error.message.start_with?("Could not find") or (load_error.message.end_with?(path) and Gem.try_activate(path)) then - begin - RUBYGEMS_ACTIVATION_MONITOR.exit - return gem_original_require(path) - ensure - RUBYGEMS_ACTIVATION_MONITOR.enter - end + RUBYGEMS_ACTIVATION_MONITOR.exit + return gem_original_require(path) + else + RUBYGEMS_ACTIVATION_MONITOR.exit end raise load_error - ensure - RUBYGEMS_ACTIVATION_MONITOR.exit end private :require |