aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-07 00:53:01 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-07 00:53:01 +0000
commit97f80207d0f0d13f28a419d8c92e96bb9064096a (patch)
treede416fff9bbc978434cb4c1185099151df2ac27c /lib/rubygems
parenta0b80a44101708b5d66cdd87f16c98277954a77c (diff)
downloadruby-97f80207d0f0d13f28a419d8c92e96bb9064096a.tar.gz
* lib/rubygems: Update to RubyGems 2.4.5.
* test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems')
-rw-r--r--lib/rubygems/basic_specification.rb74
-rw-r--r--lib/rubygems/commands/pristine_command.rb16
-rw-r--r--lib/rubygems/commands/uninstall_command.rb2
-rw-r--r--lib/rubygems/core_ext/kernel_gem.rb9
-rwxr-xr-xlib/rubygems/core_ext/kernel_require.rb2
-rw-r--r--lib/rubygems/dependency_list.rb6
-rw-r--r--lib/rubygems/ext/ext_conf_builder.rb2
-rw-r--r--lib/rubygems/installer.rb4
-rw-r--r--lib/rubygems/package/tar_writer.rb12
-rw-r--r--lib/rubygems/request_set.rb5
-rw-r--r--lib/rubygems/request_set/lockfile.rb29
-rw-r--r--lib/rubygems/resolver/api_set.rb2
-rw-r--r--lib/rubygems/resolver/api_specification.rb2
-rw-r--r--lib/rubygems/resolver/installer_set.rb2
-rw-r--r--lib/rubygems/source.rb8
-rw-r--r--lib/rubygems/specification.rb12
-rw-r--r--lib/rubygems/stub_specification.rb16
-rw-r--r--lib/rubygems/test_case.rb31
-rw-r--r--lib/rubygems/text.rb4
19 files changed, 175 insertions, 63 deletions
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb
index f9eb193fb4..f5fb0f5d97 100644
--- a/lib/rubygems/basic_specification.rb
+++ b/lib/rubygems/basic_specification.rb
@@ -58,23 +58,28 @@ class Gem::BasicSpecification
# Return true if this spec can require +file+.
def contains_requirable_file? file
- if instance_variable_defined?(:@ignored) or
- instance_variable_defined?('@ignored') then
- return false
- elsif missing_extensions? then
- @ignored = true
-
- warn "Ignoring #{full_name} because its extensions are not built. " +
- "Try: gem pristine #{full_name}"
- return false
- end
-
- suffixes = Gem.suffixes
-
- full_require_paths.any? do |dir|
- base = "#{dir}/#{file}"
- suffixes.any? { |suf| File.file? "#{base}#{suf}" }
- end
+ @contains_requirable_file ||= {}
+ @contains_requirable_file[file] ||=
+ begin
+ if instance_variable_defined?(:@ignored) or
+ instance_variable_defined?('@ignored') then
+ return false
+ elsif missing_extensions? then
+ @ignored = true
+
+ warn "Ignoring #{full_name} because its extensions are not built. " +
+ "Try: gem pristine #{name} --version #{version}"
+ return false
+ end
+
+ suffixes = Gem.suffixes
+
+ full_require_paths.any? do |dir|
+ base = "#{dir}/#{file}"
+ suffixes.any? { |suf| File.file? "#{base}#{suf}" }
+ end
+ end ? :yes : :no
+ @contains_requirable_file[file] == :yes
end
def default_gem?
@@ -134,13 +139,38 @@ class Gem::BasicSpecification
# activated.
def full_require_paths
- full_paths = raw_require_paths.map do |path|
- File.join full_gem_path, path
- end
+ @full_require_paths ||=
+ begin
+ full_paths = raw_require_paths.map do |path|
+ File.join full_gem_path, path
+ end
- full_paths.unshift extension_dir unless @extensions.nil? || @extensions.empty?
+ full_paths.unshift extension_dir unless @extensions.nil? || @extensions.empty?
- full_paths
+ full_paths
+ end
+ end
+
+ ##
+ # Full path of the target library file.
+ # If the file is not in this gem, return nil.
+
+ def to_fullpath path
+ if activated? then
+ @paths_map ||= {}
+ @paths_map[path] ||=
+ begin
+ fullpath = nil
+ suffixes = Gem.suffixes
+ full_require_paths.find do |dir|
+ suffixes.find do |suf|
+ File.file?(fullpath = "#{dir}/#{path}#{suf}")
+ end
+ end ? fullpath : nil
+ end
+ else
+ nil
+ end
end
##
diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb
index b54e7eac93..dcd5bb76fb 100644
--- a/lib/rubygems/commands/pristine_command.rb
+++ b/lib/rubygems/commands/pristine_command.rb
@@ -109,6 +109,11 @@ extensions will be restored.
next
end
+ if spec.bundled_gem_in_old_ruby?
+ say "Skipped #{spec.full_name}, it is bundled with old Ruby"
+ next
+ end
+
unless spec.extensions.empty? or options[:extensions] then
say "Skipped #{spec.full_name}, it needs to compile an extension"
next
@@ -120,8 +125,17 @@ extensions will be restored.
require 'rubygems/remote_fetcher'
say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
+
dep = Gem::Dependency.new spec.name, spec.version
- Gem::RemoteFetcher.fetcher.download_to_cache dep
+ found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
+
+ if found.empty?
+ say "Skipped #{spec.full_name}, it was not found from cache and remote sources"
+ next
+ end
+
+ spec_candidate, source = found.first
+ Gem::RemoteFetcher.fetcher.download spec_candidate, source.uri.to_s, spec.base_dir
end
env_shebang =
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 71ffdc89fc..9285e57b77 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -124,7 +124,7 @@ that is a dependency of an existing gem. You can use the
end
def uninstall_all
- _, specs = Gem::Specification.partition { |spec| spec.default_gem? }
+ specs = Gem::Specification.reject { |spec| spec.default_gem? }
specs.each do |spec|
options[:version] = spec.version
diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb
index edce4ee10b..61e77fe3c5 100644
--- a/lib/rubygems/core_ext/kernel_gem.rb
+++ b/lib/rubygems/core_ext/kernel_gem.rb
@@ -55,7 +55,14 @@ module Kernel
gem_name = gem_name.name
end
- spec = Gem::Dependency.new(gem_name, *requirements).to_spec
+ dep = Gem::Dependency.new(gem_name, *requirements)
+
+ loaded = Gem.loaded_specs[gem_name]
+
+ return false if loaded && dep.matches_spec?(loaded)
+
+ spec = dep.to_spec
+
Gem::LOADED_SPECS_MUTEX.synchronize {
spec.activate
} if spec
diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb
index bf9618d3bf..8f2cddee4d 100755
--- a/lib/rubygems/core_ext/kernel_require.rb
+++ b/lib/rubygems/core_ext/kernel_require.rb
@@ -66,7 +66,7 @@ module Kernel
begin
RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
+ return gem_original_require(spec.to_fullpath(path) || path)
end if spec
# Attempt to find +path+ in any unresolved gems...
diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb
index 3e40325527..ad7a82a86e 100644
--- a/lib/rubygems/dependency_list.rb
+++ b/lib/rubygems/dependency_list.rb
@@ -219,11 +219,7 @@ class Gem::DependencyList
dependencies.each do |dep|
specs.each do |spec|
if spec.satisfies_requirement? dep then
- begin
- yield spec
- rescue TSort::Cyclic
- # do nothing
- end
+ yield spec
break
end
end
diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb
index 213bdcb002..d11d1ac328 100644
--- a/lib/rubygems/ext/ext_conf_builder.rb
+++ b/lib/rubygems/ext/ext_conf_builder.rb
@@ -49,7 +49,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
FileUtils.mkdir_p lib_dir
entries = Dir.entries(tmp_dest) - %w[. ..]
entries = entries.map { |entry| File.join tmp_dest, entry }
- FileUtils.cp_r entries, lib_dir
+ FileUtils.cp_r entries, lib_dir, :remove_destination => true
end
FileEntry.new(tmp_dest).traverse do |ent|
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index d497ba5c05..877cb21b7c 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -421,8 +421,8 @@ class Gem::Installer
next
end
- mode = File.stat(bin_path).mode | 0111
- FileUtils.chmod mode, bin_path
+ mode = File.stat(bin_path).mode
+ FileUtils.chmod mode | 0111, bin_path unless (mode | 0111) == mode
check_executable_overwrite filename
diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb
index e1b38ad6b5..51a67ea51c 100644
--- a/lib/rubygems/package/tar_writer.rb
+++ b/lib/rubygems/package/tar_writer.rb
@@ -290,7 +290,9 @@ class Gem::Package::TarWriter
# Splits +name+ into a name and prefix that can fit in the TarHeader
def split_name(name) # :nodoc:
- raise Gem::Package::TooLongFileName if name.bytesize > 256
+ if name.bytesize > 256
+ raise Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)")
+ end
if name.bytesize <= 100 then
prefix = ""
@@ -308,8 +310,12 @@ class Gem::Package::TarWriter
prefix = (parts + [nxt]).join "/"
name = newname
- if name.bytesize > 100 or prefix.bytesize > 155 then
- raise Gem::Package::TooLongFileName
+ if name.bytesize > 100
+ raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long name (should be 100 or less)")
+ end
+
+ if prefix.bytesize > 155 then
+ raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long base path (should be 155 or less)")
end
end
diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb
index 57f9c39ba9..05bfcbee2c 100644
--- a/lib/rubygems/request_set.rb
+++ b/lib/rubygems/request_set.rb
@@ -403,10 +403,7 @@ class Gem::RequestSet
"Unresolved dependency found during sorting - #{dep} (requested by #{node.spec.full_name})"
end
- begin
- yield match
- rescue TSort::Cyclic
- end
+ yield match
end
end
diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb
index 918aa971e5..4f2fa0933f 100644
--- a/lib/rubygems/request_set/lockfile.rb
+++ b/lib/rubygems/request_set/lockfile.rb
@@ -200,6 +200,8 @@ class Gem::RequestSet::Lockfile
platforms = @requests.map { |request| request.spec.platform }.uniq
+ platforms = platforms.sort_by { |platform| platform.to_s }
+
platforms.sort.each do |platform|
out << " #{platform}"
end
@@ -277,14 +279,7 @@ class Gem::RequestSet::Lockfile
when :bang then
get :bang
- spec = @set.sets.select { |set|
- Gem::Resolver::GitSet === set or
- Gem::Resolver::VendorSet === set
- }.map { |set|
- set.specs[name]
- }.compact.first
-
- requirements << spec.version
+ requirements << pinned_requirement(name)
when :l_paren then
get :l_paren
@@ -300,6 +295,13 @@ class Gem::RequestSet::Lockfile
end
get :r_paren
+
+ if peek[0] == :bang then
+ requirements.clear
+ requirements << pinned_requirement(name)
+
+ get :bang
+ end
end
@set.gem name, *requirements
@@ -507,6 +509,17 @@ class Gem::RequestSet::Lockfile
@tokens.first || [:EOF]
end
+ def pinned_requirement name # :nodoc:
+ spec = @set.sets.select { |set|
+ Gem::Resolver::GitSet === set or
+ Gem::Resolver::VendorSet === set
+ }.map { |set|
+ set.specs[name]
+ }.compact.first
+
+ spec.version
+ end
+
def skip type # :nodoc:
get while not @tokens.empty? and peek.first == type
end
diff --git a/lib/rubygems/resolver/api_set.rb b/lib/rubygems/resolver/api_set.rb
index dda3579878..17d602f987 100644
--- a/lib/rubygems/resolver/api_set.rb
+++ b/lib/rubygems/resolver/api_set.rb
@@ -72,7 +72,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set
@to_fetch += needed
end
- def prefetch_now
+ def prefetch_now # :nodoc:
needed, @to_fetch = @to_fetch, []
uri = @dep_uri + "?gems=#{needed.sort.join ','}"
diff --git a/lib/rubygems/resolver/api_specification.rb b/lib/rubygems/resolver/api_specification.rb
index bbd5a6427b..4960e66934 100644
--- a/lib/rubygems/resolver/api_specification.rb
+++ b/lib/rubygems/resolver/api_specification.rb
@@ -19,7 +19,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification
@set = set
@name = api_data[:name]
@version = Gem::Version.new api_data[:number]
- @platform = api_data[:platform]
+ @platform = Gem::Platform.new api_data[:platform]
@dependencies = api_data[:dependencies].map do |name, ver|
Gem::Dependency.new name, ver.split(/\s*,\s*/)
end
diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb
index f53b496dc7..a68ff09dbd 100644
--- a/lib/rubygems/resolver/installer_set.rb
+++ b/lib/rubygems/resolver/installer_set.rb
@@ -154,7 +154,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
end
def prefetch(reqs)
- @remote_set.prefetch(reqs)
+ @remote_set.prefetch(reqs) if consider_remote?
end
def prerelease= allow_prerelease
diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb
index 4858ffb5ba..e5995f005f 100644
--- a/lib/rubygems/source.rb
+++ b/lib/rubygems/source.rb
@@ -26,8 +26,12 @@ class Gem::Source
# Creates a new Source which will use the index located at +uri+.
def initialize(uri)
- unless uri.kind_of? URI
- uri = URI.parse(uri.to_s)
+ begin
+ unless uri.kind_of? URI
+ uri = URI.parse(uri.to_s)
+ end
+ rescue URI::InvalidURIError
+ raise if Gem::Source == self.class
end
@uri = uri
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 87a9b603d1..8ccaa962b8 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -709,8 +709,6 @@ class Gem::Specification < Gem::BasicSpecification
specs = {}
Gem.loaded_specs.each_value{|s| specs[s] = true}
@@all.each{|s| s.activated = true if specs[s]}
-
- _resort!(@@all)
end
@@all
end
@@ -1479,6 +1477,16 @@ class Gem::Specification < Gem::BasicSpecification
end
##
+ # Used to detect if the gem is bundled in older version of Ruby, but not
+ # detectable as default gem (see BasicSpecification#default_gem?).
+
+ def bundled_gem_in_old_ruby?
+ !default_gem? &&
+ RUBY_VERSION < "2.0.0" &&
+ summary == "This #{name} is bundled with Ruby"
+ end
+
+ ##
# Returns the full path to the cache directory containing this
# spec's cached gem.
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb
index 49a6df43a3..b184d29d5e 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -42,6 +42,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
self.loaded_from = filename
@data = nil
@extensions = nil
+ @name = nil
@spec = nil
end
@@ -49,8 +50,11 @@ class Gem::StubSpecification < Gem::BasicSpecification
# True when this gem has been activated
def activated?
- loaded = Gem.loaded_specs[name]
- loaded && loaded.version == version
+ @activated ||=
+ begin
+ loaded = Gem.loaded_specs[name]
+ loaded && loaded.version == version
+ end
end
def build_extensions # :nodoc:
@@ -154,9 +158,11 @@ class Gem::StubSpecification < Gem::BasicSpecification
# The full Gem::Specification for this gem, loaded from evalling its gemspec
def to_spec
- @spec ||= Gem.loaded_specs.values.find { |spec|
- spec.name == @name and spec.version == @version
- }
+ @spec ||= if @data then
+ Gem.loaded_specs.values.find { |spec|
+ spec.name == name and spec.version == version
+ }
+ end
@spec ||= Gem::Specification.load(loaded_from)
@spec.ignored = @ignored if instance_variable_defined? :@ignored
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index e9916dad61..5dc7a1b67c 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -1035,6 +1035,37 @@ Also, a list:
Zlib::Deflate.deflate data
end
+ def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
+ if Gem.instance_variables.include? :@ruby_version or
+ Gem.instance_variables.include? '@ruby_version' then
+ Gem.send :remove_instance_variable, :@ruby_version
+ end
+
+ @RUBY_VERSION = RUBY_VERSION
+ @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.send :remove_const, :RUBY_VERSION
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.const_set :RUBY_VERSION, version
+ Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
+ Object.const_set :RUBY_REVISION, revision if revision
+ end
+
+ def util_restore_RUBY_VERSION
+ Object.send :remove_const, :RUBY_VERSION
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.const_set :RUBY_VERSION, @RUBY_VERSION
+ Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
+ defined?(@RUBY_PATCHLEVEL)
+ Object.const_set :RUBY_REVISION, @RUBY_REVISION if
+ defined?(@RUBY_REVISION)
+ end
+
##
# Is this test being run on a Windows platform?
diff --git a/lib/rubygems/text.rb b/lib/rubygems/text.rb
index 8b26bebec8..5c9287ad2e 100644
--- a/lib/rubygems/text.rb
+++ b/lib/rubygems/text.rb
@@ -27,9 +27,9 @@ module Gem::Text
end
def min3 a, b, c # :nodoc:
- if a < b && a < c
+ if a < b && a < c then
a
- elsif b < a && b < c
+ elsif b < c then
b
else
c