diff options
author | Rasmus Villemoes <rasmus.villemoes@prevas.dk> | 2018-07-03 14:54:14 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-01-14 11:35:56 +0000 |
commit | d6fe480c2bb20674cb1303f5d85fb6f8b66df1e5 (patch) | |
tree | ef5bbe60658e241b88485b3f4fb3e900dc72bda6 /scripts/lib/wic/ksparser.py | |
parent | e47d6f9e710e4fa17fc3fe9740d878affa751339 (diff) | |
download | poky-d6fe480c2bb20674cb1303f5d85fb6f8b66df1e5.tar.gz |
wic: allow bitbake variables in kickstarter files
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.
(From OE-Core rev: 8a75d614a8a1ff72c4af448ac3e1292d0e1d1a79)
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/ksparser.py')
-rw-r--r-- | scripts/lib/wic/ksparser.py | 17 |
1 files changed, 17 insertions, 0 deletions
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 @@ | |||
28 | import os | 28 | import os |
29 | import shlex | 29 | import shlex |
30 | import logging | 30 | import logging |
31 | import re | ||
31 | 32 | ||
32 | from argparse import ArgumentParser, ArgumentError, ArgumentTypeError | 33 | from argparse import ArgumentParser, ArgumentError, ArgumentTypeError |
33 | 34 | ||
34 | from wic.engine import find_canned | 35 | from wic.engine import find_canned |
35 | from wic.partition import Partition | 36 | from wic.partition import Partition |
37 | from wic.misc import get_bitbake_var | ||
36 | 38 | ||
37 | logger = logging.getLogger('wic') | 39 | logger = logging.getLogger('wic') |
38 | 40 | ||
41 | __expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}") | ||
42 | |||
43 | def expand_line(line): | ||
44 | while True: | ||
45 | m = __expand_var_regexp__.search(line) | ||
46 | if not m: | ||
47 | return line | ||
48 | key = m.group()[2:-1] | ||
49 | val = get_bitbake_var(key) | ||
50 | if val is None: | ||
51 | logger.warning("cannot expand variable %s" % key) | ||
52 | return line | ||
53 | line = line[:m.start()] + val + line[m.end():] | ||
54 | |||
39 | class KickStartError(Exception): | 55 | class KickStartError(Exception): |
40 | """Custom exception.""" | 56 | """Custom exception.""" |
41 | pass | 57 | pass |
@@ -190,6 +206,7 @@ class KickStart(): | |||
190 | line = line.strip() | 206 | line = line.strip() |
191 | lineno += 1 | 207 | lineno += 1 |
192 | if line and line[0] != '#': | 208 | if line and line[0] != '#': |
209 | line = expand_line(line) | ||
193 | try: | 210 | try: |
194 | line_args = shlex.split(line) | 211 | line_args = shlex.split(line) |
195 | parsed = parser.parse_args(line_args) | 212 | parsed = parser.parse_args(line_args) |