Changeset View
Changeset View
Standalone View
Standalone View
share/genbuild.sh
Show All 12 Lines | if [ $# -gt 0 ]; then | ||||
if [ -f "$FILE" ]; then | if [ -f "$FILE" ]; then | ||||
INFO="$(head -n 1 "$FILE")" | INFO="$(head -n 1 "$FILE")" | ||||
fi | fi | ||||
else | else | ||||
echo "Usage: $0 <filename> <srcroot>" | echo "Usage: $0 <filename> <srcroot>" | ||||
exit 1 | exit 1 | ||||
fi | fi | ||||
DESC="" | GIT_TAG="" | ||||
SUFFIX="" | GIT_COMMIT="" | ||||
if [ -e "$(command -v git)" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then | if [ -e "$(command -v git)" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then | ||||
# clean 'dirty' status of touched files that haven't been modified | # clean 'dirty' status of touched files that haven't been modified | ||||
git diff >/dev/null 2>/dev/null | git diff >/dev/null 2>/dev/null | ||||
# if latest commit is tagged and not dirty, then override using the tag name | # if latest commit is tagged and not dirty, then override using the tag name | ||||
RAWDESC=$(git describe --abbrev=0 2>/dev/null) | RAWDESC=$(git describe --abbrev=0 2>/dev/null) | ||||
if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then | if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then | ||||
git diff-index --quiet HEAD -- && DESC=$RAWDESC | git diff-index --quiet HEAD -- && GIT_TAG=$RAWDESC | ||||
fi | fi | ||||
# otherwise generate suffix from git, i.e. string like "59887e8-dirty" | # otherwise generate suffix from git, i.e. string like "59887e8-dirty" | ||||
SUFFIX=$(git rev-parse --short HEAD) | GIT_COMMIT=$(git rev-parse --short HEAD) | ||||
git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" | git diff-index --quiet HEAD -- || GIT_COMMIT="$GIT_COMMIT-dirty" | ||||
fi | fi | ||||
if [ -n "$DESC" ]; then | if [ -n "$GIT_TAG" ]; then | ||||
NEWINFO="#define BUILD_DESC \"$DESC\"" | NEWINFO="#define BUILD_GIT_TAG \"$GIT_TAG\"" | ||||
elif [ -n "$SUFFIX" ]; then | elif [ -n "$GIT_COMMIT" ]; then | ||||
NEWINFO="#define BUILD_SUFFIX $SUFFIX" | NEWINFO="#define BUILD_GIT_COMMIT \"$GIT_COMMIT\"" | ||||
else | else | ||||
NEWINFO="// No build information available" | NEWINFO="// No build information available" | ||||
fi | fi | ||||
# only update build.h if necessary | # only update build.h if necessary | ||||
if [ "$INFO" != "$NEWINFO" ]; then | if [ "$INFO" != "$NEWINFO" ]; then | ||||
echo "$NEWINFO" >"$FILE" | echo "$NEWINFO" >"$FILE" | ||||
fi | fi |