[resend^2] wic: allow bitbake variables in kickstarter files

Submitted by Rasmus Villemoes on Dec. 29, 2018, 12:06 a.m. | Patch ID: 157486

Details

Message ID 20181229000646.23975-1-rasmus.villemoes@prevas.dk
State New
Headers show

Commit Message

Rasmus Villemoes Dec. 29, 2018, 12:06 a.m.
image_types_wic.bbclass has a mechanism for doing variable substitution
on .wks files by simply letting the input file be called
.wks.in. However, that doesn't allow using variables in files included
via the include directive. This is unfortunate, because lacking either
the ability to include other files or variable substitution leads to
fragile and error-prone duplication between kickstarter files and
recipes/configuration files used for various boards.

This adds (somewhat naive) support for variable substitution in all
files parsed by wic. The user should add all required variables to
WICVARS to get them exported appropriately.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
scripts/lib/wic/ksparser.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Patch hide | download patch | download mbox

diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 7e5a9c5092..08baf76123 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -28,14 +28,30 @@ 
 import os
 import shlex
 import logging
+import re
 
 from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
 
 from wic.engine import find_canned
 from wic.partition import Partition
+from wic.misc import get_bitbake_var
 
 logger = logging.getLogger('wic')
 
+__expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}")
+
+def expand_line(line):
+    while True:
+        m = __expand_var_regexp__.search(line)
+        if not m:
+            return line
+        key = m.group()[2:-1]
+        val = get_bitbake_var(key)
+        if val is None:
+            logger.warning("cannot expand variable %s" % key)
+            return line
+        line = line[:m.start()] + val + line[m.end():]
+
 class KickStartError(Exception):
     """Custom exception."""
     pass
@@ -190,6 +206,7 @@  class KickStart():
                 line = line.strip()
                 lineno += 1
                 if line and line[0] != '#':
+                    line = expand_line(line)
                     try:
                         line_args = shlex.split(line)
                         parsed = parser.parse_args(line_args)

Comments

Rasmus Villemoes Jan. 9, 2019, 6:57 a.m.
ping

On 29/12/2018 01.06, Rasmus Villemoes wrote:
> image_types_wic.bbclass has a mechanism for doing variable substitution
> on .wks files by simply letting the input file be called
> .wks.in. However, that doesn't allow using variables in files included
> via the include directive. This is unfortunate, because lacking either
> the ability to include other files or variable substitution leads to
> fragile and error-prone duplication between kickstarter files and
> recipes/configuration files used for various boards.
> 
> This adds (somewhat naive) support for variable substitution in all
> files parsed by wic. The user should add all required variables to
> WICVARS to get them exported appropriately.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
> scripts/lib/wic/ksparser.py | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
> index 7e5a9c5092..08baf76123 100644
> --- a/scripts/lib/wic/ksparser.py
> +++ b/scripts/lib/wic/ksparser.py
> @@ -28,14 +28,30 @@
>  import os
>  import shlex
>  import logging
> +import re
>  
>  from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
>  
>  from wic.engine import find_canned
>  from wic.partition import Partition
> +from wic.misc import get_bitbake_var
>  
>  logger = logging.getLogger('wic')
>  
> +__expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}")
> +
> +def expand_line(line):
> +    while True:
> +        m = __expand_var_regexp__.search(line)
> +        if not m:
> +            return line
> +        key = m.group()[2:-1]
> +        val = get_bitbake_var(key)
> +        if val is None:
> +            logger.warning("cannot expand variable %s" % key)
> +            return line
> +        line = line[:m.start()] + val + line[m.end():]
> +
>  class KickStartError(Exception):
>      """Custom exception."""
>      pass
> @@ -190,6 +206,7 @@ class KickStart():
>                  line = line.strip()
>                  lineno += 1
>                  if line and line[0] != '#':
> +                    line = expand_line(line)
>                      try:
>                          line_args = shlex.split(line)
>                          parsed = parser.parse_args(line_args)
>
Rasmus Villemoes Jan. 13, 2019, 11:18 a.m.
ping ping

On 29/12/2018 01.06, Rasmus Villemoes wrote:
> image_types_wic.bbclass has a mechanism for doing variable substitution
> on .wks files by simply letting the input file be called
> .wks.in. However, that doesn't allow using variables in files included
> via the include directive. This is unfortunate, because lacking either
> the ability to include other files or variable substitution leads to
> fragile and error-prone duplication between kickstarter files and
> recipes/configuration files used for various boards.
> 
> This adds (somewhat naive) support for variable substitution in all
> files parsed by wic. The user should add all required variables to
> WICVARS to get them exported appropriately.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
> scripts/lib/wic/ksparser.py | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
> index 7e5a9c5092..08baf76123 100644
> --- a/scripts/lib/wic/ksparser.py
> +++ b/scripts/lib/wic/ksparser.py
> @@ -28,14 +28,30 @@
>  import os
>  import shlex
>  import logging
> +import re
>  
>  from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
>  
>  from wic.engine import find_canned
>  from wic.partition import Partition
> +from wic.misc import get_bitbake_var
>  
>  logger = logging.getLogger('wic')
>  
> +__expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}")
> +
> +def expand_line(line):
> +    while True:
> +        m = __expand_var_regexp__.search(line)
> +        if not m:
> +            return line
> +        key = m.group()[2:-1]
> +        val = get_bitbake_var(key)
> +        if val is None:
> +            logger.warning("cannot expand variable %s" % key)
> +            return line
> +        line = line[:m.start()] + val + line[m.end():]
> +
>  class KickStartError(Exception):
>      """Custom exception."""
>      pass
> @@ -190,6 +206,7 @@ class KickStart():
>                  line = line.strip()
>                  lineno += 1
>                  if line and line[0] != '#':
> +                    line = expand_line(line)
>                      try:
>                          line_args = shlex.split(line)
>                          parsed = parser.parse_args(line_args)
>