Skip to content

Commit 0b6b373

Browse files
Rollup merge of #108229 - lionellloh:issue-107049, r=Mark-Simulacrum
[107049] Recognise top level keys in config.toml.example Closes #107049 Test Plan Configure changelog-seen ``` lionellloh@lionellloh-mbp rust % ./configure --set changelog-seen=1 configure: processing command line configure: configure: changelog-seen := 1 configure: build.configure-args := ['--set', 'changelog-seen=1'] configure: configure: writing `config.toml` in current directory configure: configure: run `python /Users/lionellloh/rust/x.py --help` lionellloh@lionellloh-mbp rust % diff config.toml config.toml.example 16c16 < changelog-seen = 1 --- > changelog-seen = 2 331c331 < configure-args = ['--set', 'changelog-seen=1'] --- > #configure-args = [] 675c675 < [target.x86_64-apple-darwin] --- > [target.x86_64-unknown-linux-gnu] 809d808 < ``` Configure profile ``` lionellloh@lionellloh-mbp rust % ./configure --set profile=xyz configure: processing command line configure: configure: profile := xyz configure: build.configure-args := ['--set', 'profile=xyz'] configure: configure: writing `config.toml` in current directory configure: configure: run `python /Users/lionellloh/rust/x.py --help` lionellloh@lionellloh-mbp rust % diff config.toml config.toml.example 26c26 < profile = xyz --- > #profile = <none> 331c331 < configure-args = ['--set', 'profile=xyz'] --- > #configure-args = [] 675c675 < [target.x86_64-apple-darwin] --- > [target.x86_64-unknown-linux-gnu] 809d808 < ```
2 parents cf049ac + 5643706 commit 0b6b373

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/bootstrap/configure.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,14 @@ def set(key, value):
379379
sections[None] = []
380380
section_order = [None]
381381
targets = {}
382+
top_level_keys = []
382383

383384
for line in open(rust_dir + '/config.toml.example').read().split("\n"):
385+
if cur_section == None:
386+
if line.count('=') == 1:
387+
top_level_key = line.split('=')[0]
388+
top_level_key = top_level_key.strip(' #')
389+
top_level_keys.append(top_level_key)
384390
if line.startswith('['):
385391
cur_section = line[1:-1]
386392
if cur_section.startswith('target'):
@@ -459,12 +465,22 @@ def configure_section(lines, config):
459465
raise RuntimeError("failed to find config line for {}".format(key))
460466

461467

462-
for section_key in config:
463-
section_config = config[section_key]
464-
if section_key not in sections:
465-
raise RuntimeError("config key {} not in sections".format(section_key))
468+
def configure_top_level_key(lines, top_level_key, value):
469+
for i, line in enumerate(lines):
470+
if line.startswith('#' + top_level_key + ' = ') or line.startswith(top_level_key + ' = '):
471+
lines[i] = "{} = {}".format(top_level_key, value)
472+
return
466473

467-
if section_key == 'target':
474+
raise RuntimeError("failed to find config line for {}".format(top_level_key))
475+
476+
477+
for section_key, section_config in config.items():
478+
if section_key not in sections and section_key not in top_level_keys:
479+
raise RuntimeError("config key {} not in sections or top_level_keys".format(section_key))
480+
if section_key in top_level_keys:
481+
configure_top_level_key(sections[None], section_key, section_config)
482+
483+
elif section_key == 'target':
468484
for target in section_config:
469485
configure_section(targets[target], section_config[target])
470486
else:

0 commit comments

Comments
 (0)