diff options
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r-- | lib/rubygems.rb | 93 |
1 files changed, 60 insertions, 33 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 |