Patchwork utils.bbclass: ensure $0 is correct in wrapper scripts

login
register
mail settings
Submitter Ross Burton
Date May 30, 2013, 4:55 p.m.
Message ID <1369932910-5557-1-git-send-email-ross.burton@intel.com>
Download mbox | patch
Permalink /patch/50881/
State Accepted
Commit 3aaa4f78c609a47324da2db3b5c92a28f4f2ccff
Headers show

Comments

Ross Burton - May 30, 2013, 4:55 p.m.
Some packages (eg mesa) will invoke a tool with --version and do string matches
on the output (i.e. mesa does $LEX --version |grep "^flex ").  This doesn't work
with the combination of wrapper scripts and binaries that use $0 as they output
"flex.real".

Luckily bash's exec lets you set $0.  As we want to use this we can't use env,
but using export appears to work just as well.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/classes/utils.bbclass |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
index be0a25a..cf8893f 100644
--- a/meta/classes/utils.bbclass
+++ b/meta/classes/utils.bbclass
@@ -261,9 +261,9 @@  create_cmdline_wrapper () {
 	mv $cmd $cmd.real
 	cmdname=`basename $cmd`.real
 	cat <<END >$cmd
-#!/bin/sh
+#!/bin/bash
 realpath=\`readlink -fn \$0\`
-exec \`dirname \$realpath\`/$cmdname $@ "\$@"
+exec -a $cmd \`dirname \$realpath\`/$cmdname $@ "\$@"
 END
 	chmod +x $cmd
 }
@@ -284,9 +284,10 @@  create_wrapper () {
 	mv $cmd $cmd.real
 	cmdname=`basename $cmd`.real
 	cat <<END >$cmd
-#!/bin/sh
+#!/bin/bash
 realpath=\`readlink -fn \$0\`
-exec env $@ \`dirname \$realpath\`/$cmdname "\$@"
+export $@
+exec -a $cmd \`dirname \$realpath\`/$cmdname "\$@"
 END
 	chmod +x $cmd
 }