Date: Tue, 13 Aug 2013 14:09:56 -0600 From: Ian Lepore <ian@FreeBSD.org> To: Glen Barber <gjb@FreeBSD.org> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r254217 - head/sys/conf Message-ID: <1376424596.3320.242.camel@revolution.hippie.lan> In-Reply-To: <20130813175335.GR2432@glenbarber.us> References: <201308111357.r7BDvF7H065442@svn.freebsd.org> <1376407389.3320.209.camel@revolution.hippie.lan> <20130813153222.GL2432@glenbarber.us> <1376413337.3320.224.camel@revolution.hippie.lan> <20130813171302.GQ2432@glenbarber.us> <1376415112.3320.229.camel@revolution.hippie.lan> <20130813175335.GR2432@glenbarber.us>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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@nucleus:~ % cat foo1.sh foo2.sh
> #!/bin/sh
> echo ${0}
> . foo2.sh
> #!/bin/sh
> echo ${0}
> gjb@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
[-- Attachment #2 --]
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1376424596.3320.242.camel>
