Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Aug 2010 05:10:56 +0400
From:      Anonymous <swell.k@gmail.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: [CFT] [sys/conf/newvers.sh] Cleanup and additions.
Message-ID:  <86hbj2qc0n.fsf@gmail.com>
In-Reply-To: <4C61C50E.8040900__28807.0786548362$1281476071$gmane$org@dataix.net> (jhell@dataix.net's message of "Tue, 10 Aug 2010 17:30:54 -0400")
References:  <4C61C50E.8040900__28807.0786548362$1281476071$gmane$org@dataix.net>

next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-=

(a copy for current@)

jhell <jhell@dataix.net> writes:

>  * Adjust the paths that are checked for binaries to be of only
> /usr/local/bin and /usr/bin. "/bin" is highly unlikely to hold svn(1),
> git(1) or hg(1).

Please, look at conf/146828. That script shouldn't blindly assume where
user installs his packages[1].

[1] using non-default LOCALBASE is a convenient way to identify
    non-conforming ports

> +                                gitsvnid="`$git log |fgrep 'git-svn-id:' |head -1 |\
> +                                sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`"

The above line can be sed-only. A few parts can be simplified, too.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=a.diff

diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh
index 40761bb..568b1fe 100644
--- a/sys/conf/newvers.sh
+++ b/sys/conf/newvers.sh
@@ -83,61 +83,59 @@ LC_ALL=C; export LC_ALL
 v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
 i=`${MAKE:-make} -V KERN_IDENT`
 
+find-bin() {
+	local c prog PATH
+
+	PATH=${LOCALBASE-/usr/local}/bin
+
+	for c; do
+	    prog=$(command -v $c)
+	    if [ -x "$prog" ]; then
+		eval $c=$prog
+	    fi
+	done
+}
+
 case "$d" in
 */sys/*)
-	SRCDIR=${d##*obj}
+	SRCDIR=${d##*${MAKEOBJDIRPREFIX:-/usr/obj}}
 	if [ -n "$MACHINE" ]; then
 		SRCDIR=${SRCDIR##/$MACHINE}
 	fi
 	SRCDIR=${SRCDIR%%/sys/*}
 
+	find-bin svnversion hg git
+
 	if [ -d "${SRCDIR}/.svn" -o -d "${SRCDIR}/sys/.svn" ]; then
-		for dir in /usr/local/bin; do
-			if [ -x "${dir}/svn" ]; then
-				svnversion=${dir}/svnversion
-				break
-			fi
-		done
 		if [ -n "$svnversion" ] ; then
 			svnrev=" r`cd ${SRCDIR}/sys && $svnversion`"
 		fi
 	fi
 
 	if [ -d "${SRCDIR}/.hg" -o -d "${SRCDIR}/sys/.hg" ]; then
-		for dir in /usr/local/bin; do
-			if [ -x "${dir}/hg" ]; then
-				hg=${dir}/hg
-				break
-			fi
-		done
 		if [ -n "$hg" ]; then
 			hgrev=" `cd ${SRCDIR}/sys && $hg tip --template '{rev}:{node|short}'`"
 		fi
 	fi
 
 	if [ -d "${SRCDIR}/.git" -o -d "${SRCDIR}/sys/.git" ]; then
-		for dir in /usr/local/bin; do
-			if [ -x "${dir}/git" ]; then
+		if [ -n "$git" ]; then
 				if [ -d "${SRCDIR}/.git" ]; then
-					git="${dir}/git --git-dir=${SRCDIR}/.git"
+					git="${git} --git-dir=${SRCDIR}/.git"
 					git="${git} --work-tree=${SRCDIR}"
 				else
-					git="${dir}/git --git-dir=${SRCDIR}/sys/.git"
+					git="${git} --git-dir=${SRCDIR}/sys/.git"
 					git="${git} --work-tree=${SRCDIR}/sys"
 				fi
-				break
-			fi
-		done
 
-		if [ -n "$git" ] ; then
 			gitrev="`$git rev-parse --verify --short HEAD 2>/dev/null`"
 			gitsvnrev="`$git svn find-rev $gitrev 2>/dev/null`"
 			if [ -n "${gitsvnrev}" ] ; then
 				svnrev=" r${gitsvnrev}"
 				gitrev="=${gitrev}"
 			else
-				gitsvnid="`$git log |fgrep 'git-svn-id:' |head -1 |\
-				sed -n 's/^.*@\([0-9][0-9]*\).*$/\1/p'`"
+				gitsvnid="`$git log | sed -n '/git-svn-id:/ {
+                                           s/.*@\([[:digit:]]\{1,\}\).*/\1/p; q; }'`"
 				if [ -n "${gitsvnid}" ]; then
 					svnrev=" r${gitsvnid}"
 					gitrev="+${gitrev}"

--=-=-=--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86hbj2qc0n.fsf>