From 83b16e9ce8c2340eced8e66d4a4d374ff211c483 Mon Sep 17 00:00:00 2001 From: Enric Morales Date: Tue, 5 Nov 2024 11:32:05 +0100 Subject: [PATCH] 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`. --- src/bootstrap/configure.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 2e173c9e6df48..035ea8527a182 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -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: @@ -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):