svn commit: r254217 - head/sys/conf

Ian Lepore ian at FreeBSD.org
Tue Aug 13 20:10:00 UTC 2013


On Tue, 2013-08-13 at 13:53 -0400, Glen Barber wrote:
> On Tue, Aug 13, 2013 at 11:31:52AM -0600, Ian Lepore wrote:
> > I'm not even sure what $0 *should* expand to in a script that was
> > sourced in.  The manpage doesn't say anything meaningful to me about it.
> > Maybe it's a kind of "indeterminate results" thing which is pretty much
> > what we're seeing.
> > 
> 
> When the file is sourced, it should expand to the name of the file
> sourcing the file. 
> 
> gjb at nucleus:~ % cat foo1.sh foo2.sh
> #!/bin/sh
> echo ${0}
> . foo2.sh
> #!/bin/sh
> echo ${0}
> gjb at nucleus:~ % sh ./foo1.sh
> ./foo1.sh
> ./foo1.sh
> 
> > I was thinking that $(realpath ${PARAMFILE}) might be a good way to tap
> > dance around the problem, but PARAMFILE can be set by default from
> > $SYSDIR and it's not clear to me that that'll always be right either.
> > 
> 
> Can you please try the attached patch?  As with my prior tests, this
> works for me...
> 
> Glen
> 

That didn't work, because $SYSDIR is derived from $0 which is the root
of the problem.  The attached works, and seems reasonable to me (it's
your changes + passing in SYSDIR from the one place where newvers.sh is
sourced rather than running it by name).

-- Ian

-------------- next part --------------
Index: include/Makefile
===================================================================
--- include/Makefile	(revision 254281)
+++ include/Makefile	(working copy)
@@ -108,6 +108,7 @@ osreldate.h: ${.CURDIR}/../sys/conf/newvers.sh ${.
     ${.CURDIR}/Makefile
 	@${ECHO} creating osreldate.h from newvers.sh
 	@MAKE=${MAKE}; \
+	SYSDIR=${.CURDIR}/../sys; \
 	PARAMFILE=${.CURDIR}/../sys/sys/param.h; \
 	. ${.CURDIR}/../sys/conf/newvers.sh; \
 	echo "$$COPYRIGHT" > osreldate.h; \
Index: sys/conf/newvers.sh
===================================================================
--- sys/conf/newvers.sh	(revision 254281)
+++ sys/conf/newvers.sh	(working copy)
@@ -38,8 +38,11 @@ if [ "X${BRANCH_OVERRIDE}" != "X" ]; then
 fi
 RELEASE="${REVISION}-${BRANCH}"
 VERSION="${TYPE} ${RELEASE}"
-SYSDIR=$(dirname $0)/..
 
+if [ "X${SYSDIR}" = "X" ] ;then
+	SYSDIR=$(dirname $0)/..
+fi
+
 if [ "X${PARAMFILE}" != "X" ]; then
 	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
 		${PARAMFILE})
@@ -96,7 +99,7 @@ for dir in /usr/bin /usr/local/bin; do
 		# Run svnversion from ${dir} on this script; if return code
 		# is not zero, the checkout might not be compatible with the
 		# svnversion being used.
-		${dir}/svnversion $(realpath ${0}) >/dev/null 2>&1
+		${dir}/svnversion ${SYSDIR}/Makefile >/dev/null 2>&1
 		if [ $? -eq 0 ]; then
 			svnversion=${dir}/svnversion
 			break
@@ -105,7 +108,7 @@ for dir in /usr/bin /usr/local/bin; do
 done
 
 if [ -z "${svnversion}" ] && [ -x /usr/bin/svnliteversion ] ; then
-	/usr/bin/svnliteversion $(realpath ${0}) >/dev/null 2>&1
+	/usr/bin/svnliteversion ${SYSDIR}/Makefile >/dev/null 2>&1
 	if [ $? -eq 0 ]; then
 		svnversion=/usr/bin/svnliteversion
 	else


More information about the svn-src-all mailing list