Skip to content
This repository has been archived by the owner on Mar 28, 2018. It is now read-only.

Commit

Permalink
Version: Ensure "--version" and "version" display a commit id.
Browse files Browse the repository at this point in the history
git-archive(1), as used by github.com, allows files to be modified
"on-the-fly" as the archive file is generated.

By configuring git-archive to write the commit id to file
"commit_id.fmt", the build can be convinced (using the mandatory
"clean-local" rule) to generate file "commit_id" from "commit_id.fmt".
The value of "commit_id" is then passed via the compiler to the runtime
to allow the latter to display a commit id when run with either
"--version" or "version".

Signed-off-by: James Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 2, 2016
1 parent 8c0493d commit c8eef53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
commit_id.fmt export-subst
.gitattributes export-ignore
14 changes: 11 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ AUTOMAKE_OPTIONS = parallel-tests

CHECK_DEPS =

# Has a value if building in a git tree
GIT_COMMIT := $(shell git rev-parse HEAD 2>/dev/null)

# Has a value if building in a git-archive(1)-generated tree
# (see .gitattributes).
GENERATED_COMMIT = $(shell cat commit_id.fmt 2>/dev/null \| grep \'^[a-f0-9][a-f0-9]*\$\')

commit_id:
$(AM_V_GEN)if [ "x$(GIT_COMMIT)" != "x" ]; then \
echo "Writing commit id"; \
echo $(GIT_COMMIT) > commit_id; \
echo "Determining commit id from git"; \
echo "$(GIT_COMMIT)" > commit_id; \
elif [ "x$(GENERATED_COMMIT)" != "x" ]; then \
echo "Determining commit id from generated value"; \
echo "$(GENERATED_COMMIT)" > commit_id; \
else \
echo "WARNING: cannot commit id"; \
echo "WARNING: cannot determine actual commit id"; \
echo "0" > commit_id; \
fi

Expand Down
1 change: 1 addition & 0 deletions commit_id.fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%H$

0 comments on commit c8eef53

Please sign in to comment.