formula: add a time method for use as the build time
A number of formulae use a variant of `Time.now` to generate the build time of the formula. Let's define a method to make sure that: 1. it uses `SOURCE_DATE_EPOCH` whenever available; and, 2. it uses `utc`. Both should help with build reproducibility. See Homebrew/homebrew-core#80608.
This commit is contained in:
parent
c20826a872
commit
3776ba9756
@ -1551,6 +1551,18 @@ class Formula
|
||||
"@loader_path/../lib"
|
||||
end
|
||||
|
||||
# Creates a new `Time` object for use in the formula as the build time.
|
||||
#
|
||||
# @see https://www.rubydoc.info/stdlib/time/Time Time
|
||||
sig { returns(Time) }
|
||||
def time
|
||||
if ENV["SOURCE_DATE_EPOCH"].present?
|
||||
Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc
|
||||
else
|
||||
Time.now.utc
|
||||
end
|
||||
end
|
||||
|
||||
# an array of all core {Formula} names
|
||||
# @private
|
||||
def self.core_names
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user