rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.94k stars 12.68k forks source link

bootstrap/configure.py: targets with a dot in the name prevent finding the correct target section in `config.toml.example` #130602

Open kiike opened 1 month ago

kiike commented 1 month ago

When passing --set arguments to the configure script, the targets will be incorrectly detected when they include a dot in the name. An example would be thumbv8m.main. Thus, when using a command line such as

./configure.py --target=thumb8vm.main-none-eabi --set=target.thumbv8m.main-none-eabi.linker=/path/to/linker

this error will be triggered:

configure: processing command line
configure: 
configure: build.target         := ['thumb8vm.main-none-eabi']
configure: target.thumbv8m.main-none-eabi.linker := /path/to/linker  ...
configure: build.configure-args := ['--target=thumb8vm.main-none-eabi', '--set=ta ...
Traceback (most recent call last):
  File "/home/kiike/projects/rust/src/bootstrap/./configure.py", line 469, in <module>
    configure_section(targets[target], section_config[target])
  File "/home/kiike/projects/rust/src/bootstrap/./configure.py", line 459, in configure_section
    raise RuntimeError("failed to find config line for {}".format(key))
RuntimeError: failed to find config line for main-none-eabi

This is related to #97263 and #105920. I think there might be three different solutions:

diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index 49d564642bd..e4e1f15e80b 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -297,6 +297,12 @@ def set(key, value, config):

     arr = config
     parts = key.split('.')
+
+    if len(parts) > 2 and parts[1] == "thumbv8m" and parts[2].endswith("none-eabi"):
+        print("Old `parts`:", parts)
+        parts[1] += "." + parts.pop(2)
+        print("New `parts`:", parts)
+
     for i, part in enumerate(parts):
         if i == len(parts) - 1:
             if is_value_list(part) and isinstance(value, str):

Output:

$ python3 ./configure.py --target=thumb8vm.main-none-eabi --set=target.thumbv8m.main-none-eabi.linker=/path/to/linker
configure: processing command line
configure: 
configure: build.configure-args := ['--target=thumb8vm.main-none-eabi', '--set=ta ...
configure: build.target         := ['thumb8vm.main-none-eabi']
configure: target.thumbv8m.main-none-eabi.linker := /path/to/linker
Old `parts`: ['target', 'thumbv8m', 'main-none-eabi', 'linker']
New `parts`: ['target', 'thumbv8m.main-none-eabi', 'linker']
configure: profile              := dist
configure: 
configure: writing `config.toml` in current directory
configure: 
configure: run `python /home/kiike/projects/rust/x.py --help`
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index 49d564642bd..1945945a990 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -5,6 +5,7 @@
 from __future__ import absolute_import, division, print_function
 import sys
 import os
+import re
 rust_dir = os.path.dirname(os.path.abspath(__file__))
 rust_dir = os.path.dirname(rust_dir)
 rust_dir = os.path.dirname(rust_dir)
@@ -296,8 +297,12 @@ def set(key, value, config):
         p(s[:70] + " ...")

     arr = config
-    parts = key.split('.')
+    parts = re.split(r"(?<!\\)\.", key)
     for i, part in enumerate(parts):
+        if re.search(r"\\\.", part):
+            print("Old part:", part)
+            part = re.sub(r"\\\.", ".", part)
+            print("New part:", part)
         if i == len(parts) - 1:
             if is_value_list(part) and isinstance(value, str):
                 value = value.split(',')

Resulting in:

python3 ./configure.py --target=thumb8vm.main-none-eabi --set=target.thumbv8m\\.main-none-eabi.linker=/path/to/linker
configure: processing command line
configure: 
configure: build.configure-args := ['--target=thumb8vm.main-none-eabi', '--set=ta' ...
configure: build.target         := ['thumb8vm.main-none-eabi']
configure: target.thumbv8m\.main-none-eabi.linker := /path/to/linker
Old part: thumbv8m\.main-none-eabi
New part: thumbv8m.main-none-eabi
configure: profile              := dist
configure: 
configure: writing `config.toml` in current directory
configure: 
configure: run `python /home/kiike/projects/rust/x.py --help`

I'm wiling to work on this issue but I'd need to know what approach would be preferred.

kiike commented 1 month ago

Related: https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/specifying.20linker.20for.20cross-compiling

If this is out-of-scope for configure.py and manual editing of the config.toml is required, I'd like to know too.

kiike commented 4 weeks ago

@rustbot label T-bootstrap

kiike commented 2 weeks ago

@onur-ozkan, I'd like to work on this. As the lead for the bootstrap phase, could you provide a couple hints on how you envision the change, i.e. the approach you would like this to take? I provided some patches in the first comment to show a couple of ways I could tackle this issue.

onur-ozkan commented 1 week ago

@onur-ozkan, I'd like to work on this. As the lead for the bootstrap phase, could you provide a couple hints on how you envision the change, i.e. the approach you would like this to take? I provided some patches in the first comment to show a couple of ways I could tackle this issue.

Hi, sorry for the late response. I wouldn't add any special logic for target names but would instead solve this more generally by handling dots within quotes (e.g., making it so that --set="target.thumbv8m.main-none-eabi.linker=/path/to/linker" works without issues).