From a2ba489e2eff648b98054b1252e45a3c0643ab8e Mon Sep 17 00:00:00 2001 From: hsbt Date: Thu, 12 Nov 2015 04:50:06 +0000 Subject: * lib/rubygems: Update to RubyGems 2.5.0+ HEAD(db78980). this version includes #1367 , #1373 , #1375 * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/specification.rb | 84 ++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 28 deletions(-) (limited to 'lib/rubygems/specification.rb') diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 71b77884af..750cc1056f 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -740,23 +740,41 @@ class Gem::Specification < Gem::BasicSpecification end def self.gemspec_stubs_in dir, pattern - Dir[File.join(dir, pattern)].map { |path| - if dir == default_specifications_dir - Gem::StubSpecification.default_gemspec_stub(path) - else - Gem::StubSpecification.gemspec_stub(path) - end - }.select(&:valid?) + Dir[File.join(dir, pattern)].map { |path| yield path }.select(&:valid?) end private_class_method :gemspec_stubs_in + def self.default_stubs pattern + base_dir = Gem.default_dir + gems_dir = File.join base_dir, "gems" + gemspec_stubs_in(default_specifications_dir, pattern) do |path| + Gem::StubSpecification.default_gemspec_stub(path, base_dir, gems_dir) + end + end + private_class_method :default_stubs + + def self.installed_stubs dirs, pattern + map_stubs(dirs, pattern) do |path, base_dir, gems_dir| + Gem::StubSpecification.gemspec_stub(path, base_dir, gems_dir) + end + end + private_class_method :installed_stubs + if [].respond_to? :flat_map def self.map_stubs(dirs, pattern) # :nodoc: - dirs.flat_map { |dir| gemspec_stubs_in(dir, pattern) } + dirs.flat_map { |dir| + base_dir = File.dirname dir + gems_dir = File.join base_dir, "gems" + gemspec_stubs_in(dir, pattern) { |path| yield path, base_dir, gems_dir } + } end else # FIXME: remove when 1.8 is dropped def self.map_stubs(dirs, pattern) # :nodoc: - dirs.map { |dir| gemspec_stubs_in(dir, pattern) }.flatten 1 + dirs.map { |dir| + base_dir = File.dirname dir + gems_dir = File.join base_dir, "gems" + gemspec_stubs_in(dir, pattern) { |path| yield path, base_dir, gems_dir } + }.flatten 1 end end private_class_method :map_stubs @@ -803,7 +821,8 @@ class Gem::Specification < Gem::BasicSpecification def self.stubs @@stubs ||= begin - stubs = map_stubs([default_specifications_dir] + dirs, "*.gemspec") + pattern = "*.gemspec" + stubs = default_stubs(pattern).concat installed_stubs(dirs, pattern) stubs = uniq_by(stubs) { |stub| stub.full_name } _resort!(stubs) @@ -818,10 +837,11 @@ class Gem::Specification < Gem::BasicSpecification # Returns a Gem::StubSpecification for installed gem named +name+ def self.stubs_for name - if @@stubs || @@stubs_by_name[name] + if @@stubs @@stubs_by_name[name] || [] else - stubs = map_stubs([default_specifications_dir] + dirs, "#{name}-*.gemspec") + pattern = "#{name}-*.gemspec" + stubs = default_stubs(pattern) + installed_stubs(dirs, pattern) stubs = uniq_by(stubs) { |stub| stub.full_name }.group_by(&:name) stubs.each_value { |v| sort_by!(v) { |i| i.version } } @@ -1006,8 +1026,9 @@ class Gem::Specification < Gem::BasicSpecification # Return the best specification that contains the file matching +path+. def self.find_by_path path + path = path.dup.freeze stub = stubs.find { |spec| - spec.contains_requirable_file? path if spec + spec.contains_requirable_file? path } stub && stub.to_spec end @@ -1018,7 +1039,7 @@ class Gem::Specification < Gem::BasicSpecification def self.find_inactive_by_path path stub = stubs.find { |s| - s.contains_requirable_file? path unless s.nil? || s.activated? + s.contains_requirable_file? path unless s.activated? } stub && stub.to_spec end @@ -1030,7 +1051,7 @@ class Gem::Specification < Gem::BasicSpecification # TODO: do we need these?? Kill it specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten - specs.find_all { |spec| spec.contains_requirable_file? path if spec } + specs.find_all { |spec| spec.contains_requirable_file? path } end ## @@ -1924,23 +1945,10 @@ class Gem::Specification < Gem::BasicSpecification spec end - def find_full_gem_path # :nodoc: - super || File.expand_path(File.join(gems_dir, original_name)) - end - private :find_full_gem_path - def full_name @full_name ||= super end - ## - # The path to the gem.build_complete file within the extension install - # directory. - - def gem_build_complete_path # :nodoc: - File.join extension_dir, 'gem.build_complete' - end - ## # Work around bundler removing my methods @@ -1948,6 +1956,11 @@ class Gem::Specification < Gem::BasicSpecification super end + def gems_dir + # TODO: this logic seems terribly broken, but tests fail if just base_dir + @gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems") + end + ## # Deprecated and ignored, defaults to true. # @@ -1995,6 +2008,8 @@ class Gem::Specification < Gem::BasicSpecification def initialize name = nil, version = nil super() + @gems_dir = nil + @base_dir = nil @loaded = false @activated = false @loaded_from = nil @@ -2044,6 +2059,15 @@ class Gem::Specification < Gem::BasicSpecification end end + def base_dir + return Gem.dir unless loaded_from + @base_dir ||= if default_gem? then + File.dirname File.dirname File.dirname loaded_from + else + File.dirname File.dirname loaded_from + end + end + ## # Expire memoized instance variables that can incorrectly generate, replace # or miss files due changes in certain attributes used to compute them. @@ -2954,6 +2978,10 @@ open-ended dependency on #{dep} is not recommended alert_warning statement end + def raw_require_paths # :nodoc: + @require_paths + end + extend Gem::Deprecate # TODO: -- cgit v1.2.3