version.sh: keep the short version even if there are patches on top.

Instead of reverting to 0.0.0, keep the same version number (eg. 1.2.4)
but add an extra suffix with the change count,
eg. 1.2.4-6-tb35d95ad7-gcb8be72e6. This avoids the problem where a
small patch causes the code to report a totally different version to
the server, which might change its behaviour based on version code.
(The server might enable various bug workarounds since it thinks
0.0.0 is very old.)

Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
pull/914/head
Avery Pennarun 4 years ago
parent 0050070493
commit c03543dbe2

@ -70,12 +70,12 @@ func TestMkversion(t *testing.T) {
VERSION_XCODE="101.15.129"
VERSION_WINRES="1,15,129,0"`},
{"abcdef", "", 1, 2, 0, 17, `
VERSION_SHORT="0.0.0"
VERSION_LONG="0.0.0-tabcdef"
VERSION_SHORT="1.2.0"
VERSION_LONG="1.2.0-17-tabcdef"
VERSION_GIT_HASH="abcdef"
VERSION_EXTRA_HASH=""
VERSION_XCODE="100.0.0"
VERSION_WINRES="0,0,0,0"`},
VERSION_XCODE="101.2.0"
VERSION_WINRES="1,2,0,0"`},
{"abcdef", "defghi", 1, 15, 0, 129, `
VERSION_SHORT="1.15.129"
VERSION_LONG="1.15.129-tabcdef-gdefghi"

@ -8,8 +8,8 @@ set -eu
# 1be01ddc6e430ca3aa9beea3587d16750efb3241-dirty
git_hash_dirty() {
(
cd "$1" &&
x=$(git rev-parse HEAD) &&
cd "$1"
x=$(git rev-parse HEAD)
if ! git diff-index --quiet HEAD; then
x="$x-dirty"
fi
@ -33,8 +33,8 @@ case $# in
extra_hash=""
elif [ -d "$extra_hash_or_dir/.git" ]; then
extra_hash=$(git_hash_dirty "$extra_hash_or_dir" HEAD)
elif ! expr "$extra_hash" : "^[0-9a-f]*$"; then
echo "Invalid extra hash '$extra_hash', must be a git commit hash or path to a git repo" >&2
elif ! expr "$extra_hash_or_dir" : "^[0-9a-f]*$"; then
echo "Invalid extra hash '$extra_hash_or_dir', must be a git commit or path to a git repo" >&2
exit 1
else
extra_hash="$extra_hash_or_dir"
@ -64,7 +64,7 @@ case $# in
change_count=$6
;;
*)
echo "Usage: $0 [extra-git-hash-or-checkout]"
echo "Usage: $0 [extra-git-commitid-or-dir]"
exit 1
esac
@ -87,18 +87,21 @@ if expr "$minor" : "[0-9]*[13579]$" >/dev/null; then
exit 1
fi
patch="$change_count"
change_suffix=""
elif [ "$change_count" != "0" ]; then
# Even minor numbers are stable builds, but stable builds are
# supposed to have a zero change count. Therefore, we're currently
# describing a commit that's on a release branch, but hasn't been
# tagged as a patch release yet. We allow these commits to build
# for testing purposes, but force their version number to 0.0.0,
# to reflect that they're an unreleasable build. The git hashes
# still completely describe the build commit, so we can still
# figure out what this build is if it escapes into the wild.
major="0"
minor="0"
patch="0"
# tagged as a patch release yet.
#
# We used to change the version number to 0.0.0 in that case, but that
# caused some features to get disabled due to the low version number.
# Instead, add yet another suffix to the version number, with a change
# count.
change_suffix="-$change_count"
else
# Even minor number with no extra changes.
change_suffix=""
fi
# Hack for 1.1: add 1000 to the patch number. We switched from using
@ -113,9 +116,9 @@ fi
# policies. All that remains is to output the various vars that other
# code can use to embed version data.
if [ -z "$extra_hash" ]; then
long_version_suffix="-t$short_git_hash"
long_version_suffix="$change_suffix-t$short_git_hash"
else
long_version_suffix="-t${short_git_hash}-g${short_extra_hash}"
long_version_suffix="$change_suffix-t$short_git_hash-g$short_extra_hash"
fi
cat <<EOF
VERSION_SHORT="$major.$minor.$patch"

Loading…
Cancel
Save