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/classes/utils.bbclass | |
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/classes/utils.bbclass')
-rw-r--r-- | meta/classes/utils.bbclass | 34 |
1 files changed, 34 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 | # |