diff mbox series

[meta-swupdate] swupdate-common.bbclass: Update regex for variable matching

Message ID PH7PR17MB6130EEB4967AE8E6E29F87569C4B2@PH7PR17MB6130.namprd17.prod.outlook.com
State Changes Requested
Delegated to: Stefano Babic
Headers show
Series [meta-swupdate] swupdate-common.bbclass: Update regex for variable matching | expand

Commit Message

John Ripple Feb. 9, 2024, 5:32 p.m. UTC
From: John Ripple <john.ripple@keysight.com>

+ Changed the regex conditions so @@ symbols can be at the start or end
of lines without any other characters around them. This allows bitbake
variables to be replaced at the start or end of a line, not just in the
middle.

Signed-off-by: John Ripple <john.ripple@keysight.com>
---
 classes/swupdate-common.bbclass | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

--
2.34.1

Comments

Stefano Babic April 16, 2024, 11:51 a.m. UTC | #1
Hi John,

On 09.02.24 18:32, 'John Ripple' via swupdate wrote:
> From: John Ripple <john.ripple@keysight.com>
>
> + Changed the regex conditions so @@ symbols can be at the start or end
> of lines without any other characters around them. This allows bitbake
> variables to be replaced at the start or end of a line, not just in the
> middle.
>

This cannot be applied because it adds a feature but just for an older
branch. It can be applied to krikstone (still in development, this is
ok), but there is no counterparts for the other supported releases, that
is nanbield (at the time of the patch), and now scarthgap. It does not
apply because OE splits classes into classes-global and classes-recipe.
This feature should be added with two patches, one for kirkstone (this
one) and the second one for OE >= nanbield.

Best regards,
Stefano Babic

> Signed-off-by: John Ripple <john.ripple@keysight.com>
> ---
>   classes/swupdate-common.bbclass | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/classes/swupdate-common.bbclass
> b/classes/swupdate-common.bbclass
> index 9074f7f..6305ab2 100644
> --- a/classes/swupdate-common.bbclass
> +++ b/classes/swupdate-common.bbclass
> @@ -69,7 +69,7 @@ def swupdate_write_sha256(s):
>       with open(os.path.join(s, "sw-description"), 'r') as f:
>          for line in f:
>             shastr = r"sha256.+=.+@(.+\")"
> -          m =
> re.match(r"^(?P<before_placeholder>.+)(sha256|version).+[=:].*(?P<quote>[\'\"])@(?P<filename>.*)(?P=quote)", line)
> +          m =
> re.match(r"^(?P<before_placeholder>.*)(sha256|version).+[=:].*(?P<quote>[\'\"])@(?P<filename>.*)(?P=quote)", line)
>             if m:
>                 filename = m.group('filename')
>                 bb.warn("Syntax for sha256 changed, please use
> $swupdate_get_sha256(%s)" % filename)
> @@ -85,7 +85,7 @@ def swupdate_write_sha256(s):
>   def swupdate_exec_functions(d, s, write_lines):
>       import re
>       for index, line in enumerate(write_lines):
> -        m =
> re.match(r"^(?P<before_placeholder>.+)\$(?P<bitbake_function_name>\w+)\((?P<parms>.+)\)(?P<after_placeholder>.+)$", line)
> +        m =
> re.match(r"^(?P<before_placeholder>.*)\$(?P<bitbake_function_name>\w+)\((?P<parms>.+)\)(?P<after_placeholder>.*)$", line)
>           if m:
>               fun = m.group('bitbake_function_name') + "(d, \"" + s +
> "\", \"" + m.group('parms') + "\")"
>               ret = eval(fun)
> @@ -102,7 +102,7 @@ def swupdate_expand_bitbake_variables(d, s):
>           for line in f:
>               found = False
>               while True:
> -                m =
> re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.+)$", line)
> +                m =
> re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.*)$", line)
>                   if m:
>                       bitbake_variable_value =
> d.getVar(m.group('bitbake_variable_name'), True)
>                       if bitbake_variable_value is None:
> @@ -112,7 +112,7 @@ def swupdate_expand_bitbake_variables(d, s):
>                       found = True
>                       continue
>                   else:
> -                    m =
> re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.+)$", line)
> +                    m =
> re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.*)$", line)
>                       if m:
>                          bitbake_variable_value =
> (d.getVarFlag(m.group('bitbake_variable_name'),
> m.group('flag_var_name'), True) or "")
>                          if bitbake_variable_value is None:
> @@ -144,7 +144,7 @@ def swupdate_find_bitbake_variables(d):
>               for line in f:
>                   found = False
>                   while True:
> -                    m =
> re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.+)$", line)
> +                    m =
> re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.*)$", line)
>                       if m:
>                           bitbake_variable_value =
> m.group('bitbake_variable_name')
>                           vardeps.append(bitbake_variable_value)
> @@ -152,7 +152,7 @@ def swupdate_find_bitbake_variables(d):
>                           found = True
>                           continue
>                       else:
> -                        m =
> re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.+)$", line)
> +                        m =
> re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.*)$", line)
>                           if m:
>                               bitbake_variable_value =
> m.group('bitbake_variable_name')
>                               vardeps.append(bitbake_variable_value)
> --
> 2.34.1
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+unsubscribe@googlegroups.com
> <mailto:swupdate+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/swupdate/PH7PR17MB6130EEB4967AE8E6E29F87569C4B2%40PH7PR17MB6130.namprd17.prod.outlook.com <https://groups.google.com/d/msgid/swupdate/PH7PR17MB6130EEB4967AE8E6E29F87569C4B2%40PH7PR17MB6130.namprd17.prod.outlook.com?utm_medium=email&utm_source=footer>.
diff mbox series

Patch

diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index 9074f7f..6305ab2 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -69,7 +69,7 @@  def swupdate_write_sha256(s):
     with open(os.path.join(s, "sw-description"), 'r') as f:
        for line in f:
           shastr = r"sha256.+=.+@(.+\")"
-          m = re.match(r"^(?P<before_placeholder>.+)(sha256|version).+[=:].*(?P<quote>[\'\"])@(?P<filename>.*)(?P=quote)", line)
+          m = re.match(r"^(?P<before_placeholder>.*)(sha256|version).+[=:].*(?P<quote>[\'\"])@(?P<filename>.*)(?P=quote)", line)
           if m:
               filename = m.group('filename')
               bb.warn("Syntax for sha256 changed, please use $swupdate_get_sha256(%s)" % filename)
@@ -85,7 +85,7 @@  def swupdate_write_sha256(s):
 def swupdate_exec_functions(d, s, write_lines):
     import re
     for index, line in enumerate(write_lines):
-        m = re.match(r"^(?P<before_placeholder>.+)\$(?P<bitbake_function_name>\w+)\((?P<parms>.+)\)(?P<after_placeholder>.+)$", line)
+        m = re.match(r"^(?P<before_placeholder>.*)\$(?P<bitbake_function_name>\w+)\((?P<parms>.+)\)(?P<after_placeholder>.*)$", line)
         if m:
             fun = m.group('bitbake_function_name') + "(d, \"" + s + "\", \"" + m.group('parms') + "\")"
             ret = eval(fun)
@@ -102,7 +102,7 @@  def swupdate_expand_bitbake_variables(d, s):
         for line in f:
             found = False
             while True:
-                m = re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.+)$", line)
+                m = re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.*)$", line)
                 if m:
                     bitbake_variable_value = d.getVar(m.group('bitbake_variable_name'), True)
                     if bitbake_variable_value is None:
@@ -112,7 +112,7 @@  def swupdate_expand_bitbake_variables(d, s):
                     found = True
                     continue
                 else:
-                    m = re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.+)$", line)
+                    m = re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.*)$", line)
                     if m:
                        bitbake_variable_value = (d.getVarFlag(m.group('bitbake_variable_name'), m.group('flag_var_name'), True) or "")
                        if bitbake_variable_value is None:
@@ -144,7 +144,7 @@  def swupdate_find_bitbake_variables(d):
             for line in f:
                 found = False
                 while True:
-                    m = re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.+)$", line)
+                    m = re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.*)$", line)
                     if m:
                         bitbake_variable_value = m.group('bitbake_variable_name')
                         vardeps.append(bitbake_variable_value)
@@ -152,7 +152,7 @@  def swupdate_find_bitbake_variables(d):
                         found = True
                         continue
                     else:
-                        m = re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.+)$", line)
+                        m = re.match(r"^(?P<before_placeholder>.*)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.*)$", line)
                         if m:
                             bitbake_variable_value = m.group('bitbake_variable_name')
                             vardeps.append(bitbake_variable_value)