summaryrefslogtreecommitdiff
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
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.