public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Subject: [PATCH] wic: plugins: Improve rootfs-u-boot script_prepend passing
Date: Sat, 8 May 2021 14:43:31 +0200	[thread overview]
Message-ID: <185f97a0-6755-1344-43cd-7df51040ba65@siemens.com> (raw)

From: Jan Kiszka <jan.kiszka@siemens.com>

Passing a script_prepend value down to the generated boot.scr currently
requires double escaping: once for the wks file when being parsed by
wic and a second time for /etc/default/u-boot-script when being parsed
by the u-boot-script tool.

This removes the need for double escaping by detecting if the " or $
characters are already escaped after the wic parsing step. If not, the
plugin injects the required escape character.

In addition, this provides a way to avoid the wic warning about an
unknown (bitbake) variable when injecting ${some_var} into the script:

do_wic_image: WARNING: cannot expand variable some_var

The user can now simply escape the curly braces as well: $\{some_var\}.
The plugin will remove these escapes before generating the u-boot-script
configuration file. This also resolves the more theoretical case of a
naming clash between a WICVAR and a U-Boot script variable.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
index 3ac0aa0..15acb57 100644
--- a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
+++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py
@@ -14,6 +14,7 @@
 
 import glob
 import logging
+import re
 import os
 
 from wic import WicError
@@ -75,6 +76,12 @@ class RootfsUBootPlugin(RootfsPlugin):
             overlays = source_params.get('overlays') or ''
             cfg.write('OVERLAYS="%s"\n' % overlays)
             script_prepend = source_params.get('script_prepend') or ''
+            # remove escapes from $\{var\} that are needed to avoid expansion by wic
+            script_prepend = re.sub(r'\$\\{([^\\]+)\\}', r'${\1}', script_prepend)
+            # escape any quotes that aren't escaped yet
+            script_prepend = re.sub(r'([^\\])"', r'\1\\"', script_prepend)
+            # escape any dollars that aren't escaped yet
+            script_prepend = re.sub(r'([^\\])\$', r'\1\\$', script_prepend)
             cfg.write('SCRIPT_PREPEND="%s"\n' % script_prepend)
 
         # Run update-u-boot-script in the target rootfs
-- 
2.26.2

             reply	other threads:[~2021-05-08 12:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-08 12:43 Jan Kiszka [this message]
2021-06-08  6:47 ` Anton Mikanovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=185f97a0-6755-1344-43cd-7df51040ba65@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox