Skip to content

Commit

Permalink
Introduce GIT_EPOCH for getting SOURCE_DATE_EPOCH date in tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielG committed Sep 23, 2023
1 parent 9f66482 commit 9a34ab0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitepoch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%ct$
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target>' where <target> is one of"
Expand Down
4 changes: 2 additions & 2 deletions docs/images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@ $<
Expand Down
16 changes: 16 additions & 0 deletions git.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9a34ab0

Please sign in to comment.