Skip to content

Commit 38f690e

Browse files
committed
add _late_args for later kernel_version
in cases where --kver is passed by cmdline (such as when used with installkernel), validation could fail if there is no modules directory before the config.toml is read where no_kmod may be set. this allows for certain config to only be processed in the later stages so cmdline args can be applied in the final config pass. Signed-off-by: Zen <[email protected]>
1 parent 3056149 commit 38f690e

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

docs/dev_manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Python functions can be added imported into `init` and `build` runlevels to exec
1010
1111
Within modules, all config values are imported, then processed according to the order of the `custom_parameters` list.
1212

13+
> If config values have validation which may fail if other config is not loaded, those values can be added to the `_late_args' list to be processed last.
14+
1315
`_module_name` can be set within a module for logging purposes, it is verified to be accurate when imported but optional.
1416

1517
## Imports

src/ugrd/initramfs_dict.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class InitramfsConfigDict(UserDict):
4040
"custom_parameters": dict, # Custom parameters loaded from imports
4141
"custom_processing": dict, # Custom processing functions which will be run to validate and process parameters
4242
"_processing": dict, # A dict of queues containing parameters which have been set before the type was known
43+
"_late_args": NoDupFlatList, # A list of arguments which could be passed as command line args but need to be processed after the config is loaded
4344
"test_copy_config": NoDupFlatList, # A list of config values which are copied into test images, from the parent
4445
}
4546

@@ -57,7 +58,7 @@ def __init__(self, NO_BASE=False, *args, **kwargs):
5758
else:
5859
self["modules"] = "ugrd.base.core"
5960

60-
def import_args(self, args: dict, quiet=False) -> None:
61+
def import_args(self, args: dict, quiet=False, late=False) -> None:
6162
"""Imports data from an argument dict."""
6263
log_level = 10 if quiet else 20
6364
for arg, value in args.items():
@@ -66,6 +67,11 @@ def import_args(self, args: dict, quiet=False) -> None:
6667
if arg == "modules": # allow loading modules by name from the command line
6768
for module in value.split(","):
6869
self[arg] = module
70+
elif arg in self["_late_args"] and not late:
71+
self.logger.debug(
72+
f"[{c_(arg, 'yellow')}] Deferring late argument processing until after config load: {c_(value, 'green')}",
73+
)
74+
continue
6975
elif getattr(self, arg, None) != value: # Only set the value if it differs:
7076
self[arg] = value
7177
else:

src/ugrd/initramfs_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, config="/etc/ugrd/config.toml", *args, **kwargs):
3131
try: # Attempt to load the config file, if it exists
3232
self.load_config(config) # The user config is loaded over the base config, clobbering kwargs
3333
self.config_dict.import_args(
34-
kwargs, quiet=True
34+
kwargs, quiet=True, late=True
3535
) # Re-import kwargs (cmdline params) to apply them over the config
3636
except FileNotFoundError:
3737
if config: # If a config file was specified, log an error that it's missing

src/ugrd/kmod/kmod.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ modules = [ "ugrd.kmod.standard_mask", "ugrd.kmod.platform", "ugrd.kmod.input" ]
33
kmod_pull_firmware = true
44
kmod_decompress_firmware = true
55

6+
_late_args = ["kernel_version"]
7+
68
[custom_parameters]
79
_kmod_removed = "NoDupFlatList" # Meant to be used internally, defines kernel modules which have been ignored at runtime
810
_kmod_modinfo = "dict" # Used internally, caches modinfo output for kernel modules

0 commit comments

Comments
 (0)