aboutsummaryrefslogtreecommitdiff
path: root/py/makeversionhdr.py
diff options
context:
space:
mode:
authoriTitou <moiandme@gmail.com>2021-01-20 10:33:40 +0100
committeriTitou <moiandme@gmail.com>2021-01-31 17:48:59 +0100
commit4fb5f012c32a2ed394091039a7213472001a98c9 (patch)
tree55c2f5ea860ecb1b5628465aad9e01c9af5a989a /py/makeversionhdr.py
parentef9fde7339b12e17596966afb2b3d641ca5fcff2 (diff)
py/makeversionhdr: Honor SOURCE_DATE_EPOCH if present.
This environment variable, if defined during the build process, indicates a fixed time that should be used in place of "now" when such a time is explicitely referenced. This allows for reproducible builds of micropython. See https://reproducible-builds.org/specs/source-date-epoch/ Signed-off-by: iTitou <moiandme@gmail.com>
Diffstat (limited to 'py/makeversionhdr.py')
-rw-r--r--py/makeversionhdr.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py
index 970a86e6c..2f4bc9182 100644
--- a/py/makeversionhdr.py
+++ b/py/makeversionhdr.py
@@ -80,6 +80,12 @@ def make_version_header(filename):
git_tag, git_hash = info
+ build_date = datetime.date.today()
+ if "SOURCE_DATE_EPOCH" in os.environ:
+ build_date = datetime.datetime.utcfromtimestamp(
+ int(os.environ["SOURCE_DATE_EPOCH"])
+ ).date()
+
# Generate the file with the git and version info
file_data = """\
// This file was generated by py/makeversionhdr.py
@@ -89,7 +95,7 @@ def make_version_header(filename):
""" % (
git_tag,
git_hash,
- datetime.date.today().strftime("%Y-%m-%d"),
+ build_date.strftime("%Y-%m-%d"),
)
# Check if the file contents changed from last time