Skip to content

bpo-29708: support SOURCE_DATE_EPOCH for build info #5313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,25 @@ regen-all: regen-opcode regen-opcode-targets regen-typeslots regen-grammar regen
############################################################################
# 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) \
$(MODULE_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)`\"" \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Honor the SOURCE_DATE_EPOCH environment variable during build to produce
reproducible binaries. This means using the SOURCE_DATE_EPOCH value to
compute values for the DATE and TIME variables, that will be used in
Modules/getbuildinfo.c