Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[107049] Recognise top level keys in config.toml.example #108229

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this and used <dict>.items() instead.

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:
Expand Down