.dockerignore excludes .git, so util/genbuild.sh finds no repository inside the container and emits "// No build information available", which clientversion.cpp renders as the "-unk" suffix. Every binary produced by ./build.sh --linux-compat therefore self-reports "v1.2.0-unk" and cannot be traced to a commit -- including release artifacts, since this build path is part of the v1.2.0 tag. Pre-generating src/obj/build.h does not survive (genbuild rewrites it when the content differs), and simply un-ignoring .git does not help a linked worktree, whose .git is a file pointing outside the build context. So build.sh computes the version on the host, mirroring genbuild.sh rule for rule -- the nearest tag only when HEAD is that tag and the tree is clean, otherwise v<VERSION>-<short sha> with a -dirty suffix -- and passes it through a BUILD_DESC build-arg that Dockerfile.compat exports as DRAGONX_BUILD_DESC. genbuild.sh honours that variable when set and is otherwise untouched; with git metadata present it emits a byte-identical build.h. Every added git call is guarded with || true because build.sh runs under set -eu -o pipefail: a source tarball, a host without git, or a branch whose only reachable tags are lightweight (v1.0.1-v1.0.3 are lightweight; v1.1.0 is the first annotated one) would otherwise abort the build with no diagnostic. Those cases now degrade to the previous "-unk" behaviour with a warning. A direct "docker build -f Dockerfile.compat" passes no BUILD_DESC and still produces -unk; the Dockerfile now says so loudly rather than silently.
54 lines
1.7 KiB
Bash
Executable File
54 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Copyright (c) 2018-2024 The Hush developers
|
|
# Distributed under the GPLv3 software license, see the accompanying
|
|
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
if [ $# -gt 1 ]; then
|
|
cd "$2"
|
|
fi
|
|
if [ $# -gt 0 ]; then
|
|
FILE="$1"
|
|
shift
|
|
if [ -f "$FILE" ]; then
|
|
INFO="$(head -n 1 "$FILE")"
|
|
fi
|
|
else
|
|
echo "Usage: $0 <filename> <srcroot>"
|
|
exit 1
|
|
fi
|
|
|
|
DESC=""
|
|
SUFFIX=""
|
|
# Allow the build system to supply the version when git metadata is unavailable:
|
|
# container builds exclude .git, and a linked worktree's .git file points outside
|
|
# the build context. Without this such builds are stamped "-unk".
|
|
if [ -n "${DRAGONX_BUILD_DESC:-}" ]; then
|
|
DESC="$DRAGONX_BUILD_DESC"
|
|
elif [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
|
|
# clean 'dirty' status of touched files that haven't been modified
|
|
git diff >/dev/null 2>/dev/null
|
|
|
|
# if latest commit is tagged and not dirty, then override using the tag name
|
|
RAWDESC=$(git describe --abbrev=0 2>/dev/null)
|
|
if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
|
|
git diff-index --quiet HEAD -- && DESC=$RAWDESC
|
|
fi
|
|
|
|
# otherwise generate suffix from git, i.e. string like "59887e8-dirty"
|
|
SUFFIX=$(git rev-parse --short HEAD)
|
|
git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
|
|
|
|
fi
|
|
|
|
if [ -n "$DESC" ]; then
|
|
NEWINFO="#define BUILD_DESC \"$DESC\""
|
|
elif [ -n "$SUFFIX" ]; then
|
|
NEWINFO="#define BUILD_SUFFIX $SUFFIX"
|
|
else
|
|
NEWINFO="// No build information available"
|
|
fi
|
|
|
|
# only update build.h if necessary
|
|
if [ "$INFO" != "$NEWINFO" ]; then
|
|
echo "$NEWINFO" >"$FILE"
|
|
fi
|