@@ -10,34 +10,35 @@ die ()
1010[ $# -ne 1 ] && exit 1
1111VERSION_H=" $1 "
1212
13- # If we are being run from a release tarball, then a version.h.distrib must
14- # be present, and we always use that as our source of truth. Allow ./.git
15- # to be a file to support git worktrees.
16- if [ ! -d " ./.git" -a ! -f " ./.git" ]; then
17- if [ ! -f " ${VERSION_H} .distrib" ]; then
18- die " ${VERSION_H} .distrib: Not found, and we are not in a Git tree"
19- fi
13+ # Determine the version, in order of precedence:
14+ # 1. "git describe" in a real checkout (allow ./.git to be a file for worktrees)
15+ # 2. version.h.distrib shipped in a release tarball
16+ # 3. $SOLO5_VERSION for an exported snapshot (e.g. an opam tarball pin) that has
17+ # neither a Git tree nor a version.h.distrib
18+ if [ -d " ./.git" -o -f " ./.git" ]; then
19+ VERSION=" $( git -C . describe --dirty --tags --always) " ||
20+ die " Could not determine Git version"
21+ elif [ -f " ${VERSION_H} .distrib" ]; then
2022 cp " ${VERSION_H} .distrib" " ${VERSION_H} " || die
2123 exit 0
24+ elif [ -n " ${SOLO5_VERSION} " ]; then
25+ VERSION=" ${SOLO5_VERSION} "
26+ else
27+ die " not a Git tree, ${VERSION_H} .distrib not found, and SOLO5_VERSION unset"
2228fi
2329
24- # Otherwise, use "git describe" to get the exact version of this tree, and
25- # generate a version.h from it.
26- GIT_VERSION=" $( git -C . describe --dirty --tags --always) " ||
27- die " Could not determine Git version"
28-
2930cat << EOM >${VERSION_H} .tmp || die
3031/* Automatically generated, do not edit */
3132
3233#ifndef __VERSION_H__
3334#define __VERSION_H__
3435
35- #define SOLO5_VERSION "${GIT_VERSION } "
36+ #define SOLO5_VERSION "${VERSION } "
3637
3738#endif
3839EOM
3940
40- # Only touch the target file if it does not exist yet or Git version differs.
41+ # Only touch the target file if it does not exist yet or the version differs.
4142if [ -f ${VERSION_H} ] && diff -q ${VERSION_H} ${VERSION_H} .tmp > /dev/null; then
4243 rm ${VERSION_H} .tmp || die
4344else
0 commit comments