From 8ff44a43293c7a00470f8bf52881f7610899e256 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sun, 15 May 2011 22:45:43 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20and=20improve=20code=20for=20determining?= =?UTF-8?q?=20Haiku=20revision=20from=20a=20git=20repo=20*=20break=20out?= =?UTF-8?q?=20most=20of=20the=20CopySetHaikuRevision=20action=20into=20a?= =?UTF-8?q?=20separate=20script:=20=20=20determine=5Fhaiku=5Frevision=20*?= =?UTF-8?q?=20fix=20git=20branch=20detection=20such=20that=20it'll=20actua?= =?UTF-8?q?lly=20work=20for=20local=20branches=20(thanks=20to=20=20=20Andr?= =?UTF-8?q?eas=20F=C3=A4rber=20for=20the=20hint)=20*=20add=20some=20sanity?= =?UTF-8?q?=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41520 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/FileRules | 63 +---------------- build/scripts/determine_haiku_revision | 97 ++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 61 deletions(-) create mode 100644 build/scripts/determine_haiku_revision diff --git a/build/jam/FileRules b/build/jam/FileRules index 04c7020933..65cf50917e 100644 --- a/build/jam/FileRules +++ b/build/jam/FileRules @@ -335,67 +335,8 @@ actions CopySetHaikuRevision1 { $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) - originalDir=`pwd` - cd $(HAIKU_TOP) - export LC_ALL=C - if [ -d .svn ]; then - revision=`svn info 2>/dev/null | grep Revision | awk '{printf $2}'` - elif [ -d .git/svn ]; then - revision=`git svn info 2>/dev/null | grep Revision | awk '{printf $2}'` - elif [ -d .git ]; then - revision=`cat $(HAIKU_BUILD_OUTPUT_DIR)/haiku-revision 2>/dev/null` - lastBuiltRevision=`cat $(HAIKU_BUILD_OUTPUT_DIR)/last-built-revision \ - 2>/dev/null` - localRev=`git rev-list -n1 HEAD` - - # only determine the haiku-revision if anything has changed from - # last build - if [ -z "$revision" -o "$lastBuiltRevision" != "$localRev" ]; then - currentBranch=`git branch --contains HEAD | awk '{printf $2}'` - haikuTip=`git rev-list -n1 haiku/${currentBranch}.tip` - - # make sure that haiku-tip matches the remote tracking branch, - # otherwise the tag hasn't been fetched/updated and we should - # print a warning - trackingBranch=`git branch -r --contains $haikuTip \ - | grep -v -- '->' | tr -d ' '` - haikuTipLag=`git rev-list --count ${haikuTip}..$trackingBranch` - if [ "$haikuTipLag" != "0" ]; then - echo "*********************************************************" - echo "!!! haiku/${currentBranch}.tip is $haikuTipLag behind \ - remote tracking branch" - echo "!!! you may want to 'git fetch --tags' to update the tag" - echo "*********************************************************" - fi - - # the haiku revision the HEAD is based on is the nearest common ancestor - # of these two (i.e. the merge base) - haikuBaseRev=`git merge-base $localRev $haikuTip` - - # the revision we use is the description of HEAD with - # respect to the root of the current branch - revision=`git describe --dirty --long --match=haiku/$currentBranch` - if [ "$localRev" != "$haikuBaseRev" ]; then - # HEAD is not a changeset from Haiku's central repo, so we add - # a description of the changeset in Haiku's repo HEAD is based on - haikuBaseRevDescr=`git describe --long --match=haiku/$currentBranch $haikuBaseRev` - revision="$revision [$haikuBaseRevDescr]" - fi - echo $localRev >$(HAIKU_BUILD_OUTPUT_DIR)/last-built-revision - fi - elif [ -d .hg ]; then - # Try searching hg log for last svn commit - # Extract from "(svn r12345) ..." line - revision=`(cd $(HAIKU_TOP) && - hg log --no-merges --template "{desc|firstline}\n") 2> /dev/null | - grep --max-count=1 "(svn r" | - sed -n -e 's,(svn r\(.*\)).*,\1,p'` - fi - if [ "$revision" = "" ]; then - revision=0 - fi - echo $revision >$(HAIKU_BUILD_OUTPUT_DIR)/haiku-revision - cd $originalDir + . $(HAIKU_TOP)/build/scripts/determine_haiku_revision $(HAIKU_TOP) \ + $(HAIKU_BUILD_OUTPUT_DIR) $(2[1]) --data $(2[3]) $(1) && $(2[2]) $(1) ${revision} } diff --git a/build/scripts/determine_haiku_revision b/build/scripts/determine_haiku_revision new file mode 100644 index 0000000000..ae1e035e22 --- /dev/null +++ b/build/scripts/determine_haiku_revision @@ -0,0 +1,97 @@ +#!/bin/sh + +# get and check the parameters +if [ $# -lt 2 ]; then + echo Usage: $0 ' ' >&2 + exit 1 +fi + +HAIKU_TOP=$1 +HAIKU_BUILD_OUTPUT_DIR=$2 + + +determineGitRevision() +{ + revision=`cat ${HAIKU_BUILD_OUTPUT_DIR}/haiku-revision 2>/dev/null` + lastBuiltRevision=`cat ${HAIKU_BUILD_OUTPUT_DIR}/last-built-revision \ + 2>/dev/null` + localRev=`git rev-list -n1 HEAD` + + # only determine the haiku-revision if anything has changed from + # last build + if [ -z "$revision" -o "$lastBuiltRevision" != "$localRev" ]; then + haikuBranch=`git describe --abbrev=0 --match 'haiku/*.base' \ + | sed -re 's/haiku\/(.*)\.base/\1/'` + if [ -z "$haikuBranch" ]; then + echo "*** unable to find haiku branch the build is based on" + exit 1; + fi + haikuTip=`git rev-list -n1 haiku/${haikuBranch}.tip` + if [ -z "$haikuTip" ]; then + echo "*** unable to find tip of haiku branch the build is based on" + exit 1; + fi + + # make sure that haiku-tip matches the remote tracking branch, + # otherwise the tag hasn't been fetched/updated and we should + # print a warning + trackingBranch=`git branch -r --contains $haikuTip \ + | grep -v -- '->' | tr -d ' '` + if [ -z "$trackingBranch" ]; then + echo "*** unable to find tracking branch the build is based on" + exit 1; + fi + haikuTipLag=`git rev-list --count ${haikuTip}..$trackingBranch` + if [ "$haikuTipLag" != "0" ]; then + echo "*********************************************************" + echo "!!! haiku/${haikuBranch}.tip is $haikuTipLag behind \ + remote tracking branch" + echo "!!! you may want to 'git fetch --tags' to update the tag" + echo "*********************************************************" + fi + + # the haiku revision the HEAD is based on is the nearest common ancestor + # of these two (i.e. the merge base) + haikuBaseRev=`git merge-base $localRev $haikuTip` + if [ -z "$haikuTip" ]; then + echo "*** unable to find merge-base for haiku tip and build" + exit 1; + fi + + # the revision we use is the description of HEAD with + # respect to the root of the current branch + revision=`git describe --dirty --long --match=haiku/$haikuBranch` + if [ "$localRev" != "$haikuBaseRev" ]; then + # HEAD is not a changeset from Haiku's central repo, so we add + # a description of the changeset in Haiku's repo HEAD is based on + haikuBaseRevDescr=`git describe --long --match=haiku/$haikuBranch \ + $haikuBaseRev` + revision="$revision [$haikuBaseRevDescr]" + fi + echo $localRev >${HAIKU_BUILD_OUTPUT_DIR}/last-built-revision + fi +} + + +originalDir=`pwd` +cd ${HAIKU_TOP} +export LC_ALL=C +if [ -d .svn ]; then + revision=`svn info 2>/dev/null | grep Revision | awk '{printf $2}'` +elif [ -d .git/svn ]; then + revision=`git svn info 2>/dev/null | grep Revision | awk '{printf $2}'` +elif [ -d .git ]; then + determineGitRevision +elif [ -d .hg ]; then + # Try searching hg log for last svn commit + # Extract from "(svn r12345) ..." line + revision=`(cd ${HAIKU_TOP} && + hg log --no-merges --template "{desc|firstline}\n") 2> /dev/null | + grep --max-count=1 "(svn r" | + sed -n -e 's,(svn r\(.*\)).*,\1,p'` +fi +if [ "$revision" = "" ]; then + revision=0 +fi +echo $revision >${HAIKU_BUILD_OUTPUT_DIR}/haiku-revision +cd $originalDir