for include in context.config.initrd_include:
cmdline += ["--include", os.fspath(include)]
- args, [config] = parse_config(cmdline + ["build"])
+ args, [config] = parse_config(cmdline + ["build"], resources=context.resources)
make_executable(
*config.prepare_scripts,
*(["-f"] * args.force),
]
- _, [tools] = parse_config(cmdline + ["--include", os.fspath(resources / "mkosi-tools"), "build"])
+ _, [tools] = parse_config(
+ cmdline + ["--include", os.fspath(resources / "mkosi-tools"), "build"],
+ resources=resources,
+ )
make_executable(
*tools.prepare_scripts,
if not args.verb.needs_build() and args.verb != Verb.clean:
continue
- if config.tools_tree and config.tools_tree.name == "default":
- tools = finalize_default_tools(args, config, resources=resources)
- fork_and_wait(lambda: run_clean(args, tools)) # type: ignore
+ if config.tools_tree and config.tools_tree == Path("default"):
+ fork_and_wait(run_clean, args, finalize_default_tools(args, config, resources=resources))
- fork_and_wait(lambda: run_clean(args, config))
+ fork_and_wait(run_clean, args, config)
if args.verb == Verb.clean:
return
tools = (
finalize_default_tools(args, config, resources=resources)
- if config.tools_tree and config.tools_tree.name == "default"
+ if config.tools_tree and config.tools_tree == Path("default")
else None
)
)
if tools and not (tools.output_dir_or_cwd() / tools.output_with_compression).exists():
- fork_and_wait(lambda: run_build(args, tools, resources=resources)) # type:ignore
+ fork_and_wait(run_build, args, tools, resources=resources)
if (config.output_dir_or_cwd() / config.output_with_compression).exists():
continue
- fork_and_wait(lambda: run_build(args, config, resources=resources))
+ fork_and_wait(run_build, args, config, resources=resources)
build = True
from mkosi.run import find_binary, run
from mkosi.sandbox import sandbox_cmd
from mkosi.types import PathString, SupportsRead
-from mkosi.util import INVOKING_USER, StrEnum, chdir, flatten, is_power_of_2
+from mkosi.util import (
+ INVOKING_USER,
+ StrEnum,
+ chdir,
+ flatten,
+ is_power_of_2,
+ make_executable,
+)
from mkosi.versioncomp import GenericVersion
__version__ = "20.2"
ConfigDefaultCallback = Callable[[argparse.Namespace], Any]
+BUILTIN_CONFIGS = ("mkosi-tools", "mkosi-initrd")
+
+
class Verb(StrEnum):
build = enum.auto()
clean = enum.auto()
expanduser: bool = True,
expandvars: bool = True,
secret: bool = False,
- absolute: bool = False) -> Path:
+ absolute: bool = False,
+ constants: Sequence[str] = ()) -> Path:
+ if value in constants:
+ return Path(value)
+
if expandvars:
value = os.path.expandvars(value)
resolve: bool = True,
expanduser: bool = True,
expandvars: bool = True,
- secret: bool = False) -> Callable[[str], Path]:
+ secret: bool = False,
+ constants: Sequence[str] = ()) -> Callable[[str], Path]:
return functools.partial(
parse_path,
required=required,
expanduser=expanduser,
expandvars=expandvars,
secret=secret,
+ constants=constants,
)
resolve: bool = True,
expanduser: bool = True,
expandvars: bool = True,
- secret: bool = False) -> ConfigParseCallback:
+ secret: bool = False,
+ constants: Sequence[str] = ()) -> ConfigParseCallback:
def config_parse_path(value: Optional[str], old: Optional[Path]) -> Optional[Path]:
if not value:
return None
expanduser=expanduser,
expandvars=expandvars,
secret=secret,
+ constants=constants,
)
return config_parse_path
ConfigSetting(
dest="include",
section="Config",
- parse=config_make_list_parser(delimiter=",", reset=False, parse=make_path_parser()),
+ parse=config_make_list_parser(
+ delimiter=",",
+ reset=False,
+ parse=make_path_parser(constants=BUILTIN_CONFIGS),
+ ),
help="Include configuration from the specified file or directory",
),
ConfigSetting(
dest="tools_tree",
metavar="PATH",
section="Host",
- parse=config_make_path_parser(required=False),
+ parse=config_make_path_parser(required=False, constants=("default",)),
paths=("mkosi.tools",),
help="Look up programs to execute inside the given tree",
),
return sorted(images, key=lambda i: order.index(i.image))
-def parse_config(argv: Sequence[str] = ()) -> tuple[Args, tuple[Config, ...]]:
+def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tuple[Args, tuple[Config, ...]]:
# Compare inodes instead of paths so we can't get tricked by bind mounts and such.
parsed_includes: set[tuple[int, int]] = set()
immutable_settings: set[str] = set()
finally:
# Parse any includes that were added after yielding.
for p in getattr(namespace, "include", [])[current_num_of_includes:]:
- st = p.stat()
+ for c in BUILTIN_CONFIGS:
+ if p == Path(c):
+ path = resources / c
+ break
+ else:
+ path = p
+
+ st = path.stat()
if (st.st_dev, st.st_ino) in parsed_includes:
continue
- with chdir(p if p.is_dir() else Path.cwd()):
- parse_config_one(p if p.is_file() else Path("."), namespace, defaults)
+ if any(p == Path(c) for c in BUILTIN_CONFIGS):
+ _, [config] = parse_config(["--include", os.fspath(path)])
+ make_executable(
+ *config.prepare_scripts,
+ *config.postinst_scripts,
+ *config.finalize_scripts,
+ *config.build_scripts,
+ )
+
+ with chdir(path if path.is_dir() else Path.cwd()):
+ parse_config_one(path if path.is_file() else Path("."), namespace, defaults)
parsed_includes.add((st.st_dev, st.st_ino))
class ConfigAction(argparse.Action):