about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-11-07 09:50:31 +0000
committerbors <bors@rust-lang.org>2024-11-07 09:50:31 +0000
commitfe43131683267082fc46be5796ce84351e9fb497 (patch)
tree1607a514822531c0b7aae5d6d337492088a5db0b /src/bootstrap
parent9200cbc71230a86b8a70481b625d93a4fa5ef523 (diff)
parent8471c6bb0c3f46f5dbad5942aedb661304cae001 (diff)
downloadrust-fe43131683267082fc46be5796ce84351e9fb497.tar.gz
rust-fe43131683267082fc46be5796ce84351e9fb497.zip
Auto merge of #132635 - kiike:fix/dots_in_target, r=onur-ozkan
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`
or
`./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`.

The approach taken is to perform custom splitting instead of using `str.split()` and then repairing the split. Also, There are numerous corner cases not handled: the custom split doesn't differentiate between single quotes or double quotes, so it is perfectly possible to pass `./configure.py --set=target.\"thumbv8m.main-none-eabi\'.linker=/linker` and the behaviour would be the same as with all double quotes or single quotes.

As for the code, i'm unsure on whether to delimit strings with double or single quotes. I've seen both single quotes and double quotes used to delimit strings, like in
```py
err("Option '{}' provided more than once".format(key))
```
and this a handful of lines down:
```py
if option.name == 'sccache':
    set('llvm.ccache', 'sccache', config)
```
Please advise on the wanted one.

Fixes #130602

r? `@onur-ozkan`

Thanks in advance for the feedback!
Diffstat (limited to 'src/bootstrap')
-rwxr-xr-xsrc/bootstrap/configure.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index 2e173c9e6df..70f4e70962a 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -3,6 +3,7 @@
 # ignore-tidy-linelength
 
 from __future__ import absolute_import, division, print_function
+import shlex
 import sys
 import os
 rust_dir = os.path.dirname(os.path.abspath(__file__))
@@ -288,8 +289,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 +300,13 @@ def set(key, value, config):
         p(s[:70] + " ...")
 
     arr = config
-    parts = key.split('.')
+
+    # Split `key` on periods using shell semantics.
+    lexer = shlex.shlex(key, posix=True)
+    lexer.whitespace = "."
+    lexer.wordchars += "-"
+    parts = list(lexer)
+
     for i, part in enumerate(parts):
         if i == len(parts) - 1:
             if is_value_list(part) and isinstance(value, str):