From 960ac2e07f2edc7ac23f006d0c07467ac0967833 Mon Sep 17 00:00:00 2001 From: lionelllohcd Date: Sat, 18 Feb 2023 23:34:06 -0800 Subject: [PATCH 1/2] [107049] Recognise top level keys in config.toml.example --- src/bootstrap/configure.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 0af329e7007ac..91af36d9070ff 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -379,8 +379,14 @@ def set(key, value): 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,23 @@ 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 + + raise RuntimeError("failed to find config line for {}".format(top_level_key)) - if section_key == 'target': + +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: From 5643706ca2ca59a47966c03104d4b8d931adb2dd Mon Sep 17 00:00:00 2001 From: lionelllohcd Date: Sun, 19 Feb 2023 23:51:17 -0800 Subject: [PATCH 2/2] Removed trailing spaces to satisfy lint --- src/bootstrap/configure.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 91af36d9070ff..04e798e3949d9 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -382,8 +382,8 @@ def set(key, value): top_level_keys = [] for line in open(rust_dir + '/config.toml.example').read().split("\n"): - if cur_section == None: - if line.count('=') == 1: + 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) @@ -465,20 +465,19 @@ def configure_section(lines, config): raise RuntimeError("failed to find config line for {}".format(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 + ' = '): +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 - + return + 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: + 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: + if section_key in top_level_keys: configure_top_level_key(sections[None], section_key, section_config) elif section_key == 'target':