Respect SOURCE_DATE_EPOCH for time stamp
For reproducible builds, check the presence of SOURCE_DATE_EPOCH environment variable and use it for the time stamp. This affects the head.modified (and head.created in merge.py). See https://reproducible-builds.org/specs/source-date-epoch/
This commit is contained in:
parent
7f352b028b
commit
4b3a2eb1d9
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import print_function, division, absolute_import
|
from __future__ import print_function, division, absolute_import
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
@ -47,6 +48,10 @@ def timestampFromString(value):
|
|||||||
return calendar.timegm(time.strptime(value)) - epoch_diff
|
return calendar.timegm(time.strptime(value)) - epoch_diff
|
||||||
|
|
||||||
def timestampNow():
|
def timestampNow():
|
||||||
|
# https://reproducible-builds.org/specs/source-date-epoch/
|
||||||
|
source_date_epoch = os.environ.get("SOURCE_DATE_EPOCH")
|
||||||
|
if source_date_epoch is not None:
|
||||||
|
return int(source_date_epoch) - epoch_diff
|
||||||
return int(time.time() - epoch_diff)
|
return int(time.time() - epoch_diff)
|
||||||
|
|
||||||
def timestampSinceEpoch(value):
|
def timestampSinceEpoch(value):
|
||||||
|
@ -1,9 +1,25 @@
|
|||||||
from __future__ import print_function, division, absolute_import
|
from __future__ import print_function, division, absolute_import
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
from fontTools.misc.timeTools import asctime
|
from fontTools.misc.timeTools import asctime, timestampNow, epoch_diff
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def test_asctime():
|
def test_asctime():
|
||||||
assert isinstance(asctime(), basestring)
|
assert isinstance(asctime(), basestring)
|
||||||
assert asctime(time.gmtime(0)) == 'Thu Jan 1 00:00:00 1970'
|
assert asctime(time.gmtime(0)) == 'Thu Jan 1 00:00:00 1970'
|
||||||
|
|
||||||
|
def test_source_date_epoch():
|
||||||
|
os.environ["SOURCE_DATE_EPOCH"] = "150687315"
|
||||||
|
assert timestampNow() + epoch_diff == 150687315
|
||||||
|
|
||||||
|
# Check that malformed value fail, any better way?
|
||||||
|
os.environ["SOURCE_DATE_EPOCH"] = "ABCDEFGHI"
|
||||||
|
try:
|
||||||
|
timestampNow()
|
||||||
|
assert False
|
||||||
|
except ValueError:
|
||||||
|
assert True
|
||||||
|
|
||||||
|
del os.environ["SOURCE_DATE_EPOCH"]
|
||||||
|
assert timestampNow() + epoch_diff != 150687315
|
||||||
|
Loading…
x
Reference in New Issue
Block a user