summaryrefslogtreecommitdiff
path: root/lib/rubygems/specification.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/specification.rb')
-rw-r--r--lib/rubygems/specification.rb56
1 files changed, 30 insertions, 26 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index d59f57c49f..7206c3eaf0 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -182,6 +182,7 @@ class Gem::Specification < Gem::BasicSpecification
@@default_value[k].nil?
end
+ @@stubs = nil
@@stubs_by_name = {}
# Sentinel object to represent "not found" stubs
@@ -665,6 +666,9 @@ class Gem::Specification < Gem::BasicSpecification
#
# # Only prereleases or final releases after 2.6.0.preview2
# spec.required_ruby_version = '> 2.6.0.preview2'
+ #
+ # # This gem will work with 2.3.0 or greater, including major version 3, but lesser than 4.0.0
+ # spec.required_ruby_version = '>= 2.3', '< 4'
def required_ruby_version=(req)
@required_ruby_version = Gem::Requirement.create req
@@ -800,10 +804,8 @@ class Gem::Specification < Gem::BasicSpecification
def self.stubs
@@stubs ||= begin
pattern = "*.gemspec"
- stubs = installed_stubs(dirs, pattern) + default_stubs(pattern)
- stubs = stubs.uniq {|stub| stub.full_name }
+ stubs = stubs_for_pattern(pattern, false)
- _resort!(stubs)
@@stubs_by_name = stubs.select {|s| Gem::Platform.match_spec? s }.group_by(&:name)
stubs
end
@@ -820,31 +822,40 @@ class Gem::Specification < Gem::BasicSpecification
end
end
- EMPTY = [].freeze # :nodoc:
-
##
# Returns a Gem::StubSpecification for installed gem named +name+
# only returns stubs that match Gem.platforms
def self.stubs_for(name)
- if @@stubs_by_name[name]
- @@stubs_by_name[name]
+ if @@stubs
+ @@stubs_by_name[name] || []
else
- pattern = "#{name}-*.gemspec"
- stubs = installed_stubs(dirs, pattern).select {|s| Gem::Platform.match_spec? s } + default_stubs(pattern)
- stubs = stubs.uniq {|stub| stub.full_name }.group_by(&:name)
- stubs.each_value {|v| _resort!(v) }
-
- @@stubs_by_name.merge! stubs
- @@stubs_by_name[name] ||= EMPTY
+ @@stubs_by_name[name] ||= stubs_for_pattern("#{name}-*.gemspec").select do |s|
+ s.name == name
+ end
end
end
+ ##
+ # Finds stub specifications matching a pattern from the standard locations,
+ # optionally filtering out specs not matching the current platform
+ #
+ def self.stubs_for_pattern(pattern, match_platform = true) # :nodoc:
+ installed_stubs = installed_stubs(Gem::Specification.dirs, pattern)
+ installed_stubs.select! {|s| Gem::Platform.match_spec? s } if match_platform
+ stubs = installed_stubs + default_stubs(pattern)
+ stubs = stubs.uniq {|stub| stub.full_name }
+ _resort!(stubs)
+ stubs
+ end
+
def self._resort!(specs) # :nodoc:
specs.sort! do |a, b|
names = a.name <=> b.name
next names if names.nonzero?
- b.version <=> a.version
+ versions = b.version <=> a.version
+ next versions if versions.nonzero?
+ b.platform == Gem::Platform::RUBY ? -1 : 1
end
end
@@ -1080,20 +1091,15 @@ class Gem::Specification < Gem::BasicSpecification
end
def self._latest_specs(specs, prerelease = false) # :nodoc:
- result = Hash.new {|h,k| h[k] = {} }
- native = {}
+ result = {}
specs.reverse_each do |spec|
next if spec.version.prerelease? unless prerelease
- native[spec.name] = spec.version if spec.platform == Gem::Platform::RUBY
- result[spec.name][spec.platform] = spec
+ result[spec.name] = spec
end
- result.map(&:last).map(&:values).flatten.reject do |spec|
- minimum = native[spec.name]
- minimum && spec.version < minimum
- end.sort_by{|tup| tup.name }
+ result.map(&:last).flatten.sort_by{|tup| tup.name }
end
##
@@ -1552,7 +1558,6 @@ class Gem::Specification < Gem::BasicSpecification
def build_extensions # :nodoc:
return if default_gem?
return if extensions.empty?
- return if installed_by_version < Gem::Version.new('2.2.0.preview.2')
return if File.exist? gem_build_complete_path
return if !File.writable?(base_dir)
return if !File.exist?(File.join(base_dir, 'extensions'))
@@ -2123,7 +2128,6 @@ class Gem::Specification < Gem::BasicSpecification
def missing_extensions?
return false if default_gem?
return false if extensions.empty?
- return false if installed_by_version < Gem::Version.new('2.2.0.preview.2')
return false if File.exist? gem_build_complete_path
true
@@ -2548,7 +2552,7 @@ class Gem::Specification < Gem::BasicSpecification
begin
dependencies.each do |dep|
next unless dep.runtime?
- dep.to_specs.each do |dep_spec|
+ dep.matching_specs(true).each do |dep_spec|
next if visited.has_key?(dep_spec)
visited[dep_spec] = true
trail.push(dep_spec)