diff options
| author | Paulo Neves <ptsneves@gmail.com> | 2022-06-14 17:11:04 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-07-01 12:37:52 +0100 |
| commit | eb997a68010c55d0aeacd6b5f0d026461ae716a2 (patch) | |
| tree | 348126b70190862ed4729a100ff58319a50ca5c2 /meta | |
| parent | 00458ee0f8c0619707b53b7a72450fbd8cbc3e02 (diff) | |
| download | poky-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>
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/classes/utils.bbclass | 34 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/wrapper.py | 11 |
2 files changed, 45 insertions, 0 deletions
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 | ||
| 187 | create_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 | ||
| 214 | realpath=\`readlink -fn \$0\` | ||
| 215 | realdir=\`dirname \$realpath\` | ||
| 216 | exec -a \$realdir/$cmdname $argument \$realdir/$cmdname.real $cmdoptions "\$@" | ||
| 217 | END | ||
| 218 | chmod +x $cmd | ||
| 219 | } | ||
| 220 | |||
| 187 | create_wrapper () { | 221 | create_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 @@ | |||
| 1 | from oeqa.selftest.case import OESelftestTestCase | ||
| 2 | from oeqa.utils.commands import bitbake | ||
| 3 | |||
| 4 | class 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) | ||
