From 9a34ab0fb90494ed36d47a4259d1f3f8490af1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sat, 23 Sep 2023 22:38:18 +0200 Subject: [PATCH] Introduce GIT_EPOCH for getting SOURCE_DATE_EPOCH date in tarball --- .gitepoch | 1 + Makefile | 11 +---------- docs/Makefile | 5 +++++ docs/images/Makefile | 4 ++-- git.mk | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 .gitepoch create mode 100644 git.mk diff --git a/.gitepoch b/.gitepoch new file mode 100644 index 00000000000..2707647aacc --- /dev/null +++ b/.gitepoch @@ -0,0 +1 @@ +$Format:%ct$ diff --git a/Makefile b/Makefile index fa95b7b7035..08cf1d98dc6 100644 --- a/Makefile +++ b/Makefile @@ -143,16 +143,7 @@ endif YOSYS_VER := 0.33+0 -# Note: We arrange for .gitcommit to contain the (short) commit hash in -# tarballs generated with git-archive(1) using .gitattributes. The git repo -# will have this file in its unexpanded form tough, in which case we fall -# back to calling git directly. -TARBALL_GIT_REV := $(shell cat $(YOSYS_SRC)/.gitcommit) -ifeq ($(TARBALL_GIT_REV),$$Format:%h$$) -GIT_REV := $(shell GIT_DIR=$(YOSYS_SRC)/.git git rev-parse --short=9 HEAD || echo UNKNOWN) -else -GIT_REV := $(TARBALL_GIT_REV) -endif +include git.mk #< sets $(GIT_REV) OBJS = kernel/version_$(GIT_REV).o diff --git a/docs/Makefile b/docs/Makefile index 2319e1665c3..f18b45dc1f5 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -14,6 +14,11 @@ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) sou # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# Reproducibility +include ../git.mk #< sets $(GIT_EPOCH) +export FORCE_SOURCE_DATE ?= 1 +export SOURCE_DATE_EPOCH ?= $(GIT_EPOCH) + .PHONY: help help: @echo "Please use \`make ' where is one of" diff --git a/docs/images/Makefile b/docs/images/Makefile index 5b3c0350c81..497472cf792 100644 --- a/docs/images/Makefile +++ b/docs/images/Makefile @@ -21,9 +21,9 @@ dots: $(DOT_PDF) tex: $(TEX_PDF) svg: $(SVG_OUTPUT) +include ../../git.mk #< sets $(GIT_EPOCH) export FORCE_SOURCE_DATE ?= 1 -export SOURCE_DATE_EPOCH ?= 1640991600 -#^ 2022-01-01 00:00:00 +export SOURCE_DATE_EPOCH ?= $(GIT_EPOCH) 011/%.pdf: $(DOT_LOC)/%.dot dot -Tpdf -o $@ $< diff --git a/git.mk b/git.mk new file mode 100644 index 00000000000..512d1161d1d --- /dev/null +++ b/git.mk @@ -0,0 +1,16 @@ +GIT_METADATA_DIR := $(dir $(lastword $(MAKEFILE_LIST))) + +# Note: We arrange for .gitcommit to contain the (short) commit hash in +# tarballs generated with git-archive(1) using .gitattributes. The git repo +# will have this file in its unexpanded form tough, in which case we fall +# back to calling git directly. + +TARBALL_GIT_REV := $(shell cat $(GIT_METADATA_DIR)/.gitcommit) +ifeq ($(TARBALL_GIT_REV),$$Format:%h$$) +GIT_REV := $(shell GIT_DIR=$(GIT_METADATA_DIR)/.git git rev-parse --short=9 HEAD || echo UNKNOWN) +GIT_EPOCH = $(shell GIT_DIR=$(GIT_METADATA_DIR)/.git git show --format=%ct -q || echo 1640991600) +#^ 1640991600 == 2022-01-01 00:00:00 +else +GIT_REV := $(TARBALL_GIT_REV) +GIT_EPOCH = $(shell cat $(GIT_METADATA_DIR)/.gitepoch) +endif