scripts: gen_defines: fix tokenization of array elements
This fixes commit
3d5cc38cf6f58b363828059fa11e151112e9cce0.
That commit only works if removing the quotes from e.g. a string in an
array actually results in a token. If the string's value is something
like
"foo,bar"
though, it will result in the "token"
foo,bar
in the generated output.
This is wrong; fix it using the new edtlib.str_as_token() API
introduced to allow callers to perform the same procedure as that
library for fixing up strings.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py
index fdcc782..86bd91b 100755
--- a/scripts/dts/gen_defines.py
+++ b/scripts/dts/gen_defines.py
@@ -650,8 +650,9 @@
for i, subval in enumerate(prop.val):
if isinstance(subval, str):
macro2val[macro + f"_IDX_{i}"] = quote_str(subval)
- macro2val[macro + f"_IDX_{i}_TOKEN"] = subval
- macro2val[macro + f"_IDX_{i}_UPPER_TOKEN"] = subval.upper()
+ subval_as_token = edtlib.str_as_token(subval)
+ macro2val[macro + f"_IDX_{i}_TOKEN"] = subval_as_token
+ macro2val[macro + f"_IDX_{i}_UPPER_TOKEN"] = subval_as_token.upper()
else:
macro2val[macro + f"_IDX_{i}"] = subval
macro2val[macro + f"_IDX_{i}_EXISTS"] = 1