From eb997a68010c55d0aeacd6b5f0d026461ae716a2 Mon Sep 17 00:00:00 2001 From: Paulo Neves Date: Tue, 14 Jun 2022 17:11:04 +0200 Subject: utils: Add cmdline_shebang_wrapper util. Useful to work around shebang relocation issues, where shebangs are too long or have arguments in them, thus preventing them from using the /usr/bin/env shebang. (From OE-Core rev: 6edc1fffcbe1405d8c309a75643d7d6cd9a92848) Signed-off-by: Paulo Neves Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- meta/classes/utils.bbclass | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'meta/classes/utils.bbclass') diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass index b4eb3d38ab..b617632d9f 100644 --- a/meta/classes/utils.bbclass +++ b/meta/classes/utils.bbclass @@ -184,6 +184,40 @@ END chmod +x $cmd } +create_cmdline_shebang_wrapper () { + # Create a wrapper script where commandline options are needed + # + # These are useful to work around shebang relocation issues, where shebangs are too + # long or have arguments in them, thus preventing them from using the /usr/bin/env + # shebang + # + # Usage: create_cmdline_wrapper FILENAME + + cmd=$1 + shift + + echo "Generating wrapper script for $cmd" + + # Strip #! and get remaining interpreter + arg + argument="$(basename "$(head -n1 $cmd | sed -e 's|#![ ]*||g' )")" + # strip the shebang from the real script as we do not want it to be usable anyway + tail -n +2 $cmd > $cmd.real + cmdname=$(basename $cmd) + dirname=$(dirname $cmd) + cmdoptions=$@ + if [ "${base_prefix}" != "" ]; then + relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"` + cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"` + fi + cat <$cmd +#!/usr/bin/env bash +realpath=\`readlink -fn \$0\` +realdir=\`dirname \$realpath\` +exec -a \$realdir/$cmdname $argument \$realdir/$cmdname.real $cmdoptions "\$@" +END + chmod +x $cmd +} + create_wrapper () { # Create a wrapper script where extra environment variables are needed # -- cgit v1.2.3-54-g00ecf