Skip to content

Commit 222e7a2

Browse files
committedMay 25, 2022
Make GIT_REV logic work in release tarballs
Currently GIT_REV doesn't get set properly when building a release tarball. To fix this we arrange for .gitcommit to contain the (short) commit hash in tarballs generated with git-archive(1) using export-subst in gitattributes. This way the correct commit hash is (reproducibly) included in the release tarballs while not burdening the maintainers with updating it in the git repo. Please note this even works on Github and similar forges as they use git-archive for generating tarballs so this works out quite nicely.
1 parent cffec1f commit 222e7a2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.v linguist-language=Verilog
2+
/.gitcommit export-subst

‎.gitcommit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$Format:%h$

‎Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,18 @@ LDLIBS += -lrt
130130
endif
131131

132132
YOSYS_VER := 0.17+41
133+
134+
# Note: We arrange for .gitcommit to contain the (short) commit hash in
135+
# tarballs generated with git-archive(1) using .gitattributes. The git repo
136+
# will have this file in its unexpanded form tough, in which case we fall
137+
# back to calling git directly.
138+
TARBALL_GIT_REV := $(shell cat $(YOSYS_SRC)/.gitcommit)
139+
ifeq ($(TARBALL_GIT_REV),$$Format:%h$$)
133140
GIT_REV := $(shell git ls-remote $(YOSYS_SRC) HEAD -q | $(AWK) 'BEGIN {R = "UNKNOWN"}; ($$2 == "HEAD") {R = substr($$1, 1, 9); exit} END {print R}')
141+
else
142+
GIT_REV := $(TARBALL_GIT_REV)
143+
endif
144+
134145
OBJS = kernel/version_$(GIT_REV).o
135146

136147
bumpversion:

0 commit comments

Comments
 (0)
Please sign in to comment.