xref: /haiku/build/scripts/determine_haiku_revision (revision a3e794ae459fec76826407f8ba8c94cd3535f128)
1#!/bin/sh
2
3haikuTop=$1
4revisionFile=$2
5haikuBuildOutputDir=`dirname $revisionFile`
6lastBuiltRevisionFile=${haikuBuildOutputDir}/last-built-revision
7
8case `uname` in
9Darwin)
10	SED=gsed
11	;;
12*)
13	SED=sed
14	;;
15esac
16export SED
17
18revision=`cat ${revisionFile} 2>/dev/null`
19lastBuiltRevision=`cat $lastBuiltRevisionFile 2>/dev/null`
20
21originalDir=`pwd`
22cd ${haikuTop}
23export LC_ALL=C
24
25localRev=`git rev-parse HEAD`
26
27# only determine the haiku-revision if anything has changed from
28# last build
29if [ -z "$revision" -o "$lastBuiltRevision" != "$localRev" ]; then
30	# the revision we use is the description of HEAD with respect to the
31	# last reachable hrev-(haiku-revision-)tag
32	revision=`git describe --dirty --tags --match=hrev*`
33	if [ -z "$revision" ]; then
34		# failed to find any hrev tags, bail out
35		echo "Error: you are using a Haiku clone without tags, please set"
36		echo "       the revision tag to use (e.g. HAIKU_REVISION=hrev43210)"
37		exit 1
38	elif echo "$revision" | grep -- '-' >/dev/null; then
39		# HEAD is not directly a changeset from Haiku's central repo, so we
40		# add the current branch name as additional info
41		branchName=`git branch | grep '*' | cut -b 3-`
42		revision="$revision [$branchName]"
43	fi
44fi
45
46cd $originalDir
47
48if [ -z "$revision" ]; then
49	revision=0
50fi
51
52echo $localRev >${lastBuiltRevisionFile}
53echo $revision >${revisionFile}
54