Re: [PATCH] newvers.sh

From: M. Warner Losh <imp_at_bsdimp.com>
Date: Sat, 13 Mar 2010 21:13:03 -0700 (MST)
In message: <20100312171206.GA31761_at_dragon.NUXI.org>
            "David O'Brien" <obrien_at_freebsd.org> writes:
: * Simplify SRCDIR calculation by directly finding the kernel sources
:   based directly on one of them.
: 
: Reviewed by: dhw
: 
:   This change does not increase the kernel build time.  It also continues
:   to restrict the revision to just the kernel sources, and not the whole
:   tree.
: 
: Timing tests by: dhw

<patch omitted>

David,

I have a better simplification, I think, that works for me for each of
the tests that I've done (both traditional and buildkernel builds).

The Makefile already knows where the kernel src is located.  Let's use
that knowledge to make things a little simpler.  This also uses the
Makefile variable SYSDIR.  It should also work with non-standard sys
directories.

There's one divergence between svn and git tagging: svn does src/sys,
while git does src.  This is how the previous code was before, and I
don't think I've changed that.

Can you confirm this works for you and also comment on the change
itself?  It is a bigger change, but results in a simpler (I think)
newvers.sh.

Comments?

Warner

Index: conf/kern.post.mk
===================================================================
--- conf/kern.post.mk	(revision 204938)
+++ conf/kern.post.mk	(working copy)
_at__at_ -244,7 +244,7 _at__at_
 	${NORMAL_LINT}
 
 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
-	MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT}
+	MAKE=${MAKE} SYSDIR=$S sh $S/conf/newvers.sh ${KERN_IDENT}
 
 vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
 	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
Index: conf/newvers.sh
===================================================================
--- conf/newvers.sh	(revision 204938)
+++ conf/newvers.sh	(working copy)
_at__at_ -44,7 +44,7 _at__at_
 		${PARAMFILE})
 else
 	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
-		$(dirname $0)/../sys/param.h)
+		${SYSDIR}/sys/param.h)
 fi
 
 
_at__at_ -84,54 +84,46 _at__at_
 fi
 
 touch version
-v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
+v=`cat version` u=${USER:-root} h=${HOSTNAME:-`hostname`} t=`date`
 i=`${MAKE:-make} -V KERN_IDENT`
 
-case "$d" in
-*/sys/*)
-	SRCDIR=${d##*obj}
-	if [ -n "$MACHINE" ]; then
-		SRCDIR=${SRCDIR##/$MACHINE}
+for dir in /bin /usr/bin /usr/local/bin; do
+	if [ -d "${SYSDIR}/.svn" -a -x "${dir}/svnversion" ] ; then
+		svnversion=${dir}/svnversion
+		break
 	fi
-	SRCDIR=${SRCDIR%%/sys/*}
+	if [ -d "${SYSDIR}/../.git" -a -x "${dir}/git" ] ; then
+		git_cmd="${dir}/git --git-dir=${SYSDIR}/../.git"
+		break
+	fi
+done
 
-	for dir in /bin /usr/bin /usr/local/bin; do
-		if [ -d "${SRCDIR}/sys/.svn" -a -x "${dir}/svnversion" ] ; then
-			svnversion=${dir}/svnversion
-			break
-		fi
-		if [ -d "${SRCDIR}/.git" -a -x "${dir}/git" ] ; then
-			git_cmd="${dir}/git --git-dir=${SRCDIR}/.git"
-			break
-		fi
-	done
+if [ -n "$svnversion" ] ; then
+    echo "$svnversion"
+	svn=" r`cd ${SYSDIR} && $svnversion`"
+fi
 
-	if [ -n "$svnversion" ] ; then
-		svn=" r`cd ${SRCDIR}/sys && $svnversion`"
-	fi
-	if [ -n "$git_cmd" ] ; then
-		git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
-		svn=`$git_cmd svn find-rev $git 2>/dev/null`
-		if [ -n "$svn" ] ; then
+if [ -n "$git_cmd" ] ; then
+	git=`$git_cmd rev-parse --verify --short HEAD 2>/dev/null`
+	svn=`$git_cmd svn find-rev $git 2>/dev/null`
+	if [ -n "$svn" ] ; then
+		svn=" r${svn}"
+		git="=${git}"
+	else
+		svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
+		     sed -n 's/^.*_at_\([0-9][0-9]*\).*$/\1/p'`
+		if [ -n $svn ] ; then
 			svn=" r${svn}"
-			git="=${git}"
+			git="+${git}"
 		else
-			svn=`$git_cmd log | fgrep 'git-svn-id:' | head -1 | \
-			     sed -n 's/^.*_at_\([0-9][0-9]*\).*$/\1/p'`
-			if [ -n $svn ] ; then
-				svn=" r${svn}"
-				git="+${git}"
-			else
-				git=" ${git}"
-			fi
+			git=" ${git}"
 		fi
-		if $git_cmd --work-tree=${SRCDIR} diff-index \
-		    --name-only HEAD | read dummy; then
-			git="${git}-dirty"
-		fi
 	fi
-	;;
-esac
+	if $git_cmd --work-tree=${SYSDIR}/.. diff-index \
+	    --name-only HEAD | read dummy; then
+		git="${git}-dirty"
+	fi
+fi
 
 cat << EOF > vers.c
 $COPYRIGHT
Received on Sun Mar 14 2010 - 03:18:39 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:01 UTC