diff mbox series

bitbake: ConfHandler: Allow variable flag name with a single character

Message ID 20230411060654.19442-1-kai.kang@windriver.com
State Accepted, archived
Commit bb9e523291a3cad6e1596ee6a1e715b5e5feba8f
Headers show
Series bitbake: ConfHandler: Allow variable flag name with a single character | expand

Commit Message

Kai April 11, 2023, 6:06 a.m. UTC
From: Kai Kang <kai.kang@windriver.com>

Update regex pattern to allow variable flag name with a single character.

Regression tests have also been updated in `bb.parse` and
`bin/bitbake-selftest -k ParseTest` has been successfully executed.

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 bitbake/lib/bb/parse/parse_py/ConfHandler.py | 2 +-
 bitbake/lib/bb/tests/parse.py                | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Ola x Nilsson April 11, 2023, 8:44 a.m. UTC | #1
On Tue, Apr 11 2023, Kai Kang wrote:

> From: Kai Kang <kai.kang@windriver.com>
>
> Update regex pattern to allow variable flag name with a single character.
>
> Regression tests have also been updated in `bb.parse` and
> `bin/bitbake-selftest -k ParseTest` has been successfully executed.
>
> Signed-off-by: Kai Kang <kai.kang@windriver.com>
> ---
>  bitbake/lib/bb/parse/parse_py/ConfHandler.py | 2 +-
>  bitbake/lib/bb/tests/parse.py                | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
> index 05c627ec8b..0bfe357012 100644
> --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
> +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
> @@ -21,7 +21,7 @@ __config_regexp__  = re.compile( r"""
>      ^
>      (?P<exp>export\s+)?
>      (?P<var>[a-zA-Z0-9\-_+.${}/~:]+?)
> -    (\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\])?
> +    (\[(?P<flag>[a-zA-Z0-9\-_+.]([a-zA-Z0-9\-_+.@]+)?)\])?

It would be better to use the simpler expression
(\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]*)\])?


/Ola


>      \s* (
>          (?P<colon>:=) |
> diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py
> index d27c7c6f15..a3165d95bd 100644
> --- a/bitbake/lib/bb/tests/parse.py
> +++ b/bitbake/lib/bb/tests/parse.py
> @@ -222,6 +222,7 @@ VAR = " \\
>      at_sign_in_var_flag = """
>  A[flag@.service] = "nonet"
>  B[flag@.target] = "ntb"
> +C[f] = "flag"
>  
>  unset A[flag@.service]
>  """
> @@ -232,6 +233,7 @@ unset A[flag@.service]
>          self.assertEqual(d.getVar("B"), None)
>          self.assertEqual(d.getVarFlag("A","flag@.service"), None)
>          self.assertEqual(d.getVarFlag("B","flag@.target"), "ntb")
> +        self.assertEqual(d.getVarFlag("C","f"), "flag")
>  
>      def test_parse_invalid_at_sign_in_var_flag(self):
>          invalid_at_sign = self.at_sign_in_var_flag.replace("B[f", "B[@f")
Kai April 11, 2023, 9 a.m. UTC | #2
On 4/11/23 16:44, Ola x Nilsson wrote:
> On Tue, Apr 11 2023, Kai Kang wrote:
>
>> From: Kai Kang <kai.kang@windriver.com>
>>
>> Update regex pattern to allow variable flag name with a single character.
>>
>> Regression tests have also been updated in `bb.parse` and
>> `bin/bitbake-selftest -k ParseTest` has been successfully executed.
>>
>> Signed-off-by: Kai Kang <kai.kang@windriver.com>
>> ---
>>   bitbake/lib/bb/parse/parse_py/ConfHandler.py | 2 +-
>>   bitbake/lib/bb/tests/parse.py                | 2 ++
>>   2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
>> index 05c627ec8b..0bfe357012 100644
>> --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
>> +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
>> @@ -21,7 +21,7 @@ __config_regexp__  = re.compile( r"""
>>       ^
>>       (?P<exp>export\s+)?
>>       (?P<var>[a-zA-Z0-9\-_+.${}/~:]+?)
>> -    (\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\])?
>> +    (\[(?P<flag>[a-zA-Z0-9\-_+.]([a-zA-Z0-9\-_+.@]+)?)\])?
> It would be better to use the simpler expression
> (\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]*)\])?

Oh, yes, it is better. Thanks and v2 will be sent.

Kai

>
>
> /Ola
>
>
>>       \s* (
>>           (?P<colon>:=) |
>> diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py
>> index d27c7c6f15..a3165d95bd 100644
>> --- a/bitbake/lib/bb/tests/parse.py
>> +++ b/bitbake/lib/bb/tests/parse.py
>> @@ -222,6 +222,7 @@ VAR = " \\
>>       at_sign_in_var_flag = """
>>   A[flag@.service] = "nonet"
>>   B[flag@.target] = "ntb"
>> +C[f] = "flag"
>>   
>>   unset A[flag@.service]
>>   """
>> @@ -232,6 +233,7 @@ unset A[flag@.service]
>>           self.assertEqual(d.getVar("B"), None)
>>           self.assertEqual(d.getVarFlag("A","flag@.service"), None)
>>           self.assertEqual(d.getVarFlag("B","flag@.target"), "ntb")
>> +        self.assertEqual(d.getVarFlag("C","f"), "flag")
>>   
>>       def test_parse_invalid_at_sign_in_var_flag(self):
>>           invalid_at_sign = self.at_sign_in_var_flag.replace("B[f", "B[@f")
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#14690): https://lists.openembedded.org/g/bitbake-devel/message/14690
> Mute This Topic: https://lists.openembedded.org/mt/98192343/3616933
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [kai.kang@eng.windriver.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
index 05c627ec8b..0bfe357012 100644
--- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
@@ -21,7 +21,7 @@  __config_regexp__  = re.compile( r"""
     ^
     (?P<exp>export\s+)?
     (?P<var>[a-zA-Z0-9\-_+.${}/~:]+?)
-    (\[(?P<flag>[a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\])?
+    (\[(?P<flag>[a-zA-Z0-9\-_+.]([a-zA-Z0-9\-_+.@]+)?)\])?
 
     \s* (
         (?P<colon>:=) |
diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py
index d27c7c6f15..a3165d95bd 100644
--- a/bitbake/lib/bb/tests/parse.py
+++ b/bitbake/lib/bb/tests/parse.py
@@ -222,6 +222,7 @@  VAR = " \\
     at_sign_in_var_flag = """
 A[flag@.service] = "nonet"
 B[flag@.target] = "ntb"
+C[f] = "flag"
 
 unset A[flag@.service]
 """
@@ -232,6 +233,7 @@  unset A[flag@.service]
         self.assertEqual(d.getVar("B"), None)
         self.assertEqual(d.getVarFlag("A","flag@.service"), None)
         self.assertEqual(d.getVarFlag("B","flag@.target"), "ntb")
+        self.assertEqual(d.getVarFlag("C","f"), "flag")
 
     def test_parse_invalid_at_sign_in_var_flag(self):
         invalid_at_sign = self.at_sign_in_var_flag.replace("B[f", "B[@f")