summaryrefslogtreecommitdiff
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
authorEllen Marie Dash <the@smallest.dog>2019-08-17 04:45:09 +0000
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-09-26 17:48:00 +0900
commit508afe2c26737e0be60a72faa9d6740a06b0914c (patch)
treeb912da8888b6d1b476b8fdc67562cbf9b3b9cdef /lib/rubygems.rb
parent8436b2717c458a554dd81456a8e6e030e2c3e038 (diff)
[rubygems/rubygems] Set SOURCE_DATE_EPOCH env var if not provided.
Fixes #2290. 1. `Gem::Specification.date` returns SOURCE_DATE_EPOCH when defined, 2. this commit makes RubyGems set it _persistently_ when not provided. This combination means that you can build a gem, check the build time, and use that value to generate a new build -- and then verify they're the same. https://github.com/rubygems/rubygems/commit/d830d53f59
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r--lib/rubygems.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 4d06d98..2676fbd 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -1242,6 +1242,23 @@ 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 it is not set as an environment variable already, this also sets it.
+ #
+ # 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
+
+ Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc.freeze
+ end
+
# FIX: Almost everywhere else we use the `def self.` way of defining class
# methods, and then we switch over to `class << self` here. Pick one or the
# other.