diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-08 01:32:18 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-08 01:32:18 +0000 |
commit | c00e84327f14845bd484e76b5ee5dfeb1fa9ce3d (patch) | |
tree | 9f558dafa363f4f0118d504a50cd4461e2821cd1 /lib/rubygems.rb | |
parent | 6b05153a3a75b74b64553d6a46f501d9ee0f0376 (diff) |
Merge rubygems master.
This is RC version of Rubygems 2.7.0.
https://github.com/rubygems/rubygems/commit/688fb7e83c13c3fe7c2bb03c49a2db4c82852aee
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r-- | lib/rubygems.rb | 113 |
1 files changed, 78 insertions, 35 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 55aa85b8b2..d819bdee02 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -39,7 +39,7 @@ require 'rubygems/errors' # Further RubyGems documentation can be found at: # # * {RubyGems Guides}[http://guides.rubygems.org] -# * {RubyGems API}[http://rubygems.rubyforge.org/rdoc] (also available from +# * {RubyGems API}[http://www.rubydoc.info/github/rubygems/rubygems] (also available from # <tt>gem server</tt>) # # == RubyGems Plugins @@ -47,15 +47,16 @@ require 'rubygems/errors' # As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or # $LOAD_PATH. Plugins must be named 'rubygems_plugin' (.rb, .so, etc) and # placed at the root of your gem's #require_path. Plugins are discovered via -# Gem::find_files then loaded. Take care when implementing a plugin as your +# Gem::find_files and then loaded. Take care when implementing a plugin as your # plugin file may be loaded multiple times if multiple versions of your gem # are installed. # -# For an example plugin, see the graph gem which adds a `gem graph` command. +# For an example plugin, see the {Graph gem}[https://github.com/seattlerb/graph] +# which adds a `gem graph` command. # # == RubyGems Defaults, Packaging # -# RubyGems defaults are stored in rubygems/defaults.rb. If you're packaging +# RubyGems defaults are stored in lib/rubygems/defaults.rb. If you're packaging # RubyGems or implementing Ruby you can change RubyGems' defaults. # # For RubyGems packagers, provide lib/rubygems/defaults/operating_system.rb @@ -65,7 +66,7 @@ require 'rubygems/errors' # override any defaults from lib/rubygems/defaults.rb. # # If you need RubyGems to perform extra work on install or uninstall, your -# defaults override file can set pre and post install and uninstall hooks. +# defaults override file can set pre/post install and uninstall hooks. # See Gem::pre_install, Gem::pre_uninstall, Gem::post_install, # Gem::post_uninstall. # @@ -106,6 +107,8 @@ require 'rubygems/errors' # # (If your name is missing, PLEASE let us know!) # +# == License +# # See {LICENSE.txt}[rdoc-ref:lib/rubygems/LICENSE.txt] for permissions. # # Thanks! @@ -130,6 +133,7 @@ module Gem GEM_DEP_FILES = %w[ gem.deps.rb + gems.rb Gemfile Isolate ] @@ -159,7 +163,7 @@ module Gem # these are defined in Ruby 1.8.7, hence the need for this convoluted setup. READ_BINARY_ERRORS = begin - read_binary_errors = [Errno::EACCES] + read_binary_errors = [Errno::EACCES, Errno::EROFS] read_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP) read_binary_errors end.freeze @@ -174,6 +178,8 @@ module Gem write_binary_errors end.freeze + USE_BUNDLER_FOR_GEMDEPS = true # :nodoc: + @@win_platform = nil @configuration = nil @@ -266,17 +272,22 @@ module Gem return loaded if loaded && dep.matches_spec?(loaded) - specs = dep.matching_specs(true) - - raise Gem::GemNotFoundException, - "can't find gem #{dep}" if specs.empty? + find_specs = proc { dep.matching_specs(true) } + if dep.to_s == "bundler (>= 0.a)" + specs = Gem::BundlerVersionFinder.without_filtering(&find_specs) + else + specs = find_specs.call + end specs = specs.find_all { |spec| spec.executables.include? exec_name } if exec_name unless spec = specs.first - msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}" + msg = "can't find gem #{dep} with executable #{exec_name}" + if name == "bundler" && bundler_message = Gem::BundlerVersionFinder.missing_version_message + msg = bundler_message + end raise Gem::GemNotFoundException, msg end @@ -297,7 +308,10 @@ module Gem def self.activate_bin_path name, exec_name, requirement # :nodoc: spec = find_spec_for_exe name, exec_name, [requirement] - Gem::LOADED_SPECS_MUTEX.synchronize { spec.activate } + Gem::LOADED_SPECS_MUTEX.synchronize do + spec.activate + finish_resolve + end spec.bin_file exec_name end @@ -356,12 +370,16 @@ module Gem # package is not available as a gem, return nil. def self.datadir(gem_name) -# TODO: deprecate spec = @loaded_specs[gem_name] return nil if spec.nil? spec.datadir end + class << self + extend Gem::Deprecate + deprecate :datadir, "spec.datadir", 2016, 10 + end + ## # A Zlib::Deflate.deflate wrapper @@ -594,7 +612,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Zlib::GzipReader wrapper that unzips +data+. def self.gunzip(data) - require 'rubygems/util' Gem::Util.gunzip data end @@ -602,7 +619,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Zlib::GzipWriter wrapper that zips +data+. def self.gzip(data) - require 'rubygems/util' Gem::Util.gzip data end @@ -610,7 +626,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # A Zlib::Inflate#inflate wrapper def self.inflate(data) - require 'rubygems/util' Gem::Util.inflate data end @@ -715,9 +730,20 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} ## # The file name and line number of the caller of the caller of this method. + # + # +depth+ is how many layers up the call stack it should go. + # + # e.g., + # + # def a; Gem.location_of_caller; end + # a #=> ["x.rb", 2] # (it'll vary depending on file name and line number) + # + # def b; c; end + # def c; Gem.location_of_caller(2); end + # b #=> ["x.rb", 6] # (it'll vary depending on file name and line number) - def self.location_of_caller - caller[1] =~ /(.*?):(\d+).*?$/i + def self.location_of_caller(depth = 1) + caller[depth] =~ /(.*?):(\d+).*?$/i file = $1 lineno = $2.to_i @@ -1148,8 +1174,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} path = path.dup if path == "-" then - require 'rubygems/util' - Gem::Util.traverse_parents Dir.pwd do |directory| dep_file = GEM_DEP_FILES.find { |f| File.file?(f) } @@ -1168,18 +1192,36 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} raise ArgumentError, "Unable to find gem dependencies file at #{path}" end - rs = Gem::RequestSet.new - @gemdeps = rs.load_gemdeps path + if USE_BUNDLER_FOR_GEMDEPS + + ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path) + require 'rubygems/user_interaction' + Gem::DefaultUserInteraction.use_ui(ui) do + require "bundler" + @gemdeps = Bundler.setup + Bundler.ui = nil + @gemdeps.requested_specs.map(&:to_spec).sort_by(&:name) + end + + else + + rs = Gem::RequestSet.new + @gemdeps = rs.load_gemdeps path + + rs.resolve_current.map do |s| + s.full_spec.tap(&:activate) + end - rs.resolve_current.map do |s| - sp = s.full_spec - sp.activate - sp end - rescue Gem::LoadError, Gem::UnsatisfiableDependencyError => e - warn e.message - warn "You may need to `gem install -g` to install missing gems" - warn "" + rescue => e + case e + when Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError) + warn e.message + warn "You may need to `gem install -g` to install missing gems" + warn "" + else + raise + end end class << self @@ -1225,6 +1267,8 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} prefix_pattern = /^(#{prefix_group})/ end + suffix_pattern = /#{Regexp.union(Gem.suffixes)}\z/ + spec.files.each do |file| if new_format file = file.sub(prefix_pattern, "") @@ -1232,6 +1276,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end @path_to_default_spec_map[file] = spec + @path_to_default_spec_map[file.sub(suffix_pattern, "")] = spec end end @@ -1239,11 +1284,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Find a Gem::Specification of default gem from +path+ def find_unresolved_default_spec(path) - Gem.suffixes.each do |suffix| - spec = @path_to_default_spec_map["#{path}#{suffix}"] - return spec if spec - end - nil + @path_to_default_spec_map[path] end ## @@ -1314,6 +1355,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/" + autoload :BundlerVersionFinder, 'rubygems/bundler_version_finder' autoload :ConfigFile, 'rubygems/config_file' autoload :Dependency, 'rubygems/dependency' autoload :DependencyList, 'rubygems/dependency_list' @@ -1329,6 +1371,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} autoload :SourceList, 'rubygems/source_list' autoload :SpecFetcher, 'rubygems/spec_fetcher' autoload :Specification, 'rubygems/specification' + autoload :Util, 'rubygems/util' autoload :Version, 'rubygems/version' require "rubygems/specification" |