summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Neves <ptsneves@gmail.com>2022-06-14 17:11:04 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-07-01 12:37:52 +0100
commiteb997a68010c55d0aeacd6b5f0d026461ae716a2 (patch)
tree348126b70190862ed4729a100ff58319a50ca5c2
parent00458ee0f8c0619707b53b7a72450fbd8cbc3e02 (diff)
downloadpoky-eb997a68010c55d0aeacd6b5f0d026461ae716a2.tar.gz
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 <ptsneves@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb21
-rw-r--r--meta-selftest/recipes-test/wrapper/files/test.awk2
-rw-r--r--meta/classes/utils.bbclass34
-rw-r--r--meta/lib/oeqa/selftest/cases/wrapper.py11
4 files changed, 68 insertions, 0 deletions
diff --git a/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
new file mode 100644
index 0000000000..c4126a41fc
--- /dev/null
+++ b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
@@ -0,0 +1,21 @@
1SUMMARY = "Check that create_cmdline_shebang works"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4INHIBIT_DEFAULT_DEPS = "1"
5
6SRC_URI += "file://test.awk"
7
8EXCLUDE_FROM_WORLD = "1"
9do_install() {
10 install -d ${D}${bindir}
11 install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test
12 sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir}/test
13 create_cmdline_shebang_wrapper ${D}${bindir}/test
14 if [ $(${D}${bindir}/test) != "Don't Panic!" ]; then
15 bbfatal "Wrapper is broken"
16 else
17 bbnote "Wrapper is good"
18 fi
19}
20
21BBCLASSEXTEND = "native"
diff --git a/meta-selftest/recipes-test/wrapper/files/test.awk b/meta-selftest/recipes-test/wrapper/files/test.awk
new file mode 100644
index 0000000000..91429197b1
--- /dev/null
+++ b/meta-selftest/recipes-test/wrapper/files/test.awk
@@ -0,0 +1,2 @@
1#! @AWK_BIN@ -f
2BEGIN { print "Don't Panic!" }
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
184 chmod +x $cmd 184 chmod +x $cmd
185} 185}
186 186
187create_cmdline_shebang_wrapper () {
188 # Create a wrapper script where commandline options are needed
189 #
190 # These are useful to work around shebang relocation issues, where shebangs are too
191 # long or have arguments in them, thus preventing them from using the /usr/bin/env
192 # shebang
193 #
194 # Usage: create_cmdline_wrapper FILENAME <extra-options>
195
196 cmd=$1
197 shift
198
199 echo "Generating wrapper script for $cmd"
200
201 # Strip #! and get remaining interpreter + arg
202 argument="$(basename "$(head -n1 $cmd | sed -e 's|#![ ]*||g' )")"
203 # strip the shebang from the real script as we do not want it to be usable anyway
204 tail -n +2 $cmd > $cmd.real
205 cmdname=$(basename $cmd)
206 dirname=$(dirname $cmd)
207 cmdoptions=$@
208 if [ "${base_prefix}" != "" ]; then
209 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
210 cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
211 fi
212 cat <<END >$cmd
213#!/usr/bin/env bash
214realpath=\`readlink -fn \$0\`
215realdir=\`dirname \$realpath\`
216exec -a \$realdir/$cmdname $argument \$realdir/$cmdname.real $cmdoptions "\$@"
217END
218 chmod +x $cmd
219}
220
187create_wrapper () { 221create_wrapper () {
188 # Create a wrapper script where extra environment variables are needed 222 # Create a wrapper script where extra environment variables are needed
189 # 223 #
diff --git a/meta/lib/oeqa/selftest/cases/wrapper.py b/meta/lib/oeqa/selftest/cases/wrapper.py
new file mode 100644
index 0000000000..6de63310c0
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/wrapper.py
@@ -0,0 +1,11 @@
1from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import bitbake
3
4class WrapperTests(OESelftestTestCase):
5 def test_shebang_wrapper(self):
6 """
7 Summary: Build a recipe which will fail if the cmdline_shebang_wrapper function is defective.
8 Expected: Exit status to be 0.
9 Author: Paulo Neves <ptsneves@gmail.com>
10 """
11 res = bitbake("cmdline-shebang-wrapper-test -c install", ignore_status=False)