a58eb3e9ef
When building from a release tag (e.g. v5.4.1), git describe was finding the nearest ancestor tag (v5.3.8) instead of the exact tag, resulting in version strings like 'v5.3.8-9-gdfb4b22' instead of 'v5.4.1'. Now genbuild.sh tries --exact-match first, falling back to distance-based describe only when not on a tagged commit.
41 lines
992 B
Bash
Executable File
41 lines
992 B
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ $# -gt 0 ]; then
|
|
FILE="$1"
|
|
shift
|
|
if [ -f "$FILE" ]; then
|
|
INFO="$(head -n 1 "$FILE")"
|
|
fi
|
|
else
|
|
echo "Usage: $0 <filename>"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -e "$(which git)" ]; then
|
|
# clean 'dirty' status of touched files that haven't been modified
|
|
git diff >/dev/null 2>/dev/null
|
|
|
|
# Try exact tag match first (when building from a release tag)
|
|
DESC="$(git describe --tags --exact-match 2>/dev/null)"
|
|
|
|
# If no exact match, fall back to git describe with commit distance
|
|
if [ -z "$DESC" ]; then
|
|
DESC="$(git describe --tags --dirty 2>/dev/null)"
|
|
fi
|
|
|
|
# get a string like "2012-04-10 16:27:19 +0200"
|
|
TIME="$(git log -n 1 --format="%ci")"
|
|
fi
|
|
|
|
if [ -n "$DESC" ]; then
|
|
NEWINFO="#define BUILD_DESC \"$DESC\""
|
|
else
|
|
NEWINFO="// No build information available"
|
|
fi
|
|
|
|
# only update build.h if necessary
|
|
if [ "$INFO" != "$NEWINFO" ]; then
|
|
echo "$NEWINFO" >"$FILE"
|
|
echo "#define BUILD_DATE \"$TIME\"" >>"$FILE"
|
|
fi
|