From a1e681690c19a50d6c61e6c8bd98d6af4be146d4 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 26 Aug 2013 16:38:50 +0200 Subject: [PATCH] Rework rule CopySetHaikuRevision * Remove support for VCSs other than git. * Make the haiku-revision file a regular build target and make sure it is built only once. * Make determine_haiku_revision an actual shell script and simplify it a bit. --- build/jam/FileRules | 54 ++++++++----- build/scripts/determine_haiku_revision | 103 ++++++++++--------------- 2 files changed, 75 insertions(+), 82 deletions(-) mode change 100644 => 100755 build/scripts/determine_haiku_revision diff --git a/build/jam/FileRules b/build/jam/FileRules index 0285d300bb..85dd45c1d0 100644 --- a/build/jam/FileRules +++ b/build/jam/FileRules @@ -328,51 +328,63 @@ rule ObjectReferences } } + rule CopySetHaikuRevision target : source { # CopySetHaikuRevision : # - # Copy to , writing the SVN revision of the working root + # Copy to , writing the Git revision of the working # directory into the haiku revision section of . # # - Output file target. Gristed and located target. # - ELF object to be copied. Gristed and located target. - # If existent, make the target depend on the .svn/entries file in the + # If existing, make the target depend on the .git/index file in the # root directory, so it gets updated when the revision changes due to - # "svn up". - if [ Glob [ FDirName $(HAIKU_TOP) .svn ] : entries ] { - local svnEntries = entries ; - SEARCH on $(svnEntries) = [ FDirName $(HAIKU_TOP) .svn ] ; - Depends $(target) : $(svnEntries) ; - } else if [ Glob [ FDirName $(HAIKU_TOP) .git ] : index ] { - local gitIndex = index ; - SEARCH on $(gitIndex) = [ FDirName $(HAIKU_TOP) .git ] ; - Depends $(target) : $(gitIndex) ; - } else if [ Glob [ FDirName $(HAIKU_TOP) .hg ] : store ] { - local hgStore = store ; - SEARCH on $(hgStore) = [ FDirName $(HAIKU_TOP) .hg ] ; - Depends $(target) : $(hgStore) ; + # commits or merges. + local gitIndex = index ; + local revisionFile = haiku-revision ; + if ! [ on $(gitIndex) return $(HAIKU_GIT_REVISION_DETERMINED) ] { + if [ Glob [ FDirName $(HAIKU_TOP) .git ] : index ] { + HAIKU_GIT_REVISION_DETERMINED on $(gitIndex) = 1 ; + SEARCH on $(gitIndex) = [ FDirName $(HAIKU_TOP) .git ] ; + MakeLocate $(revisionFile) : $(HAIKU_BUILD_OUTPUT_DIR) ; + Depends $(revisionFile) : $(gitIndex) ; + DetermineHaikuRevision $(revisionFile) : $(gitIndex) ; + } else { + revisionFile = ; + } } PropagateContainerUpdateTargetFlags $(target) : $(source) ; - Depends $(target) : copyattr set_haiku_revision $(source) ; + Depends $(target) + : copyattr set_haiku_revision $(source) $(revisionFile) ; CopySetHaikuRevision1 $(target) - : copyattr set_haiku_revision $(source) ; + : copyattr set_haiku_revision $(source) $(revisionFile) ; } + actions CopySetHaikuRevision1 { $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) - . $(HAIKU_TOP)/build/scripts/determine_haiku_revision - determineHaikuRevision $(HAIKU_TOP) $(HAIKU_BUILD_OUTPUT_DIR) + $(2[1]) --data $(2[3]) $(1) || exit 1 - $(2[1]) --data $(2[3]) $(1) && - $(2[2]) $(1) ${revision} + revision=0 + if [ -n "$(2[4]:E=)" ]; then + revision="`cat $(2[4]:E=)`" + fi + $(2[2]) $(1) "$revision" } + +actions DetermineHaikuRevision +{ + $(HAIKU_TOP)/build/scripts/determine_haiku_revision $(HAIKU_TOP) $(1) +} + + rule DataFileToSourceFile sourceFile : dataFile : dataVariable : sizeVariable { sourceFile = [ FGristFiles $(sourceFile) ] ; diff --git a/build/scripts/determine_haiku_revision b/build/scripts/determine_haiku_revision old mode 100644 new mode 100755 index 012c09008a..465180a12e --- a/build/scripts/determine_haiku_revision +++ b/build/scripts/determine_haiku_revision @@ -1,70 +1,51 @@ #!/bin/sh -determineGitRevision() -{ - haikuTop=$1 - haikuBuildOutputDir=$2 +haikuTop=$1 +revisionFile=$2 +haikuBuildOutputDir=`dirname $revisionFile` +lastBuiltRevisionFile=${haikuBuildOutputDir}/last-built-revision - revision=`cat ${haikuBuildOutputDir}/haiku-revision 2>/dev/null` - lastBuiltRevision=`cat ${haikuBuildOutputDir}/last-built-revision \ - 2>/dev/null` - localRev=`git rev-parse HEAD` +case `uname` in +Darwin) + SED=gsed + ;; +*) + SED=sed + ;; +esac +export SED - # only determine the haiku-revision if anything has changed from - # last build - if [ -z "$revision" -o "$lastBuiltRevision" != "$localRev" ]; then - # the revision we use is the description of HEAD with respect to the - # last reachable hrev-(haiku-revision-)tag - revision=`git describe --dirty --tags --match=hrev*` - if [ -z "$revision" ]; then - # failed to find any hrev tags, use short hash instead - revision=`git rev-parse --short HEAD` - elif echo "$revision" | grep -- '-' >/dev/null; then - # HEAD is not directly a changeset from Haiku's central repo, so we - # add the current branch name as additional info - branchName=`git branch | grep '*' | cut -b 3-` - revision="$revision [$branchName]" - fi - echo $localRev >${haikuBuildOutputDir}/last-built-revision - fi -} +revision=`cat ${revisionFile} 2>/dev/null` +lastBuiltRevision=`cat $lastBuiltRevisionFile 2>/dev/null` +originalDir=`pwd` +cd ${haikuTop} +export LC_ALL=C -determineHaikuRevision() -{ - haikuTop=$1 - haikuBuildOutputDir=$2 +localRev=`git rev-parse HEAD` - case `uname` in - Darwin) - SED=gsed - ;; - *) - SED=sed - ;; - esac - export SED - - originalDir=`pwd` - cd ${haikuTop} - 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 $haikuTop $haikuBuildOutputDir - elif [ -d .hg ]; then - # Try searching hg log for last svn commit - # Extract from "(svn r12345) ..." line - revision=`(cd ${haikuTop} && - 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 +# only determine the haiku-revision if anything has changed from +# last build +if [ -z "$revision" -o "$lastBuiltRevision" != "$localRev" ]; then + # the revision we use is the description of HEAD with respect to the + # last reachable hrev-(haiku-revision-)tag + revision=`git describe --dirty --tags --match=hrev*` if [ -z "$revision" ]; then - revision=0 + # failed to find any hrev tags, use short hash instead + revision=`git rev-parse --short HEAD` + elif echo "$revision" | grep -- '-' >/dev/null; then + # HEAD is not directly a changeset from Haiku's central repo, so we + # add the current branch name as additional info + branchName=`git branch | grep '*' | cut -b 3-` + revision="$revision [$branchName]" fi - echo $revision >${haikuBuildOutputDir}/haiku-revision - cd $originalDir -} +fi + +cd $originalDir + +if [ -z "$revision" ]; then + revision=0 +fi + +echo $localRev >${lastBuiltRevisionFile} +echo $revision >${revisionFile}