Browse Source

python,python3: honour the SOURCE_DATE_EPOCH for the build-info

The Modules/getbuildinfo.c allows the use of DATE and TIME
macros to be defined via CFLAGS.

These vars, control the build date & time when the
interpreter is opened, and can be read via the
`platform._sys_version()` function.

So, a conversion from SOURCE_DATE_EPOCH to DATE & TIME
is required at build-time.

This is especially needed for `platform._sys_version()`
to work.
The installation of pip seems to rely on this.

The logic has been adapted from:
 https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal#Makefile

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
lilik-openwrt-22.03
Alexandru Ardelean 7 years ago
parent
commit
c54b312043
4 changed files with 58 additions and 2 deletions
  1. +1
    -1
      lang/python/python/Makefile
  2. +28
    -0
      lang/python/python/patches/013-getbuildinfo-date-time-source-date-epoch.patch
  3. +1
    -1
      lang/python/python3/Makefile
  4. +28
    -0
      lang/python/python3/patches/013-getbuildinfo-date-time-source-date-epoch.patch

+ 1
- 1
lang/python/python/Makefile View File

@ -12,7 +12,7 @@ include ./files/python-version.mk
PKG_NAME:=python
PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
PKG_RELEASE:=8
PKG_RELEASE:=9
PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)


+ 28
- 0
lang/python/python/patches/013-getbuildinfo-date-time-source-date-epoch.patch View File

@ -0,0 +1,28 @@
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -625,6 +625,16 @@ regen-all: regen-opcode-targets regen-gr
############################################################################
# Special rules for object files
+DATE_FMT = %b %d %Y
+TIME_FMT = %H:%M:%S
+ifdef SOURCE_DATE_EPOCH
+ BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")
+ BUILD_TIME ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(TIME_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(TIME_FMT)" 2>/dev/null || date -u "+$(TIME_FMT)")
+else
+ BUILD_DATE ?= $(shell date "+$(DATE_FMT)")
+ BUILD_TIME ?= $(shell date "+$(TIME_FMT)")
+endif
+
Modules/getbuildinfo.o: $(PARSER_OBJS) \
$(OBJECT_OBJS) \
$(PYTHON_OBJS) \
@@ -633,6 +643,8 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
$(MODOBJS) \
$(srcdir)/Modules/getbuildinfo.c
$(CC) -c $(PY_CFLAGS) \
+ -DDATE="\"$(BUILD_DATE)\"" \
+ -DTIME="\"$(BUILD_TIME)\"" \
-DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \
-DGITTAG="\"`LC_ALL=C $(GITTAG)`\"" \
-DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \

+ 1
- 1
lang/python/python3/Makefile View File

@ -14,7 +14,7 @@ PYTHON_VERSION:=$(PYTHON3_VERSION)
PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO)
PKG_NAME:=python3
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz


+ 28
- 0
lang/python/python3/patches/013-getbuildinfo-date-time-source-date-epoch.patch View File

@ -0,0 +1,28 @@
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -725,6 +725,16 @@ regen-all: regen-opcode regen-opcode-tar
############################################################################
# Special rules for object files
+DATE_FMT = %b %d %Y
+TIME_FMT = %H:%M:%S
+ifdef SOURCE_DATE_EPOCH
+ BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")
+ BUILD_TIME ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(TIME_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(TIME_FMT)" 2>/dev/null || date -u "+$(TIME_FMT)")
+else
+ BUILD_DATE ?= $(shell date "+$(DATE_FMT)")
+ BUILD_TIME ?= $(shell date "+$(TIME_FMT)")
+endif
+
Modules/getbuildinfo.o: $(PARSER_OBJS) \
$(OBJECT_OBJS) \
$(PYTHON_OBJS) \
@@ -732,6 +742,8 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
$(MODOBJS) \
$(srcdir)/Modules/getbuildinfo.c
$(CC) -c $(PY_CORE_CFLAGS) \
+ -DDATE="\"$(BUILD_DATE)\"" \
+ -DTIME="\"$(BUILD_TIME)\"" \
-DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \
-DGITTAG="\"`LC_ALL=C $(GITTAG)`\"" \
-DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \

Loading…
Cancel
Save