mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	We need to use git describe in a way that only refers to vX.Y.Z style tags. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
		
			
				
	
	
		
			76 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/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 --match "v[0-9]*" --abbrev=12"
 | |
| 	v0=$($cmd) || v0=$(cat .gitversion) || croak "odd; command '$cmd' failed"
 | |
| fi
 | |
| 
 | |
| # strip off the 'v' prefix, if any
 | |
| v0=${v0#v}
 | |
| 
 | |
| case $os in
 | |
| 	linux)
 | |
| 		v=$v0
 | |
| 		;;
 | |
| 	darwin)
 | |
| 		# 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
 | |
| 		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 ]; then
 | |
| 			if [ $# -gt 1 ]; then
 | |
| 				v=$v.$2
 | |
| 			else
 | |
| 				v=$v.0
 | |
| 			fi
 | |
| 		fi
 | |
| 		;;
 | |
| 	full|win)
 | |
| 		# 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
 | |
| 		v=$1
 | |
| 		if [ $dots -eq 1 ]; then
 | |
| 			v=$v.0
 | |
| 		fi
 | |
| 		if [ $# -gt 1 ]; then
 | |
| 			v=$v.$2
 | |
| 		else
 | |
| 			v=$v.0
 | |
| 		fi
 | |
| 		;;
 | |
| 	*)
 | |
| 		v=git.missing.please.hardcode.version
 | |
| 		;;
 | |
| esac
 | |
| printf '%s' $v
 |