[Libguestfs] [PATCH] ./run: Use 'prepend' function to build paths.
Richard W.M. Jones
rjones at redhat.com
Fri Feb 13 10:42:07 UTC 2015
On Fri, Feb 13, 2015 at 11:35:15AM +0100, Pino Toscano wrote:
> On Friday 13 February 2015 10:16:34 Richard W.M. Jones wrote:
> > Add a bash function 'prepend' for intelligently prepending elements to
> > paths. eg:
> >
> > prepend PYTHONPATH "/foo"
> >
> > would set PYTHONPATH to "/foo" or "/foo:<previous-contents-of-PYTHONPATH>"
> >
> > Tested by:
> >
> > (1) Building and testing libguestfs twice: first without libguestfs
> > installed as a system library, and then with it installed.
> >
> > (2) Examining the output of './run printenv' by hand and comparing
> > environment variables to the expected values.
> > ---
>
> Nice idea, thanks for it.
>
> > # Set LD_LIBRARY_PATH and DYLD_LIBRARY_PATH to contain library.
> > -build_libs_path="$b/src/.libs:$b/java/.libs:$b/gobject/.libs"
> > -export LD_LIBRARY_PATH="$build_libs_path${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
> > -export DYLD_LIBRARY_PATH="$build_libs_path${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH"
> > +prepend LD_LIBRARY_PATH "$b/gobject/.libs"
> > +prepend LD_LIBRARY_PATH "$b/java/.libs"
> > +prepend LD_LIBRARY_PATH "$b/src/.libs"
> > +prepend DYLD_LIBRARY_PATH "$b/gobject/.libs"
> > +prepend DYLD_LIBRARY_PATH "$b/java/.libs"
> > +prepend DYLD_LIBRARY_PATH "$b/src/.libs"
> > +export LD_LIBRARY_PATH
> > +export DYLD_LIBRARY_PATH
>
> I'd still leave the build_libs_path variable, so we don't duplicate
> its content twice.
I considered that, but think this way is clearer, even if there's some
minimal duplication.
> > # virt-p2v-make-* data directory.
> > if [ -z "$VIRT_P2V_DATA_DIR" ]; then
> > - VIRT_P2V_DATA_DIR="$b/p2v"
> > + prepend VIRT_P2V_DATA_DIR "$b/p2v"
> > export VIRT_P2V_DATA_DIR
> > fi
>
> Is prepend needed here? After all, it is just a single directory.
No it's not -- I removed this hunk.
> > # For Lua.
> > export LUA=@LUA@
> > +# Can't use 'prepend' here because Lua paths use semicolons.
> > if [ -z "$LUA_CPATH" ]; then
> > LUA_CPATH="$b/lua/?.so"
> > else
>
> I guess using a second helper like:
>
> prepend_semicolon()
> {
> eval $1="$2\${$1:+;\$$1}"
> }
>
> could help?
Actually what's needed is a more general function which could use a
generic separator and also handle appending, thus coping with:
if [ -z "$CGO_CFLAGS" ]; then
CGO_CFLAGS="-I$s/src"
else
CGO_CFLAGS="$CGO_CFLAGS -I$s/src"
fi
Anyway, I have pushed this for now, without the P2V data dir hunk.
Thanks,
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
More information about the Libguestfs
mailing list