Skip to content

Commit

Permalink
Don't test the profile override hack
Browse files Browse the repository at this point in the history
It generates invalid TOML. I want to get rid of it eventually, but this avoids the issue in the meantime.
  • Loading branch information
jyn514 committed Jun 24, 2023
1 parent c7af6fb commit 24e67d5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,6 @@ def __init__(self, config_toml="", args=FakeArgs()):
self.color = args.color
self.warnings = args.warnings

profile = self.get_toml('profile')
if profile is not None:
include_file = 'config.{}.toml'.format(profile)
include_dir = os.path.join(self.rust_root, 'src', 'bootstrap', 'defaults')
include_path = os.path.join(include_dir, include_file)
# HACK: This works because `self.get_toml()` returns the first match it finds for a
# specific key, so appending our defaults at the end allows the user to override them
with open(include_path) as included_toml:
self.config_toml += os.linesep + included_toml.read()

config_verbose_count = self.get_toml('verbose', 'build')
if config_verbose_count is not None:
self.verbose = max(self.verbose, int(config_verbose_count))
Expand Down Expand Up @@ -794,9 +784,12 @@ def get_toml(self, key, section=None):
>>> rb.get_toml("key1")
'true'
"""
return RustBuild.get_toml_static(self.config_toml, key, section)

@staticmethod
def get_toml_static(config_toml, key, section=None):
cur_section = None
for line in self.config_toml.splitlines():
for line in config_toml.splitlines():
section_match = re.match(r'^\s*\[(.*)\]\s*$', line)
if section_match is not None:
cur_section = section_match.group(1)
Expand All @@ -805,7 +798,7 @@ def get_toml(self, key, section=None):
if match is not None:
value = match.group(1)
if section is None or section == cur_section:
return self.get_string(value) or value.strip()
return RustBuild.get_string(value) or value.strip()
return None

def cargo(self):
Expand Down Expand Up @@ -1054,6 +1047,16 @@ def bootstrap(args):
with open(toml_path) as config:
config_toml = config.read()

profile = RustBuild.get_toml_static(config_toml, 'profile')
if profile is not None:
include_file = 'config.{}.toml'.format(profile)
include_dir = os.path.join(rust_root, 'src', 'bootstrap', 'defaults')
include_path = os.path.join(include_dir, include_file)
# HACK: This works because `self.get_toml()` returns the first match it finds for a
# specific key, so appending our defaults at the end allows the user to override them
with open(include_path) as included_toml:
config_toml += os.linesep + included_toml.read()

# Configure initial bootstrap
build = RustBuild(config_toml, args)
build.check_vendored_status()
Expand Down

0 comments on commit 24e67d5

Please sign in to comment.