Skip to content

Commit

Permalink
Merge pull request systemd#3120 from DaanDeMeyer/fix
Browse files Browse the repository at this point in the history
Log config file path where available on config file parse errors
  • Loading branch information
DaanDeMeyer authored Oct 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 2469e6d + d1b5a05 commit 8a3f5fa
Showing 3 changed files with 34 additions and 17 deletions.
6 changes: 4 additions & 2 deletions mkosi.conf
Original file line number Diff line number Diff line change
@@ -12,12 +12,14 @@ History=yes
Format=directory
OutputDirectory=mkosi.output

[Build]
BuildSources=.
BuildSourcesEphemeral=yes

[Content]
Autologin=yes
SELinuxRelabel=no
ShimBootloader=unsigned
BuildSources=.
BuildSourcesEphemeral=yes

Packages=
binutils
41 changes: 27 additions & 14 deletions mkosi/config.py
Original file line number Diff line number Diff line change
@@ -1543,13 +1543,18 @@ def parse_simple_config(value: str) -> Any:
continue

if not (s := lookup.get(name)):
die(f"Unknown setting {name}")
die(f"{path.absolute()}: Unknown setting {name}")

if section != s.section:
logging.warning(f"Setting {name} should be configured in [{s.section}], not [{section}].")
logging.warning(
f"{path.absolute()}: Setting {name} should be configured in [{s.section}], not "
f"[{section}]."
)

if name != s.name:
logging.warning(f"Setting {name} is deprecated, please use {s.name} instead.")
logging.warning(
f"{path.absolute()}: Setting {name} is deprecated, please use {s.name} instead."
)

setattr(config, s.dest, s.parse(value, getattr(config, s.dest, None)))

@@ -3770,7 +3775,7 @@ def expand_specifiers(self, text: str, path: Path) -> str:
elif setting := SETTINGS_LOOKUP_BY_SPECIFIER.get(c):
if (v := self.finalize_value(setting)) is None:
logging.warning(
f"Setting {setting.name} specified by specifier '%{c}' "
f"{path.absolute()}: Setting {setting.name} specified by specifier '%{c}' "
f"in {text} is not yet set, ignoring"
)
continue
@@ -3789,16 +3794,16 @@ def expand_specifiers(self, text: str, path: Path) -> str:

if (v := self.finalize_value(setting)) is None:
logging.warning(
f"Setting {setting.name} which specifier '%{c}' in {text} depends on "
"is not yet set, ignoring"
f"{path.absolute()}: Setting {setting.name} which specifier '%{c}' in "
f"{text} depends on is not yet set, ignoring"
)
break

setattr(specifierns, d, v)
else:
result += specifier.callback(specifierns, path)
else:
logging.warning(f"Unknown specifier '%{c}' found in {text}, ignoring")
logging.warning(f"{path.absolute()}: Unknown specifier '%{c}' found in {text}, ignoring")
elif c == "%":
percent = True
else:
@@ -3939,7 +3944,9 @@ def match_config(self, path: Path) -> bool:
die(f"{k} cannot be used in [{section}]")

if k != s.name:
logging.warning(f"Setting {k} is deprecated, please use {s.name} instead.")
logging.warning(
f"{path.absolute()}: Setting {k} is deprecated, please use {s.name} instead."
)

# If we encounter a setting that has not been explicitly configured yet, we assign the
# default value first so that we can match on default values for settings.
@@ -4053,25 +4060,31 @@ def parse_config_one(self, path: Path, parse_profiles: bool = False, parse_local

name = k.removeprefix("@")
if name != k:
logging.warning(f"The '@' specifier is deprecated, please use {name} instead of {k}")
logging.warning(
f"{path.absolute()}: The '@' specifier is deprecated, please use {name} instead of "
f"{k}"
)

if not (s := SETTINGS_LOOKUP_BY_NAME.get(name)):
die(f"Unknown setting {name}")
die(f"{path.absolute()}: Unknown setting {name}")
if (
s.scope == SettingScope.universal
and (image := getattr(self.config, "image", None)) is not None
):
die(f"Setting {name} cannot be configured in subimage {image}")
die(f"{path.absolute()}: Setting {name} cannot be configured in subimage {image}")
if name in self.immutable:
die(f"Setting {name} cannot be modified anymore at this point")
die(f"{path.absolute()}: Setting {name} cannot be modified anymore at this point")

if section != s.section:
logging.warning(
f"Setting {name} should be configured in [{s.section}], not [{section}]."
f"{path.absolute()}: Setting {name} should be configured in [{s.section}], not "
f"[{section}]."
)

if name != s.name:
logging.warning(f"Setting {name} is deprecated, please use {s.name} instead.")
logging.warning(
f"{path.absolute()}: Setting {name} is deprecated, please use {s.name} instead."
)

v = self.expand_specifiers(v, path)

4 changes: 3 additions & 1 deletion mkosi/resources/mkosi-tools/mkosi.conf
Original file line number Diff line number Diff line change
@@ -5,8 +5,10 @@ Format=directory
Output=mkosi.tools
ManifestFormat=

[Content]
[Build]
BuildSources=

[Content]
Bootable=no
Packages=
acl

0 comments on commit 8a3f5fa

Please sign in to comment.