From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F974C433EF for ; Tue, 14 Jun 2022 13:40:15 +0000 (UTC) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mx.groups.io with SMTP id smtpd.web09.6182.1655214005281192641 for ; Tue, 14 Jun 2022 06:40:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oRKA8Pst; spf=pass (domain: gmail.com, ip: 209.85.128.52, mailfrom: martin.jansa@gmail.com) Received: by mail-wm1-f52.google.com with SMTP id x6-20020a1c7c06000000b003972dfca96cso4819258wmc.4 for ; Tue, 14 Jun 2022 06:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SObAKJDQMEy3Ni3dUi2O1DOJf6kozok8UyF7v/1pXPE=; b=oRKA8PstgsMmKTjX9jjn91CozlkDiX16vtDIH2pYWwVbF6q+qXhjtbJLB4W8hmrN9q VIQHDpvMpRG2/VdNx3ozD1kM1XiK/U6WXkSVlZ16I+Upw+fL92nLQf2V/Px5V5OP3H6Q lbFoyG9coB4OoGYqX2zgHOW3+FXbUwHWTM4+gf3fXHWEen6jucqmCXQkF+fqg9ITEQeW L6aBmhje2+Nz7wn+1fH9CTe/S893eR8iArf4S1IV1ub62tLKXjn0URAaK7RhjQtfoMAd hpPsL8fRHwMSPOk1JCRbkIB9l4uBbYQqe4d/7J6xsk2U3IK3eM1sbvTpnTc1AL3bwJnT n7xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SObAKJDQMEy3Ni3dUi2O1DOJf6kozok8UyF7v/1pXPE=; b=rW3DCTk0y6nbNI5F/78ASlTIPYDTf6yglydSuArdyrolrr+9UpDqI0owz3W9rZ+b7t XjzqXyzBGcyQyyUCWTBibiKVZKsa5/tF4WVdr2KevGfTgDITIdpuQM1SYw3ayguPjC0C ymfSwIBuEByfLFJShhsrvyzJt0ORK0A9sX/LrAADl9GZOkxZYL4ZEJsG5it1wdMN4vGu 0CgTXJ9xQr1QnTIO/y+Q7kyzLlyf504q7Eyb2hT17TXnh22ATGZ1jPn1mkuLOoPoGyRs S7d3pyunJFJBUKhb1NEejguX04lbdbfi4VCfXtVgXa8DwwWZirRuQy2RY0ljejhKfTHG Zngw== X-Gm-Message-State: AOAM532jDHY5/SiE0huAATmyEX4cyYMBe3JZYrwrqDfjjzri6oBuAE55 jbXbjCWHeCHlCXHVrM+0AFGi6PLhsDpB/MWTS6Y= X-Google-Smtp-Source: ABdhPJyFa+hxKZgI6SBVwBc0x1OKATRjIvh9Q6eWHZbcnAoRXLOWFf/utKfWrLkwL/soQpmkt8t7U3yNGfFTkhRUHPg= X-Received: by 2002:a7b:c057:0:b0:39c:4579:42e1 with SMTP id u23-20020a7bc057000000b0039c457942e1mr4286563wmc.102.1655214003719; Tue, 14 Jun 2022 06:40:03 -0700 (PDT) MIME-Version: 1.0 References: <20220606155807.1414519-1-ptsneves@gmail.com> <20220614131652.566471-1-ptsneves@gmail.com> <20220614131652.566471-6-ptsneves@gmail.com> In-Reply-To: <20220614131652.566471-6-ptsneves@gmail.com> From: Martin Jansa Date: Tue, 14 Jun 2022 15:39:47 +0200 Message-ID: Subject: Re: [OE-core] [PATCH v4 6/7] utils: Add cmdline_shebang_wrapper util. To: Paulo Neves Cc: openembedded-core@lists.openembedded.org Content-Type: multipart/alternative; boundary="000000000000b811bb05e1688a44" List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 14 Jun 2022 13:40:15 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/166889 --000000000000b811bb05e1688a44 Content-Type: text/plain; charset="UTF-8" FILESEXTRAPATHS:prepend doesn't seem to be needed and LICENSE is really CLOSED? On Tue, Jun 14, 2022 at 3:17 PM Paulo Neves 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 > + > + 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 > # > 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 > + """ > + 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] > -=-=-=-=-=-=-=-=-=-=-=- > > --000000000000b811bb05e1688a44 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
FILESEXTRAPATHS:prepend doesn't seem to be needed and = LICENSE is really CLOSED?

On Tue, Jun 14, 2022 at 3:17 PM Paulo Neves &= lt;ptsneves@gmail.com> wrote:<= br>
Useful to work a= round shebang relocation issues, where
shebangs are too long or have arguments in them, thus preventing them
from using the /usr/bin/env shebang.
---
=C2=A0.../wrapper/cmdline-shebang-wrapper-test.bb=C2=A0 = =C2=A0| 21 ++++++++++++
=C2=A0.../recipes-test/wrapper/files/test.awk=C2=A0 =C2=A0 =C2=A0 =C2=A0|= =C2=A0 2 ++
=C2=A0meta/classes/utils.bbclass=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 34 +++++++++++++++++++
=C2=A0meta/lib/oeqa/selftest/cases/wrapper.py=C2=A0 =C2=A0 =C2=A0 =C2=A0| 1= 1 ++++++
=C2=A04 files changed, 68 insertions(+)
=C2=A0create mode 100644 meta-selftest/recipes-test/wrapper/cm= dline-shebang-wrapper-test.bb
=C2=A0create mode 100644 meta-selftest/recipes-test/wrapper/files/test.awk<= br> =C2=A0create mode 100644 meta/lib/oeqa/selftest/cases/wrapper.py

diff --git a/meta-selftest/recipes-test/wrapper/cmdline-sheban= g-wrapper-test.bb b/meta-selftest/recipes-test/wrapper/cmd= line-shebang-wrapper-test.bb
new file mode 100644
index 0000000000..302eea8901
--- /dev/null
+++ b/meta-selftest/recipes-test/wrapper/cmdline-shebang-wrapp= er-test.bb
@@ -0,0 +1,21 @@
+FILESEXTRAPATHS:prepend :=3D "${THISDIR}/files:"
+SUMMARY =3D "Check that create_cmdline_shebang works"
+LICENSE =3D "CLOSED"
+INHIBIT_DEFAULT_DEPS =3D "1"
+
+SRC_URI +=3D "file://test.awk"
+
+EXCLUDE_FROM_WORLD =3D "1"
+do_install() {
+=C2=A0 =C2=A0 install -d ${D}${bindir}
+=C2=A0 =C2=A0 install -m 0755 ${WORKDIR}/test.awk ${D}${bindir}/test
+=C2=A0 =C2=A0 sed -i -e 's|@AWK_BIN@|${bindir}/awk|g' ${D}${bindir= }/test
+=C2=A0 =C2=A0 create_cmdline_shebang_wrapper ${D}${bindir}/test
+=C2=A0 =C2=A0 if [ $(${D}${bindir}/test) !=3D "Don't Panic!"= ]; then
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 bbfatal "Wrapper is broken"
+=C2=A0 =C2=A0 else
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 bbnote "Wrapper is good"
+=C2=A0 =C2=A0 fi
+}
+
+BBCLASSEXTEND =3D "native"
diff --git a/meta-selftest/recipes-test/wrapper/files/test.awk b/meta-selft= est/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
=C2=A0 =C2=A0 =C2=A0 =C2=A0 chmod +x $cmd
=C2=A0}

+create_cmdline_shebang_wrapper () {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0# Create a wrapper script where commandline opt= ions are needed
+=C2=A0 =C2=A0 =C2=A0 =C2=A0#
+=C2=A0 =C2=A0 =C2=A0 =C2=A0# These are useful to work around shebang reloc= ation issues, where shebangs are too
+=C2=A0 # long or have arguments in them, thus preventing them from using t= he /usr/bin/env
+=C2=A0 =C2=A0 =C2=A0 =C2=A0# shebang
+=C2=A0 =C2=A0 =C2=A0 =C2=A0#
+=C2=A0 =C2=A0 =C2=A0 =C2=A0# Usage: create_cmdline_wrapper FILENAME <ex= tra-options>
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0cmd=3D$1
+=C2=A0 =C2=A0 =C2=A0 =C2=A0shift
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0echo "Generating wrapper script for $cmd&q= uot;
+
+=C2=A0 # Strip #! and get remaining interpreter + arg
+=C2=A0 argument=3D"$(basename "$(head -n1 $cmd | sed -e 's|#= ![ ]*||g' )")"
+=C2=A0 # strip the shebang from the real script as we do not want it to be= usable anyway
+=C2=A0 tail -n +2 $cmd > $cmd.real
+=C2=A0 =C2=A0 =C2=A0 =C2=A0cmdname=3D$(basename $cmd)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0dirname=3D$(dirname $cmd)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0cmdoptions=3D$@
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if [ "${base_prefix}" !=3D "&quo= t; ]; then
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0relpath=3D`python3 = -c "import os; print(os.path.relpath('${D}${base_prefix}', = 9;$dirname'))"`
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cmdoptions=3D`echo = $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
+=C2=A0 =C2=A0 =C2=A0 =C2=A0fi
+=C2=A0 =C2=A0 =C2=A0 =C2=A0cat <<END >$cmd
+#!/usr/bin/env bash
+realpath=3D\`readlink -fn \$0\`
+realdir=3D\`dirname \$realpath\`
+exec -a \$realdir/$cmdname $argument \$realdir/$cmdname.real $cmdoptions &= quot;\$@"
+END
+=C2=A0 =C2=A0 =C2=A0 =C2=A0chmod +x $cmd
+}
+
=C2=A0create_wrapper () {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Create a wrapper script where extra environme= nt variables are needed
=C2=A0 =C2=A0 =C2=A0 =C2=A0 #
diff --git a/meta/lib/oeqa/selftest/cases/wrapper.py b/meta/lib/oeqa/selfte= st/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):
+=C2=A0 =C2=A0 def test_shebang_wrapper(self):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Summary:=C2=A0 =C2=A0Build a recipe which will= fail if the cmdline_shebang_wrapper function is defective.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Expected:=C2=A0 Exit status to be 0.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Author:=C2=A0 =C2=A0 Paulo Neves <ptsneves@gmail.com>=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 res =3D bitbake("cmdline-shebang-wrapper-= test -c install", ignore_status=3DFalse)
--
2.25.1


-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
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<= br> Unsubscribe: https://lists.openembedded.org/= g/openembedded-core/unsub [Martin.Jansa@gmail.com]
-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-

--000000000000b811bb05e1688a44--