subsurface/scripts/get-version

62 lines
1.2 KiB
Text
Raw Normal View History

#!/bin/sh
# $1 - os name {linux|darwin|win}
# $2 - [optional] raw version string "vX.Y-patchN-sha1". as from `git describe'
# (see below)
set -eu
#set -x
croak() {
echo "$0: $*" >&2
exit 1
}
[ $# -ge 1 ] || croak "missing OS argument"
os=$1
if [ $# -eq 2 ] && [ "$2" ]; then
v0=$2
else
cmd="git describe --tags --abbrev=12"
v0=$($cmd) || croak "odd; command '$cmd' failed"
fi
# strip off the 'v' prefix, if any
v0=${v0#v}
case $os in
linux)
v=$v0
;;
darwin|win)
Expand the version magic even more Someone who is better at shell script writing needs to review this. Here's what it's supposed to do. Create version strings with three or four values for darwin or win, respectively, that we can use as the versions of the bundle or installer. The version that Subsurface reports isn't affected by this. So in a way this is automating something that's mostly cosmetic. If we have a 2 digit version number (like 3.0), do the same the old script did - add just zeroes if we are on a tag, otherwise add the number of commits since the tag (and a last 0 if on win). If we have a 3 digit version numner (like 3.0.1), leave it alone on mac and add either the number of commits since the tag or a zero if we are on the tag on win. Now this can create the same version number for two different versions on darwin: the first commit after 3.0 and the version tagged as 3.0.1 will both get the same number. That's kinda silly but remember - the non-tagged versions aren't supposed to be widely distributed (and the third digit in them should be much larger than anything we'd ever release; we are already on commit 16 since the last tag and hopefully will never release a 3.0.16 as tagged release). And of course the full version as displayed in the About box is always able to tell things apart because of the SHA added at the end if it's a non-tagged version. So why all this magic? The reason we do this is so that during development we are able to create Mac and Windows installers and they get reasonable version numbers, based on the versioning that these vendors suppose. And without manual intervention. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24 04:38:30 +00:00
# just the dots in the version string - this way we can
# count them
IFS=.
set -- $v0 # split $v0 using $IFS separator
dots=$(($# - 1)) # use positional argument count
# split version string using a '-' separator
IFS=-
set -- $v0
Expand the version magic even more Someone who is better at shell script writing needs to review this. Here's what it's supposed to do. Create version strings with three or four values for darwin or win, respectively, that we can use as the versions of the bundle or installer. The version that Subsurface reports isn't affected by this. So in a way this is automating something that's mostly cosmetic. If we have a 2 digit version number (like 3.0), do the same the old script did - add just zeroes if we are on a tag, otherwise add the number of commits since the tag (and a last 0 if on win). If we have a 3 digit version numner (like 3.0.1), leave it alone on mac and add either the number of commits since the tag or a zero if we are on the tag on win. Now this can create the same version number for two different versions on darwin: the first commit after 3.0 and the version tagged as 3.0.1 will both get the same number. That's kinda silly but remember - the non-tagged versions aren't supposed to be widely distributed (and the third digit in them should be much larger than anything we'd ever release; we are already on commit 16 since the last tag and hopefully will never release a 3.0.16 as tagged release). And of course the full version as displayed in the About box is always able to tell things apart because of the SHA added at the end if it's a non-tagged version. So why all this magic? The reason we do this is so that during development we are able to create Mac and Windows installers and they get reasonable version numbers, based on the versioning that these vendors suppose. And without manual intervention. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24 04:38:30 +00:00
v=$1
# do we need to add another digit?
# We know there are 1 or 2 dots in $v, so if it's just one
# or we are trying to get to 4, add one digit
if [ $dots -eq 1 ] || [ $os = win ]; then
Expand the version magic even more Someone who is better at shell script writing needs to review this. Here's what it's supposed to do. Create version strings with three or four values for darwin or win, respectively, that we can use as the versions of the bundle or installer. The version that Subsurface reports isn't affected by this. So in a way this is automating something that's mostly cosmetic. If we have a 2 digit version number (like 3.0), do the same the old script did - add just zeroes if we are on a tag, otherwise add the number of commits since the tag (and a last 0 if on win). If we have a 3 digit version numner (like 3.0.1), leave it alone on mac and add either the number of commits since the tag or a zero if we are on the tag on win. Now this can create the same version number for two different versions on darwin: the first commit after 3.0 and the version tagged as 3.0.1 will both get the same number. That's kinda silly but remember - the non-tagged versions aren't supposed to be widely distributed (and the third digit in them should be much larger than anything we'd ever release; we are already on commit 16 since the last tag and hopefully will never release a 3.0.16 as tagged release). And of course the full version as displayed in the About box is always able to tell things apart because of the SHA added at the end if it's a non-tagged version. So why all this magic? The reason we do this is so that during development we are able to create Mac and Windows installers and they get reasonable version numbers, based on the versioning that these vendors suppose. And without manual intervention. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24 04:38:30 +00:00
if [ $# -gt 1 ]; then
v=$v.$2
else
v=$v.0
fi
fi
# and if it was just one dot and we want 4, at another 0
if [ $dots -eq 1 ] && [ $os = win ]; then
Expand the version magic even more Someone who is better at shell script writing needs to review this. Here's what it's supposed to do. Create version strings with three or four values for darwin or win, respectively, that we can use as the versions of the bundle or installer. The version that Subsurface reports isn't affected by this. So in a way this is automating something that's mostly cosmetic. If we have a 2 digit version number (like 3.0), do the same the old script did - add just zeroes if we are on a tag, otherwise add the number of commits since the tag (and a last 0 if on win). If we have a 3 digit version numner (like 3.0.1), leave it alone on mac and add either the number of commits since the tag or a zero if we are on the tag on win. Now this can create the same version number for two different versions on darwin: the first commit after 3.0 and the version tagged as 3.0.1 will both get the same number. That's kinda silly but remember - the non-tagged versions aren't supposed to be widely distributed (and the third digit in them should be much larger than anything we'd ever release; we are already on commit 16 since the last tag and hopefully will never release a 3.0.16 as tagged release). And of course the full version as displayed in the About box is always able to tell things apart because of the SHA added at the end if it's a non-tagged version. So why all this magic? The reason we do this is so that during development we are able to create Mac and Windows installers and they get reasonable version numbers, based on the versioning that these vendors suppose. And without manual intervention. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24 04:38:30 +00:00
v=$v.0
fi
;;
*)
v=git.missing.please.hardcode.version
;;
esac
printf '%s' $v