summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-06-30 21:23:37 +0900
committernagachika <nagachika@ruby-lang.org>2020-09-15 20:55:40 +0900
commit7d76314885be3532999684356657ce36da84d04e (patch)
treeaae23ff9ce30ff03c1f0867c0bc46ea968e8e324 /lib
parent3590f082442afc4506250f5274a7877371a112de (diff)
Merge RubyGems 3.1.4
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems.rb93
-rw-r--r--lib/rubygems/basic_specification.rb2
-rw-r--r--lib/rubygems/command.rb2
-rw-r--r--lib/rubygems/commands/help_command.rb2
-rw-r--r--lib/rubygems/commands/sources_command.rb6
-rw-r--r--lib/rubygems/commands/uninstall_command.rb2
-rw-r--r--lib/rubygems/ext/builder.rb4
-rw-r--r--lib/rubygems/request_set/gem_dependency_api.rb2
-rw-r--r--lib/rubygems/resolver/api_set.rb2
-rw-r--r--lib/rubygems/resolver/api_specification.rb2
-rw-r--r--lib/rubygems/server.rb2
-rw-r--r--lib/rubygems/specification.rb20
-rw-r--r--lib/rubygems/specification_policy.rb10
-rw-r--r--lib/rubygems/test_case.rb40
-rw-r--r--lib/rubygems/util.rb8
-rw-r--r--lib/rubygems/version.rb2
16 files changed, 131 insertions, 68 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 57cb70cc2b..94242a1310 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -9,7 +9,7 @@
require 'rbconfig'
module Gem
- VERSION = "3.1.2".freeze
+ VERSION = "3.1.4".freeze
end
# Must be first since it unloads the prelude from 1.9.2
@@ -26,19 +26,19 @@ require 'rubygems/errors'
# For user documentation, see:
#
# * <tt>gem help</tt> and <tt>gem help [command]</tt>
-# * {RubyGems User Guide}[http://guides.rubygems.org/]
-# * {Frequently Asked Questions}[http://guides.rubygems.org/faqs]
+# * {RubyGems User Guide}[https://guides.rubygems.org/]
+# * {Frequently Asked Questions}[https://guides.rubygems.org/faqs]
#
# For gem developer documentation see:
#
-# * {Creating Gems}[http://guides.rubygems.org/make-your-own-gem]
+# * {Creating Gems}[https://guides.rubygems.org/make-your-own-gem]
# * Gem::Specification
# * Gem::Version for version dependency notes
#
# Further RubyGems documentation can be found at:
#
-# * {RubyGems Guides}[http://guides.rubygems.org]
-# * {RubyGems API}[http://www.rubydoc.info/github/rubygems/rubygems] (also available from
+# * {RubyGems Guides}[https://guides.rubygems.org]
+# * {RubyGems API}[https://www.rubydoc.info/github/rubygems/rubygems] (also available from
# <tt>gem server</tt>)
#
# == RubyGems Plugins
@@ -189,6 +189,8 @@ module Gem
@pre_reset_hooks ||= []
@post_reset_hooks ||= []
+ @default_source_date_epoch = nil
+
##
# Try to activate a gem containing +path+. Returns true if
# activation succeeded or wasn't needed because it was already
@@ -1236,20 +1238,43 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
end
##
- # The SOURCE_DATE_EPOCH environment variable (or, if that's not set, the current time), converted to Time object.
- # This is used throughout RubyGems for enabling reproducible builds.
+ # If the SOURCE_DATE_EPOCH environment variable is set, returns it's value.
+ # Otherwise, returns the time that `Gem.source_date_epoch_string` was
+ # first called in the same format as SOURCE_DATE_EPOCH.
#
- # If it is not set as an environment variable already, this also sets it.
+ # NOTE(@duckinator): The implementation is a tad weird because we want to:
+ # 1. Make builds reproducible by default, by having this function always
+ # return the same result during a given run.
+ # 2. Allow changing ENV['SOURCE_DATE_EPOCH'] at runtime, since multiple
+ # tests that set this variable will be run in a single process.
+ #
+ # If you simplify this function and a lot of tests fail, that is likely
+ # due to #2 above.
#
# Details on SOURCE_DATE_EPOCH:
# https://reproducible-builds.org/specs/source-date-epoch/
- def self.source_date_epoch
- if ENV["SOURCE_DATE_EPOCH"].nil? || ENV["SOURCE_DATE_EPOCH"].empty?
- ENV["SOURCE_DATE_EPOCH"] = Time.now.to_i.to_s
- end
+ def self.source_date_epoch_string
+ # The value used if $SOURCE_DATE_EPOCH is not set.
+ @default_source_date_epoch ||= Time.now.to_i.to_s
+
+ specified_epoch = ENV["SOURCE_DATE_EPOCH"]
+
+ # If it's empty or just whitespace, treat it like it wasn't set at all.
+ specified_epoch = nil if !specified_epoch.nil? && specified_epoch.strip.empty?
+
+ epoch = specified_epoch || @default_source_date_epoch
- Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc.freeze
+ epoch.strip
+ end
+
+ ##
+ # Returns the value of Gem.source_date_epoch_string, as a Time object.
+ #
+ # This is used throughout RubyGems for enabling reproducible builds.
+
+ def self.source_date_epoch
+ Time.at(self.source_date_epoch_string.to_i).utc.freeze
end
# FIX: Almost everywhere else we use the `def self.` way of defining class
@@ -1281,10 +1306,11 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
#
def register_default_spec(spec)
- new_format = spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
+ extended_require_paths = spec.require_paths.map {|f| f + "/"}
+ new_format = extended_require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
if new_format
- prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
+ prefix_group = extended_require_paths.join("|")
prefix_pattern = /^(#{prefix_group})/
end
@@ -1366,23 +1392,24 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/".freeze
- autoload :BundlerVersionFinder, 'rubygems/bundler_version_finder'
- autoload :ConfigFile, 'rubygems/config_file'
- autoload :Dependency, 'rubygems/dependency'
- autoload :DependencyList, 'rubygems/dependency_list'
- autoload :Installer, 'rubygems/installer'
- autoload :Licenses, 'rubygems/util/licenses'
- autoload :PathSupport, 'rubygems/path_support'
- autoload :Platform, 'rubygems/platform'
- autoload :RequestSet, 'rubygems/request_set'
- autoload :Requirement, 'rubygems/requirement'
- autoload :Resolver, 'rubygems/resolver'
- autoload :Source, 'rubygems/source'
- autoload :SourceList, 'rubygems/source_list'
- autoload :SpecFetcher, 'rubygems/spec_fetcher'
- autoload :Specification, 'rubygems/specification'
- autoload :Util, 'rubygems/util'
- autoload :Version, 'rubygems/version'
+ autoload :BundlerVersionFinder, File.expand_path('rubygems/bundler_version_finder', __dir__)
+ autoload :ConfigFile, File.expand_path('rubygems/config_file', __dir__)
+ autoload :Dependency, File.expand_path('rubygems/dependency', __dir__)
+ autoload :DependencyList, File.expand_path('rubygems/dependency_list', __dir__)
+ autoload :Installer, File.expand_path('rubygems/installer', __dir__)
+ autoload :Licenses, File.expand_path('rubygems/util/licenses', __dir__)
+ autoload :NameTuple, File.expand_path('rubygems/name_tuple', __dir__)
+ autoload :PathSupport, File.expand_path('rubygems/path_support', __dir__)
+ autoload :Platform, File.expand_path('rubygems/platform', __dir__)
+ autoload :RequestSet, File.expand_path('rubygems/request_set', __dir__)
+ autoload :Requirement, File.expand_path('rubygems/requirement', __dir__)
+ autoload :Resolver, File.expand_path('rubygems/resolver', __dir__)
+ autoload :Source, File.expand_path('rubygems/source', __dir__)
+ autoload :SourceList, File.expand_path('rubygems/source_list', __dir__)
+ autoload :SpecFetcher, File.expand_path('rubygems/spec_fetcher', __dir__)
+ autoload :Specification, File.expand_path('rubygems/specification', __dir__)
+ autoload :Util, File.expand_path('rubygems/util', __dir__)
+ autoload :Version, File.expand_path('rubygems/version', __dir__)
require "rubygems/specification"
end
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb
index c6d63ac473..339953eb29 100644
--- a/lib/rubygems/basic_specification.rb
+++ b/lib/rubygems/basic_specification.rb
@@ -78,7 +78,7 @@ class Gem::BasicSpecification
elsif missing_extensions?
@ignored = true
- if RUBY_ENGINE == platform || Gem::Platform.local === platform
+ if Gem::Platform::RUBY == platform || Gem::Platform.local === platform
warn "Ignoring #{full_name} because its extensions are not built. " +
"Try: gem pristine #{name} --version #{version}"
end
diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index c1e5e13c5a..32ec0f8ba6 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -646,7 +646,7 @@ basic help message containing pointers to more information.
http://localhost:8808/
with info about installed gems
Further information:
- http://guides.rubygems.org
+ https://guides.rubygems.org
HELP
# :startdoc:
diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb
index 9f14e22f90..259e8b5622 100644
--- a/lib/rubygems/commands/help_command.rb
+++ b/lib/rubygems/commands/help_command.rb
@@ -38,7 +38,7 @@ Some examples of 'gem' usage.
* Create a gem:
- See http://guides.rubygems.org/make-your-own-gem/
+ See https://guides.rubygems.org/make-your-own-gem/
* See information about RubyGems:
diff --git a/lib/rubygems/commands/sources_command.rb b/lib/rubygems/commands/sources_command.rb
index feab23237d..ca9d425232 100644
--- a/lib/rubygems/commands/sources_command.rb
+++ b/lib/rubygems/commands/sources_command.rb
@@ -136,7 +136,7 @@ RubyGems has been configured to serve gems via the following URLs through
its history:
* http://gems.rubyforge.org (RubyGems 1.3.6 and earlier)
-* http://rubygems.org (RubyGems 1.3.7 through 1.8.25)
+* https://rubygems.org/ (RubyGems 1.3.7 through 1.8.25)
* https://rubygems.org (RubyGems 2.0.1 and newer)
Since all of these sources point to the same set of gems you only need one
@@ -153,8 +153,8 @@ before it is added.
To remove a source use the --remove argument:
- $ gem sources --remove http://rubygems.org
- http://rubygems.org removed from sources
+ $ gem sources --remove https://rubygems.org/
+ https://rubygems.org/ removed from sources
EOF
end
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 68e048c010..c1a9dbba32 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -143,7 +143,7 @@ that is a dependency of an existing gem. You can use the
uninstall_gem spec.name
end
- alert "Uninstalled all gems in #{options[:install_dir]}"
+ alert "Uninstalled all gems in #{options[:install_dir] || Gem.dir}"
end
def uninstall_specific
diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb
index 2fc1074d92..a8bd4c8d1b 100644
--- a/lib/rubygems/ext/builder.rb
+++ b/lib/rubygems/ext/builder.rb
@@ -68,7 +68,9 @@ class Gem::Ext::Builder
results << (command.respond_to?(:shelljoin) ? command.shelljoin : command)
require "open3"
- output, status = Open3.capture2e(*command)
+ # Set $SOURCE_DATE_EPOCH for the subprocess.
+ env = {'SOURCE_DATE_EPOCH' => Gem.source_date_epoch_string}
+ output, status = Open3.capture2e(env, *command)
if verbose
puts output
else
diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb
index b7a8ee6f4f..ef3f302ea8 100644
--- a/lib/rubygems/request_set/gem_dependency_api.rb
+++ b/lib/rubygems/request_set/gem_dependency_api.rb
@@ -235,7 +235,7 @@ class Gem::RequestSet::GemDependencyAPI
return unless (groups & @without_groups).empty?
dependencies.each do |dep|
- @set.gem dep.name, *dep.requirement
+ @set.gem dep.name, *dep.requirement.as_list
end
end
diff --git a/lib/rubygems/resolver/api_set.rb b/lib/rubygems/resolver/api_set.rb
index 6fd91e3b73..135f1b08aa 100644
--- a/lib/rubygems/resolver/api_set.rb
+++ b/lib/rubygems/resolver/api_set.rb
@@ -23,7 +23,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set
##
# Creates a new APISet that will retrieve gems from +uri+ using the RubyGems
# API URL +dep_uri+ which is described at
- # http://guides.rubygems.org/rubygems-org-api
+ # https://guides.rubygems.org/rubygems-org-api
def initialize(dep_uri = 'https://rubygems.org/api/v1/dependencies')
super()
diff --git a/lib/rubygems/resolver/api_specification.rb b/lib/rubygems/resolver/api_specification.rb
index 9bbc095788..4052846e99 100644
--- a/lib/rubygems/resolver/api_specification.rb
+++ b/lib/rubygems/resolver/api_specification.rb
@@ -11,7 +11,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification
# Creates an APISpecification for the given +set+ from the rubygems.org
# +api_data+.
#
- # See http://guides.rubygems.org/rubygems-org-api/#misc_methods for the
+ # See https://guides.rubygems.org/rubygems-org-api/#misc_methods for the
# format of the +api_data+.
def initialize(set, api_data)
diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb
index 97923ef698..83d7cf5abc 100644
--- a/lib/rubygems/server.rb
+++ b/lib/rubygems/server.rb
@@ -661,7 +661,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
"only_one_executable" => true,
"full_name" => "rubygems-#{Gem::VERSION}",
"has_deps" => false,
- "homepage" => "http://guides.rubygems.org/",
+ "homepage" => "https://guides.rubygems.org/",
"name" => 'rubygems',
"ri_installed" => true,
"summary" => "RubyGems itself",
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 5321edfcc3..f925480f88 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -193,6 +193,12 @@ class Gem::Specification < Gem::BasicSpecification
@@spec_with_requirable_file = {}
@@active_stub_with_requirable_file = {}
+ # Tracking removed method calls to warn users during build time.
+ REMOVED_METHODS = [:rubyforge_project=].freeze # :nodoc:
+ def removed_method_calls
+ @removed_method_calls ||= []
+ end
+
######################################################################
# :section: Required gemspec attributes
@@ -727,14 +733,6 @@ class Gem::Specification < Gem::BasicSpecification
attr_writer :original_platform # :nodoc:
##
- # Deprecated and ignored.
- #
- # Formerly used to set rubyforge project.
-
- attr_writer :rubyforge_project
- deprecate :rubyforge_project=, :none, 2019, 12
-
- ##
# The Gem::Specification version of this gemspec.
#
# Do not set this, it is set automatically when the gem is packaged.
@@ -2107,9 +2105,15 @@ class Gem::Specification < Gem::BasicSpecification
end
##
+ # Track removed method calls to warn about during build time.
# Warn about unknown attributes while loading a spec.
def method_missing(sym, *a, &b) # :nodoc:
+ if REMOVED_METHODS.include?(sym)
+ removed_method_calls << sym
+ return
+ end
+
if @specification_version > CURRENT_SPECIFICATION_VERSION and
sym.to_s =~ /=$/
warn "ignoring #{sym} loading #{full_name}" if $DEBUG
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index c3c496db9b..b7fb2cfa1a 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -75,6 +75,8 @@ class Gem::SpecificationPolicy
validate_dependencies
+ validate_removed_attributes
+
if @warnings > 0
if strict
error "specification has warnings"
@@ -408,6 +410,12 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li
warning "#{executable_path} is missing #! line"
end
+ def validate_removed_attributes # :nodoc:
+ @specification.removed_method_calls.each do |attr|
+ warning("#{attr} is deprecated and ignored. Please remove this from your gemspec to ensure that your gem continues to build in the future.")
+ end
+ end
+
def warning(statement) # :nodoc:
@warnings += 1
@@ -421,7 +429,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li
end
def help_text # :nodoc:
- "See http://guides.rubygems.org/specification-reference/ for help"
+ "See https://guides.rubygems.org/specification-reference/ for help"
end
end
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index 206497c651..89403206f9 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -96,6 +96,8 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
TEST_PATH = ENV.fetch('RUBYGEMS_TEST_PATH', File.expand_path('../../../test/rubygems', __FILE__))
+ SPECIFICATIONS = File.expand_path(File.join(TEST_PATH, "specifications"), __FILE__)
+
def assert_activate(expected, *specs)
specs.each do |spec|
case spec
@@ -169,20 +171,24 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
# original value when the block ends
#
def bindir(value)
- bindir = RbConfig::CONFIG['bindir']
+ with_clean_path_to_ruby do
+ bindir = RbConfig::CONFIG['bindir']
- if value
- RbConfig::CONFIG['bindir'] = value
- else
- RbConfig::CONFIG.delete 'bindir'
- end
+ if value
+ RbConfig::CONFIG['bindir'] = value
+ else
+ RbConfig::CONFIG.delete 'bindir'
+ end
- yield
- ensure
- if bindir
- RbConfig::CONFIG['bindir'] = bindir
- else
- RbConfig::CONFIG.delete 'bindir'
+ begin
+ yield
+ ensure
+ if bindir
+ RbConfig::CONFIG['bindir'] = bindir
+ else
+ RbConfig::CONFIG.delete 'bindir'
+ end
+ end
end
end
@@ -1247,6 +1253,16 @@ Also, a list:
end
end
+ def with_clean_path_to_ruby
+ orig_ruby = Gem.ruby
+
+ Gem.instance_variable_set :@ruby, nil
+
+ yield
+ ensure
+ Gem.instance_variable_set :@ruby, orig_ruby
+ end
+
class << self
# :nodoc:
diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb
index b5f1408401..7fc239af9a 100644
--- a/lib/rubygems/util.rb
+++ b/lib/rubygems/util.rb
@@ -14,7 +14,13 @@ module Gem::Util
require 'stringio'
data = StringIO.new(data, 'r')
- unzipped = Zlib::GzipReader.new(data).read
+ gzip_reader = begin
+ Zlib::GzipReader.new(data)
+ rescue Zlib::GzipFile::Error => e
+ raise e.class, e.inspect, e.backtrace
+ end
+
+ unzipped = gzip_reader.read
unzipped.force_encoding Encoding::BINARY
unzipped
end
diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb
index 6524faf5c8..b1faedcda2 100644
--- a/lib/rubygems/version.rb
+++ b/lib/rubygems/version.rb
@@ -151,7 +151,7 @@
class Gem::Version
- autoload :Requirement, 'rubygems/requirement'
+ autoload :Requirement, File.expand_path('requirement', __dir__)
include Comparable