From 906f376b52730ab3721d17d749a44dee9efcd633 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 4 Feb 2025 13:54:44 -0800 Subject: [PATCH] environment: handle machine file options sections with more than one subproject Instead of having a raw python exception, provide a helpful error message that `[sub:sub1:project options]` should just be `[sub1:project options]` No test is provided as this is basic error handling, and I felt it was not worth adding to our test runtime to test that we don't raise a raw exception. Fixes: #14222 --- mesonbuild/environment.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 90b10697a..f1d55cc0f 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -273,7 +273,7 @@ class Environment: for section, values in config.items(): if ':' in section: - section_subproject, section = section.split(':') + section_subproject, section = section.split(':', 1) else: section_subproject = '' if section == 'built-in options': @@ -290,6 +290,13 @@ class Environment: # Project options are always for the host machine key = self.mfilestr2key(strk, section, section_subproject, machine) self.options[key] = v + elif ':' in section: + correct_subproject, correct_section = section.split(':')[-2:] + raise MesonException( + 'Subproject options should always be set as ' + '`[subproject:section]`, even if the options are from a ' + 'nested subproject. ' + f'Replace `[{section_subproject}:{section}]` with `[{correct_subproject}:{correct_section}]`') def _set_default_options_from_env(self) -> None: opts: T.List[T.Tuple[str, str]] = (