diff mbox series

doc: Mention `if [[ somecondition ]]` is not supported

Message ID 20250320003358.977774-1-javier.tia@linaro.org
State Not Applicable
Headers show
Series doc: Mention `if [[ somecondition ]]` is not supported | expand

Commit Message

Javier Tia March 20, 2025, 12:33 a.m. UTC
I keep forgetting using `if [[ somecondition ]]` is not supported.

Signed-off-by: Javier Tia <javier.tia@linaro.org>
---
 doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Quentin Schulz March 25, 2025, 10:04 a.m. UTC | #1
On 3/20/25 1:33 AM, Javier Tia via lists.openembedded.org wrote:
> I keep forgetting using `if [[ somecondition ]]` is not supported.
> 
> Signed-off-by: Javier Tia <javier.tia@linaro.org>
> ---
>   doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> index 415fbf6d6..5474e154f 100644
> --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> @@ -1381,6 +1381,10 @@ To make use of this technique, you need the following things in place:
>      To call your modified version of the function as defined in your recipe,
>      call it as ``do_foo``.
>   
> +   .. note::
> +
> +      Conditional expression using ``[[ somecondition ]]`` is not supported.
> +

Do you know what the reason is for that limitation?

The example above this git context is not really implying `[[ 
somecondition ]]` would be valid though.

If I remember correctly, the shell functions are run by /bin/sh 
interpreter, so it depends on which shell you have configured by default 
in your system. Is it possible this is due to you being used to develop 
with bash where this is possible and having your Yocto build run with a 
different shell (e.g. dash, which doesn't seem to support that? c.f. 
https://manned.org/dash.1)?

I think we should recommend people write POSIX-compliant shell functions 
and tasks rather no?

Cheers,
Quentin
Richard Purdie March 25, 2025, 10:14 a.m. UTC | #2
On Tue, 2025-03-25 at 11:04 +0100, Quentin Schulz via lists.yoctoproject.org wrote:
> 
> 
> On 3/20/25 1:33 AM, Javier Tia via lists.openembedded.org wrote:
> > I keep forgetting using `if [[ somecondition ]]` is not supported.
> > 
> > Signed-off-by: Javier Tia <javier.tia@linaro.org>
> > ---
> >   doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> > index 415fbf6d6..5474e154f 100644
> > --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> > +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> > @@ -1381,6 +1381,10 @@ To make use of this technique, you need the following things in place:
> >      To call your modified version of the function as defined in your recipe,
> >      call it as ``do_foo``.
> >   
> > +   .. note::
> > +
> > +      Conditional expression using ``[[ somecondition ]]`` is not supported.
> > +
> 
> Do you know what the reason is for that limitation?
> 
> The example above this git context is not really implying `[[ 
> somecondition ]]` would be valid though.
> 
> If I remember correctly, the shell functions are run by /bin/sh 
> interpreter, so it depends on which shell you have configured by default 
> in your system. Is it possible this is due to you being used to develop 
> with bash where this is possible and having your Yocto build run with a 
> different shell (e.g. dash, which doesn't seem to support that? c.f. 
> https://manned.org/dash.1)?
> 
> I think we should recommend people write POSIX-compliant shell functions 
> and tasks rather no?

Bitbake parses the shell functions and our shell parser can't cope with
certain syntax unfortunately.

Cheers,

Richard
Quentin Schulz March 25, 2025, 5:30 p.m. UTC | #3
Hi Richard,

On 3/25/25 11:14 AM, Richard Purdie wrote:
> On Tue, 2025-03-25 at 11:04 +0100, Quentin Schulz via lists.yoctoproject.org wrote:
>>
>>
>> On 3/20/25 1:33 AM, Javier Tia via lists.openembedded.org wrote:
>>> I keep forgetting using `if [[ somecondition ]]` is not supported.
>>>
>>> Signed-off-by: Javier Tia <javier.tia@linaro.org>
>>> ---
>>>    doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 ++++
>>>    1 file changed, 4 insertions(+)
>>>
>>> diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
>>> index 415fbf6d6..5474e154f 100644
>>> --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
>>> +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
>>> @@ -1381,6 +1381,10 @@ To make use of this technique, you need the following things in place:
>>>       To call your modified version of the function as defined in your recipe,
>>>       call it as ``do_foo``.
>>>    
>>> +   .. note::
>>> +
>>> +      Conditional expression using ``[[ somecondition ]]`` is not supported.
>>> +
>>
>> Do you know what the reason is for that limitation?
>>
>> The example above this git context is not really implying `[[
>> somecondition ]]` would be valid though.
>>
>> If I remember correctly, the shell functions are run by /bin/sh
>> interpreter, so it depends on which shell you have configured by default
>> in your system. Is it possible this is due to you being used to develop
>> with bash where this is possible and having your Yocto build run with a
>> different shell (e.g. dash, which doesn't seem to support that? c.f.
>> https://manned.org/dash.1)?
>>
>> I think we should recommend people write POSIX-compliant shell functions
>> and tasks rather no?
> 
> Bitbake parses the shell functions and our shell parser can't cope with
> certain syntax unfortunately.
> 

Ah, I see. This happens before the shell even runs the code. Do we 
happen to have a list of things/syntax we cannot parse?

I think it therefore deserves a bigger place than a small note, maybe 
e.g. a sub(sub...)section of limitations?

Cheers,
Quentin
Richard Purdie March 25, 2025, 5:49 p.m. UTC | #4
On Tue, 2025-03-25 at 18:30 +0100, Quentin Schulz wrote:
> Hi Richard,
> 
> On 3/25/25 11:14 AM, Richard Purdie wrote:
> > On Tue, 2025-03-25 at 11:04 +0100, Quentin Schulz via lists.yoctoproject.org wrote:
> > > 
> > > 
> > > On 3/20/25 1:33 AM, Javier Tia via lists.openembedded.org wrote:
> > > > I keep forgetting using `if [[ somecondition ]]` is not supported.
> > > > 
> > > > Signed-off-by: Javier Tia <javier.tia@linaro.org>
> > > > ---
> > > >    doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 ++++
> > > >    1 file changed, 4 insertions(+)
> > > > 
> > > > diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> > > > index 415fbf6d6..5474e154f 100644
> > > > --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> > > > +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> > > > @@ -1381,6 +1381,10 @@ To make use of this technique, you need the following things in place:
> > > >       To call your modified version of the function as defined in your recipe,
> > > >       call it as ``do_foo``.
> > > >    
> > > > +   .. note::
> > > > +
> > > > +      Conditional expression using ``[[ somecondition ]]`` is not supported.
> > > > +
> > > 
> > > Do you know what the reason is for that limitation?
> > > 
> > > The example above this git context is not really implying `[[
> > > somecondition ]]` would be valid though.
> > > 
> > > If I remember correctly, the shell functions are run by /bin/sh
> > > interpreter, so it depends on which shell you have configured by default
> > > in your system. Is it possible this is due to you being used to develop
> > > with bash where this is possible and having your Yocto build run with a
> > > different shell (e.g. dash, which doesn't seem to support that? c.f.
> > > https://manned.org/dash.1)?
> > > 
> > > I think we should recommend people write POSIX-compliant shell functions
> > > and tasks rather no?
> > 
> > Bitbake parses the shell functions and our shell parser can't cope with
> > certain syntax unfortunately.
> > 
> 
> Ah, I see. This happens before the shell even runs the code. Do we 
> happen to have a list of things/syntax we cannot parse?

There are open bugs. I did recently run into backgrounding not working
in the pseudo reproducer so I just used a separate script. Not sure we
want to support background processes though.

> I think it therefore deserves a bigger place than a small note, maybe
> e.g. a sub(sub...)section of limitations?

Patches welcome!

Cheers,

Richard
Antonin Godard March 27, 2025, 1:44 p.m. UTC | #5
Hi Javier,

On Thu Mar 20, 2025 at 1:33 AM CET, Javier Tia wrote:
> I keep forgetting using `if [[ somecondition ]]` is not supported.
>
> Signed-off-by: Javier Tia <javier.tia@linaro.org>
> ---
>  doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> index 415fbf6d6..5474e154f 100644
> --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> @@ -1381,6 +1381,10 @@ To make use of this technique, you need the following things in place:
>     To call your modified version of the function as defined in your recipe,
>     call it as ``do_foo``.
>  
> +   .. note::
> +
> +      Conditional expression using ``[[ somecondition ]]`` is not supported.
> +
>  With these conditions met, your single recipe can freely choose between
>  the original function as defined in the class file and the modified
>  function in your recipe. If you do not set up these conditions, you are

The documentation already says the following:

  The scripts are executed by ``/bin/sh``, which may not be a bash
  shell but might be something such as ``dash``. You should not use
  Bash-specific script (bashisms).

I think [[ ]] is a bashism, or at least the POSIX shell spec clearly state to
not use it[1]. I'm not sure the BitBake documentation should list all the shell
syntax it does not support, as I expect there are quite a few.

The codeparser, however, could be modified to try and detect the usage of [[ ]]
and give a warning on such occurrences?

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_04

Antonin
diff mbox series

Patch

diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
index 415fbf6d6..5474e154f 100644
--- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
+++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
@@ -1381,6 +1381,10 @@  To make use of this technique, you need the following things in place:
    To call your modified version of the function as defined in your recipe,
    call it as ``do_foo``.
 
+   .. note::
+
+      Conditional expression using ``[[ somecondition ]]`` is not supported.
+
 With these conditions met, your single recipe can freely choose between
 the original function as defined in the class file and the modified
 function in your recipe. If you do not set up these conditions, you are