Skip to content

Commit

Permalink
bootstrap: add quoting support to avoid splitting
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
kiike committed Nov 5, 2024
1 parent 27e38f8 commit 83b16e9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ def build(known_args):

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

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

arr = config
parts = key.split('.')

# Split on periods unless the block is quoted.
parts = []
current_part = ''
within_quotes = False
for character in key:
if character in ['"', '\'']:
within_quotes = not within_quotes
elif character == '.' and not within_quotes:
parts.append(current_part)
current_part = ''
else:
current_part += character
else:
if current_part:
parts.append(current_part)
if within_quotes:
raise RuntimeError('end quote not found in arguments.')

for i, part in enumerate(parts):
if i == len(parts) - 1:
if is_value_list(part) and isinstance(value, str):
Expand Down

0 comments on commit 83b16e9

Please sign in to comment.