[PATCH] env: Allow string CONFIG options in the text environment
Simon Glass
sjg at chromium.org
Thu Nov 3 21:46:23 CET 2022
Sometimes it is useful to include a CONFIG option that contains a string.
This is hard to do in general, since in many cases it is useful to have
the quotes around the string so that, for example:
bootcmd=run CONFIG_BOARD_CMD
becomes
bootcmd=run "boot_board"
But for the special case where there is a single quoted, it seems
reasonable to suppress the quotes, so that:
board=CONFIG_SYS_BOARD
becomes
board=sandbox
Update the script, documentation and tests accordingly.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
doc/usage/environment.rst | 7 ++++++-
scripts/env2string.awk | 8 ++++++++
test/py/tests/test_env.py | 10 +++++++++-
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst
index 15897f63dd9..7272c6abbb4 100644
--- a/doc/usage/environment.rst
+++ b/doc/usage/environment.rst
@@ -55,7 +55,12 @@ variable but assigning to a new one::
This file can include C-style comments. Blank lines and multi-line
variables are supported, and you can use normal C preprocessor directives
-and CONFIG defines from your board config also.
+and CONFIG defines from your board config also. If the CONFIG value consists of
+a string and this is the only thing in the variable, the quotes will be
+dropped::
+
+ something=CONFIG_SYS_BOARD
+ # where CONFIG_SYS_BOARD is "sandbox" this becomes: something=sandbox
For example, for snapper9260 you would create a text file called
`board/bluewater/snapper9260.env` containing the environment text.
diff --git a/scripts/env2string.awk b/scripts/env2string.awk
index de470a49941..3a0fac47d07 100644
--- a/scripts/env2string.awk
+++ b/scripts/env2string.awk
@@ -43,6 +43,14 @@ NF {
var = substr($0, 1, RLENGTH - 1)
env = substr($0, RLENGTH + 1)
+ # If the env value consists entirely of a quoted string, drop
+ # the quotes. This handles things like fred=CONFIG_SYS_BOARD
+ # which would otherwise result in fred=\"sandbox\" in this
+ # output and fred="sandbox" in the final environment.
+ if (length(env) != 0 && match(env, /^\\"([^"]*)\\"$/)) {
+ env = substr(env, RSTART + 2, RLENGTH - 4)
+ }
+
# Deal with += which concatenates the new string to the existing
# variable. Again we are careful to use POSIX match()
if (length(env) != 0 && match(var, "^(.*)[+]$")) {
diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 6d08565f0b5..9bec12a2269 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -588,8 +588,16 @@ e=456
m+= 456''', 'e=456\\0m=123 456\\0')
# contains quotes
+ check_script('''fred=run "my var"
+mary=another"''', 'fred=run \\"my var\\"\\0mary=another\\"\\0')
+
+ # contains only a quoted strings, so quotes are removed
check_script('''fred="my var"
-mary=another"''', 'fred=\\"my var\\"\\0mary=another\\"\\0')
+mary=another"''', 'fred=my var\\0mary=another\\"\\0')
+
+ # contains more than one quoted string
+ check_script('''fred="my var" or "this var"
+mary=another"''', 'fred=\\"my var\\" or \\"this var\\"\\0mary=another\\"\\0')
# variable name ending in +
check_script('''fred\\+=my var
--
2.38.1.431.g37b22c650d-goog
More information about the U-Boot
mailing list