| Message ID | 20220614131652.566471-6-ptsneves@gmail.com |
|---|---|
| State | Accepted, archived |
| Commit | 6edc1fffcbe1405d8c309a75643d7d6cd9a92848 |
| Headers | show |
| Series | [v4,1/7] python: Avoid shebang overflow on python-config.py | expand |
FILESEXTRAPATHS:prepend doesn't seem to be needed and LICENSE is really CLOSED? On Tue, Jun 14, 2022 at 3:17 PM Paulo Neves <ptsneves@gmail.com> wrote: > 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. > --- > .../wrapper/cmdline-shebang-wrapper-test.bb | 21 ++++++++++++ > .../recipes-test/wrapper/files/test.awk | 2 ++ > meta/classes/utils.bbclass | 34 +++++++++++++++++++ > meta/lib/oeqa/selftest/cases/wrapper.py | 11 ++++++ > 4 files changed, 68 insertions(+) > create mode 100644 meta-selftest/recipes-test/wrapper/ > cmdline-shebang-wrapper-test.bb > create mode 100644 meta-selftest/recipes-test/wrapper/files/test.awk > create mode 100644 meta/lib/oeqa/selftest/cases/wrapper.py > > 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..302eea8901 > --- /dev/null > +++ b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb > @@ -0,0 +1,21 @@ > +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" > +SUMMARY = "Check that create_cmdline_shebang works" > +LICENSE = "CLOSED" > +INHIBIT_DEFAULT_DEPS = "1" > + > +SRC_URI += "file://test.awk" > + > +EXCLUDE_FROM_WORLD = "1" > +do_install() { > + install -d ${D}${bindir} > + install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test > + sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir}/test > + create_cmdline_shebang_wrapper ${D}${bindir}/test > + if [ $(${D}${bindir}/test) != "Don't Panic!" ]; then > + bbfatal "Wrapper is broken" > + else > + bbnote "Wrapper is good" > + fi > +} > + > +BBCLASSEXTEND = "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 @@ > +#! @AWK_BIN@ -f > +BEGIN { 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 > 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 <extra-options> > + > + 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 <<END >$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 > # > 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 @@ > +from oeqa.selftest.case import OESelftestTestCase > +from oeqa.utils.commands import bitbake > + > +class WrapperTests(OESelftestTestCase): > + def test_shebang_wrapper(self): > + """ > + Summary: Build a recipe which will fail if the > cmdline_shebang_wrapper function is defective. > + Expected: Exit status to be 0. > + Author: Paulo Neves <ptsneves@gmail.com> > + """ > + res = bitbake("cmdline-shebang-wrapper-test -c install", > ignore_status=False) > -- > 2.25.1 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#166887): > https://lists.openembedded.org/g/openembedded-core/message/166887 > Mute This Topic: https://lists.openembedded.org/mt/91748692/3617156 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ > Martin.Jansa@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- > >
Regarding the FILESEXTRAPATHS:prepend i was convinced that
${THISDIR}/files was not automatically added and was needed for the
test.awk file. I guess I have been cargo culting for some time on this.
Will remove it.
This is a recipe for a test and if i add a license different than CLOSED
than i need to add a license file, which seems a bit overkill for a one
line. Am I wrong? What license should it even be? Dont Panic is a common
string used in awk docs.
Paulo Neves
On 6/14/22 15:39, Martin Jansa wrote:
> FILESEXTRAPATHS:prepend doesn't seem to be needed and LICENSE is
> really CLOSED?
>
> On Tue, Jun 14, 2022 at 3:17 PM Paulo Neves <ptsneves@gmail.com> wrote:
>
> 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.
> ---
> .../wrapper/cmdline-shebang-wrapper-test.bb
> <http://cmdline-shebang-wrapper-test.bb> | 21 ++++++++++++
> .../recipes-test/wrapper/files/test.awk | 2 ++
> meta/classes/utils.bbclass | 34
> +++++++++++++++++++
> meta/lib/oeqa/selftest/cases/wrapper.py | 11 ++++++
> 4 files changed, 68 insertions(+)
> create mode 100644
> meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
> <http://cmdline-shebang-wrapper-test.bb>
> create mode 100644 meta-selftest/recipes-test/wrapper/files/test.awk
> create mode 100644 meta/lib/oeqa/selftest/cases/wrapper.py
>
> diff --git
> a/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
> <http://cmdline-shebang-wrapper-test.bb>
> b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
> <http://cmdline-shebang-wrapper-test.bb>
> new file mode 100644
> index 0000000000..302eea8901
> --- /dev/null
> +++
> b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
> <http://cmdline-shebang-wrapper-test.bb>
> @@ -0,0 +1,21 @@
> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
> +SUMMARY = "Check that create_cmdline_shebang works"
> +LICENSE = "CLOSED"
> +INHIBIT_DEFAULT_DEPS = "1"
> +
> +SRC_URI += "file://test.awk"
> +
> +EXCLUDE_FROM_WORLD = "1"
> +do_install() {
> + install -d ${D}${bindir}
> + install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test
> + sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir}/test
> + create_cmdline_shebang_wrapper ${D}${bindir}/test
> + if [ $(${D}${bindir}/test) != "Don't Panic!" ]; then
> + bbfatal "Wrapper is broken"
> + else
> + bbnote "Wrapper is good"
> + fi
> +}
> +
> +BBCLASSEXTEND = "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 @@
> +#! @AWK_BIN@ -f
> +BEGIN { 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
> 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 <extra-options>
> +
> + 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 <<END >$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
> #
> 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 @@
> +from oeqa.selftest.case import OESelftestTestCase
> +from oeqa.utils.commands import bitbake
> +
> +class WrapperTests(OESelftestTestCase):
> + def test_shebang_wrapper(self):
> + """
> + Summary: Build a recipe which will fail if the
> cmdline_shebang_wrapper function is defective.
> + Expected: Exit status to be 0.
> + Author: Paulo Neves <ptsneves@gmail.com>
> + """
> + res = bitbake("cmdline-shebang-wrapper-test -c install",
> ignore_status=False)
> --
> 2.25.1
>
>
>
>
You can use bitbake-getvar to see the default FILESPATH, but "files" next
to recipe is included by default (I prefer to use BPN directory for
slightly faster lookup - unless the files are shared between different
recipes). FILESEXTRAPATHS is usually only needed from bbappends which add
new files to SRC_URI.
For LICENSE you can use MIT and
LIC_FILES_CHKSUM =
"file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
like many "pure-metadata" recipes in oe-core.
On Tue, Jun 14, 2022 at 3:46 PM Paulo Neves <ptsneves@gmail.com> wrote:
> Regarding the FILESEXTRAPATHS:prepend i was convinced that
> ${THISDIR}/files was not automatically added and was needed for the
> test.awk file. I guess I have been cargo culting for some time on this.
> Will remove it.
>
> This is a recipe for a test and if i add a license different than CLOSED
> than i need to add a license file, which seems a bit overkill for a one
> line. Am I wrong? What license should it even be? Dont Panic is a common
> string used in awk docs.
>
> Paulo Neves
>
> On 6/14/22 15:39, Martin Jansa wrote:
>
> FILESEXTRAPATHS:prepend doesn't seem to be needed and LICENSE is really
> CLOSED?
>
> On Tue, Jun 14, 2022 at 3:17 PM Paulo Neves <ptsneves@gmail.com> wrote:
>
>> 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.
>> ---
>> .../wrapper/cmdline-shebang-wrapper-test.bb | 21 ++++++++++++
>> .../recipes-test/wrapper/files/test.awk | 2 ++
>> meta/classes/utils.bbclass | 34 +++++++++++++++++++
>> meta/lib/oeqa/selftest/cases/wrapper.py | 11 ++++++
>> 4 files changed, 68 insertions(+)
>> create mode 100644 meta-selftest/recipes-test/wrapper/
>> cmdline-shebang-wrapper-test.bb
>> create mode 100644 meta-selftest/recipes-test/wrapper/files/test.awk
>> create mode 100644 meta/lib/oeqa/selftest/cases/wrapper.py
>>
>> 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..302eea8901
>> --- /dev/null
>> +++ b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb
>> @@ -0,0 +1,21 @@
>> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
>> +SUMMARY = "Check that create_cmdline_shebang works"
>> +LICENSE = "CLOSED"
>> +INHIBIT_DEFAULT_DEPS = "1"
>> +
>> +SRC_URI += "file://test.awk"
>> +
>> +EXCLUDE_FROM_WORLD = "1"
>> +do_install() {
>> + install -d ${D}${bindir}
>> + install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test
>> + sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir}/test
>> + create_cmdline_shebang_wrapper ${D}${bindir}/test
>> + if [ $(${D}${bindir}/test) != "Don't Panic!" ]; then
>> + bbfatal "Wrapper is broken"
>> + else
>> + bbnote "Wrapper is good"
>> + fi
>> +}
>> +
>> +BBCLASSEXTEND = "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 @@
>> +#! @AWK_BIN@ -f
>> +BEGIN { 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
>> 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 <extra-options>
>> +
>> + 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 <<END >$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
>> #
>> 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 @@
>> +from oeqa.selftest.case import OESelftestTestCase
>> +from oeqa.utils.commands import bitbake
>> +
>> +class WrapperTests(OESelftestTestCase):
>> + def test_shebang_wrapper(self):
>> + """
>> + Summary: Build a recipe which will fail if the
>> cmdline_shebang_wrapper function is defective.
>> + Expected: Exit status to be 0.
>> + Author: Paulo Neves <ptsneves@gmail.com>
>> + """
>> + res = bitbake("cmdline-shebang-wrapper-test -c install",
>> ignore_status=False)
>> --
>> 2.25.1
>>
>>
>> -=-=-=-=-=-=-=-=-=-=-=-
>> Links: You receive all messages sent to this group.
>> View/Reply Online (#166887):
>> https://lists.openembedded.org/g/openembedded-core/message/166887
>> Mute This Topic: https://lists.openembedded.org/mt/91748692/3617156
>> Group Owner: openembedded-core+owner@lists.openembedded.org
>> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
>> Martin.Jansa@gmail.com]
>> -=-=-=-=-=-=-=-=-=-=-=-
>>
>>
>
Thanks for the great tips. Yeah the habit of using the FILESPATH is that mostly I work on bbappends. Today i learned. I sent a new v5 with the corrections you mention. Paulo Neves On 6/14/22 16:17, Martin Jansa wrote: > You can use bitbake-getvar to see the default FILESPATH, but "files" > next to recipe is included by default (I prefer to use BPN directory > for slightly faster lookup - unless the files are shared between > different recipes). FILESEXTRAPATHS is usually only needed from > bbappends which add new files to SRC_URI. > > For LICENSE you can use MIT and > LIC_FILES_CHKSUM = > "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" > like many "pure-metadata" recipes in oe-core. > > On Tue, Jun 14, 2022 at 3:46 PM Paulo Neves <ptsneves@gmail.com> wrote: > > Regarding the FILESEXTRAPATHS:prepend i was convinced that > ${THISDIR}/files was not automatically added and was needed for > the test.awk file. I guess I have been cargo culting for some time > on this. Will remove it. > > This is a recipe for a test and if i add a license different than > CLOSED than i need to add a license file, which seems a bit > overkill for a one line. Am I wrong? What license should it even > be? Dont Panic is a common string used in awk docs. > > Paulo Neves > > On 6/14/22 15:39, Martin Jansa wrote: >> FILESEXTRAPATHS:prepend doesn't seem to be needed and LICENSE is >> really CLOSED? >> >> On Tue, Jun 14, 2022 at 3:17 PM Paulo Neves <ptsneves@gmail.com> >> wrote: >> >> 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. >> --- >> .../wrapper/cmdline-shebang-wrapper-test.bb >> <http://cmdline-shebang-wrapper-test.bb> | 21 ++++++++++++ >> .../recipes-test/wrapper/files/test.awk | 2 ++ >> meta/classes/utils.bbclass | 34 >> +++++++++++++++++++ >> meta/lib/oeqa/selftest/cases/wrapper.py | 11 ++++++ >> 4 files changed, 68 insertions(+) >> create mode 100644 >> meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb >> <http://cmdline-shebang-wrapper-test.bb> >> create mode 100644 >> meta-selftest/recipes-test/wrapper/files/test.awk >> create mode 100644 meta/lib/oeqa/selftest/cases/wrapper.py >> >> diff --git >> a/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb >> <http://cmdline-shebang-wrapper-test.bb> >> b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb >> <http://cmdline-shebang-wrapper-test.bb> >> new file mode 100644 >> index 0000000000..302eea8901 >> --- /dev/null >> +++ >> b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb >> <http://cmdline-shebang-wrapper-test.bb> >> @@ -0,0 +1,21 @@ >> +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" >> +SUMMARY = "Check that create_cmdline_shebang works" >> +LICENSE = "CLOSED" >> +INHIBIT_DEFAULT_DEPS = "1" >> + >> +SRC_URI += "file://test.awk" >> + >> +EXCLUDE_FROM_WORLD = "1" >> +do_install() { >> + install -d ${D}${bindir} >> + install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test >> + sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir}/test >> + create_cmdline_shebang_wrapper ${D}${bindir}/test >> + if [ $(${D}${bindir}/test) != "Don't Panic!" ]; then >> + bbfatal "Wrapper is broken" >> + else >> + bbnote "Wrapper is good" >> + fi >> +} >> + >> +BBCLASSEXTEND = "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 @@ >> +#! @AWK_BIN@ -f >> +BEGIN { 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 >> 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 <extra-options> >> + >> + 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 <<END >$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 >> # >> 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 @@ >> +from oeqa.selftest.case import OESelftestTestCase >> +from oeqa.utils.commands import bitbake >> + >> +class WrapperTests(OESelftestTestCase): >> + def test_shebang_wrapper(self): >> + """ >> + Summary: Build a recipe which will fail if the >> cmdline_shebang_wrapper function is defective. >> + Expected: Exit status to be 0. >> + Author: Paulo Neves <ptsneves@gmail.com> >> + """ >> + res = bitbake("cmdline-shebang-wrapper-test -c >> install", ignore_status=False) >> -- >> 2.25.1 >> >> >> >> >
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..302eea8901 --- /dev/null +++ b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapper-test.bb @@ -0,0 +1,21 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" +SUMMARY = "Check that create_cmdline_shebang works" +LICENSE = "CLOSED" +INHIBIT_DEFAULT_DEPS = "1" + +SRC_URI += "file://test.awk" + +EXCLUDE_FROM_WORLD = "1" +do_install() { + install -d ${D}${bindir} + install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test + sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir}/test + create_cmdline_shebang_wrapper ${D}${bindir}/test + if [ $(${D}${bindir}/test) != "Don't Panic!" ]; then + bbfatal "Wrapper is broken" + else + bbnote "Wrapper is good" + fi +} + +BBCLASSEXTEND = "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 @@ +#! @AWK_BIN@ -f +BEGIN { 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 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 <extra-options> + + 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 <<END >$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 # 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 @@ +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import bitbake + +class WrapperTests(OESelftestTestCase): + def test_shebang_wrapper(self): + """ + Summary: Build a recipe which will fail if the cmdline_shebang_wrapper function is defective. + Expected: Exit status to be 0. + Author: Paulo Neves <ptsneves@gmail.com> + """ + res = bitbake("cmdline-shebang-wrapper-test -c install", ignore_status=False)