Skip to content

Commit 83b16e9

Browse files
committed
bootstrap: add quoting support to avoid splitting
With this change, it is now possible to pass quotes to the configure script, such as `./configure.py --set=target.\"thumbv8m.main-none-eabi\".linker=/linker` , which will treat `thumbv8.main-none-eabi` as a whole part. Currently, the string would be split into two elements: `thumbv8`, and `main-none-eabi`.
1 parent 27e38f8 commit 83b16e9

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/bootstrap/configure.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ def build(known_args):
288288

289289
def set(key, value, config):
290290
if isinstance(value, list):
291-
# Remove empty values, which value.split(',') tends to generate.
292-
value = [v for v in value if v]
291+
# Remove empty values, which value.split(',') tends to generate and
292+
# replace single quotes for double quotes to ensure correct parsing.
293+
value = [v.replace('\'', '"') for v in value if v]
293294

294295
s = "{:20} := {}".format(key, value)
295296
if len(s) < 70 or VERBOSE:
@@ -298,7 +299,25 @@ def set(key, value, config):
298299
p(s[:70] + " ...")
299300

300301
arr = config
301-
parts = key.split('.')
302+
303+
# Split on periods unless the block is quoted.
304+
parts = []
305+
current_part = ''
306+
within_quotes = False
307+
for character in key:
308+
if character in ['"', '\'']:
309+
within_quotes = not within_quotes
310+
elif character == '.' and not within_quotes:
311+
parts.append(current_part)
312+
current_part = ''
313+
else:
314+
current_part += character
315+
else:
316+
if current_part:
317+
parts.append(current_part)
318+
if within_quotes:
319+
raise RuntimeError('end quote not found in arguments.')
320+
302321
for i, part in enumerate(parts):
303322
if i == len(parts) - 1:
304323
if is_value_list(part) and isinstance(value, str):

0 commit comments

Comments
 (0)