diff options
| author | Michael Goulet <michael@errs.io> | 2023-02-25 11:53:10 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-25 11:53:10 -0800 |
| commit | 0b6b373f4885757d908ffbc524ad5aa73fc983bc (patch) | |
| tree | b49f714ea25191e7db4f36384cd80f1fcdd5b735 | |
| parent | cf049ac2af24eb899b38082d46cec491013b3175 (diff) | |
| parent | 5643706ca2ca59a47966c03104d4b8d931adb2dd (diff) | |
| download | rust-0b6b373f4885757d908ffbc524ad5aa73fc983bc.tar.gz rust-0b6b373f4885757d908ffbc524ad5aa73fc983bc.zip | |
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 < ```
| -rwxr-xr-x | src/bootstrap/configure.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 0af329e7007..04e798e3949 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -379,8 +379,14 @@ cur_section = None sections[None] = [] section_order = [None] targets = {} +top_level_keys = [] for line in open(rust_dir + '/config.toml.example').read().split("\n"): + if cur_section == None: + if line.count('=') == 1: + top_level_key = line.split('=')[0] + top_level_key = top_level_key.strip(' #') + top_level_keys.append(top_level_key) if line.startswith('['): cur_section = line[1:-1] if cur_section.startswith('target'): @@ -459,12 +465,22 @@ def configure_section(lines, config): raise RuntimeError("failed to find config line for {}".format(key)) -for section_key in config: - section_config = config[section_key] - if section_key not in sections: - raise RuntimeError("config key {} not in sections".format(section_key)) +def configure_top_level_key(lines, top_level_key, value): + for i, line in enumerate(lines): + if line.startswith('#' + top_level_key + ' = ') or line.startswith(top_level_key + ' = '): + lines[i] = "{} = {}".format(top_level_key, value) + return - if section_key == 'target': + raise RuntimeError("failed to find config line for {}".format(top_level_key)) + + +for section_key, section_config in config.items(): + if section_key not in sections and section_key not in top_level_keys: + raise RuntimeError("config key {} not in sections or top_level_keys".format(section_key)) + if section_key in top_level_keys: + configure_top_level_key(sections[None], section_key, section_config) + + elif section_key == 'target': for target in section_config: configure_section(targets[target], section_config[target]) else: |
