diff options
author | Antonin Godard <antoningodard@pm.me> | 2024-05-14 01:53:06 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-21 14:14:41 +0100 |
commit | 03742d7cb375c124a0190dac7bcbc53aefa123dc (patch) | |
tree | 0b9ad663074fb0410de48a597cb1589e125a7a86 /bitbake/lib/bb/codeparser.py | |
parent | 98471a91e8d74203e0c22aa933bed97e764bb8e2 (diff) | |
download | poky-03742d7cb375c124a0190dac7bcbc53aefa123dc.tar.gz |
bitbake: codeparser: support shell substitutions in quotes
The current shell substitution mechanism only works without quotes. For
example:
var1=$(cmd1 ...)
Will work and add `cmd1` to the correspondind `run.do_*` file.
However, although quite common, this syntax is not supported:
var1="$(cmd1 ...)"
This commit adds this feature by adding a step to process_words() to
check whether we are dealing with quotes first, and by iterating on
what's between them to detect new shell substitution candidates. These
candidates are tested and parsed like before in the next step. The
original `part` being part of the candidates means the syntax
var1=$(cmd1 ...) is still valid.
(Bitbake rev: f56e1a37b2ba1773ed308043d7eb073cc2e6c06e)
Signed-off-by: Antonin Godard <antoningodard@pm.me>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/codeparser.py')
-rw-r--r-- | bitbake/lib/bb/codeparser.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py index 2e8b7ced3c..c613806c8e 100644 --- a/bitbake/lib/bb/codeparser.py +++ b/bitbake/lib/bb/codeparser.py | |||
@@ -490,13 +490,28 @@ class ShellParser(): | |||
490 | if not isinstance(part, list): | 490 | if not isinstance(part, list): |
491 | continue | 491 | continue |
492 | 492 | ||
493 | if part[0] in ('`', '$('): | 493 | candidates = [part] |
494 | command = pyshlex.wordtree_as_string(part[1:-1]) | 494 | |
495 | self._parse_shell(command) | 495 | # If command is of type: |
496 | 496 | # | |
497 | if word[0] in ("cmd_name", "cmd_word"): | 497 | # var="... $(cmd [...]) ..." |
498 | if word in words: | 498 | # |
499 | words.remove(word) | 499 | # Then iterate on what's between the quotes and if we find a |
500 | # list, make that what we check for below. | ||
501 | if len(part) >= 3 and part[0] == '"': | ||
502 | for p in part[1:-1]: | ||
503 | if isinstance(p, list): | ||
504 | candidates.append(p) | ||
505 | |||
506 | for candidate in candidates: | ||
507 | if len(candidate) >= 2: | ||
508 | if candidate[0] in ('`', '$('): | ||
509 | command = pyshlex.wordtree_as_string(candidate[1:-1]) | ||
510 | self._parse_shell(command) | ||
511 | |||
512 | if word[0] in ("cmd_name", "cmd_word"): | ||
513 | if word in words: | ||
514 | words.remove(word) | ||
500 | 515 | ||
501 | usetoken = False | 516 | usetoken = False |
502 | for word in words: | 517 | for word in words: |