From: Laurence Kiln <246209442+LaurenceKiln@users.noreply.github.com> Date: Wed, 17 Dec 2025 18:15:22 +0000 (+0200) Subject: Migrate log_step to complete_step in places X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b19a49ccf7288b4400ef17f3e8f491e979fb916c;p=thirdparty%2Fmkosi.git Migrate log_step to complete_step in places --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index f4766ae71..4428156f8 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1527,42 +1527,41 @@ def build_kernel_modules_initrd(context: Context, kver: str) -> Path: if kmods.exists(): return kmods - log_step("Building kernel modules initrd") - - make_cpio( - context.root, - kmods, - files=gen_required_kernel_modules( - context, - kver, - modules_include=finalize_kernel_modules_include( + with complete_step("Building kernel modules initrd"): + make_cpio( + context.root, + kmods, + files=gen_required_kernel_modules( context, - include=context.config.kernel_modules_initrd_include, - host=context.config.kernel_modules_initrd_include_host, + kver, + modules_include=finalize_kernel_modules_include( + context, + include=context.config.kernel_modules_initrd_include, + host=context.config.kernel_modules_initrd_include_host, + ), + modules_exclude=context.config.kernel_modules_initrd_exclude, + firmware_include=context.config.firmware_include, + firmware_exclude=context.config.firmware_exclude, ), - modules_exclude=context.config.kernel_modules_initrd_exclude, - firmware_include=context.config.firmware_include, - firmware_exclude=context.config.firmware_exclude, - ), - sandbox=context.sandbox, - ) + sandbox=context.sandbox, + ) - if context.config.distribution.is_apt_distribution(): - # Older Debian and Ubuntu releases do not compress their kernel modules, so we compress the - # initramfs instead. Note that this is not ideal since the compressed kernel modules will - # all be decompressed on boot which requires significant memory. - if context.config.distribution == Distribution.debian and context.config.release in ( - "sid", - "testing", - ): - compression = Compression.none - else: - compression = Compression.zstd + if context.config.distribution.is_apt_distribution(): + # Older Debian and Ubuntu releases do not compress their kernel modules, so we compress the + # initramfs instead. Note that this is not ideal since the compressed kernel modules will + # all be decompressed on boot which requires significant memory. + if context.config.distribution == Distribution.debian and context.config.release in ( + "sid", + "testing", + ): + compression = Compression.none + else: + compression = Compression.zstd - maybe_compress(context, compression, kmods, kmods) + maybe_compress(context, compression, kmods, kmods) - if ArtifactOutput.kernel_modules_initrd in context.config.split_artifacts: - shutil.copy(kmods, context.staging / context.config.output_split_kernel_modules_initrd) + if ArtifactOutput.kernel_modules_initrd in context.config.split_artifacts: + shutil.copy(kmods, context.staging / context.config.output_split_kernel_modules_initrd) return kmods diff --git a/mkosi/archive.py b/mkosi/archive.py index 1ba28afc0..f3fbea610 100644 --- a/mkosi/archive.py +++ b/mkosi/archive.py @@ -5,7 +5,7 @@ from collections.abc import Iterable, Sequence from pathlib import Path from typing import Optional -from mkosi.log import log_step +from mkosi.log import complete_step, log_step from mkosi.run import SandboxProtocol, finalize_passwd_symlinks, nosandbox, run, workdir from mkosi.sandbox import umask from mkosi.util import PathString, chdir @@ -23,38 +23,37 @@ def tar_exclude_apivfs_tmp() -> list[str]: def make_tar(src: Path, dst: Path, *, sandbox: SandboxProtocol = nosandbox) -> None: - log_step(f"Creating tar archive {dst}…") - - with dst.open("wb") as f: - run( - [ - "tar", - "--create", - "--file", "-", - "--directory", workdir(src, sandbox), - "--acls", - "--selinux", - # --xattrs implies --format=pax - "--xattrs", - # PAX format emits additional headers for atime, ctime and mtime - # that would make the archive non-reproducible. - "--pax-option=delete=atime,delete=ctime,delete=mtime", - "--sparse", - "--force-local", - *(["--owner=root:0"] if os.getuid() != 0 else []), - *(["--group=root:0"] if os.getuid() != 0 else []), - *tar_exclude_apivfs_tmp(), - ".", - ], - stdout=f, - # Make sure tar uses user/group information from the root directory instead of the host. - sandbox=sandbox( - options=[ - "--ro-bind", src, workdir(src, sandbox), - *finalize_passwd_symlinks(workdir(src, sandbox)), + with complete_step(f"Creating tar archive {dst}…"): + with dst.open("wb") as f: + run( + [ + "tar", + "--create", + "--file", "-", + "--directory", workdir(src, sandbox), + "--acls", + "--selinux", + # --xattrs implies --format=pax + "--xattrs", + # PAX format emits additional headers for atime, ctime and mtime + # that would make the archive non-reproducible. + "--pax-option=delete=atime,delete=ctime,delete=mtime", + "--sparse", + "--force-local", + *(["--owner=root:0"] if os.getuid() != 0 else []), + *(["--group=root:0"] if os.getuid() != 0 else []), + *tar_exclude_apivfs_tmp(), + ".", ], - ), - ) # fmt: skip + stdout=f, + # Make sure tar uses user/group information from the root directory instead of the host. + sandbox=sandbox( + options=[ + "--ro-bind", src, workdir(src, sandbox), + *finalize_passwd_symlinks(workdir(src, sandbox)), + ], + ), + ) # fmt: skip def can_extract_tar(src: Path) -> bool: @@ -119,27 +118,26 @@ def make_cpio( else: files = sorted(files) - log_step(f"Creating cpio archive {dst}…") - - with dst.open("wb") as f: - run( - [ - "cpio", - "--create", - "--reproducible", - "--renumber-inodes", - "--null", - "--format=newc", - "--quiet", - "--directory", workdir(src, sandbox), - *(["--owner=0:0"] if os.getuid() != 0 else []), - ], - input="\0".join(os.fspath(f) for f in files), - stdout=f, - sandbox=sandbox( - options=[ - "--ro-bind", src, workdir(src, sandbox), - *finalize_passwd_symlinks(workdir(src, sandbox)) + with complete_step(f"Creating cpio archive {dst}…"): + with dst.open("wb") as f: + run( + [ + "cpio", + "--create", + "--reproducible", + "--renumber-inodes", + "--null", + "--format=newc", + "--quiet", + "--directory", workdir(src, sandbox), + *(["--owner=0:0"] if os.getuid() != 0 else []), ], - ), - ) # fmt: skip + input="\0".join(os.fspath(f) for f in files), + stdout=f, + sandbox=sandbox( + options=[ + "--ro-bind", src, workdir(src, sandbox), + *finalize_passwd_symlinks(workdir(src, sandbox)) + ], + ), + ) # fmt: skip diff --git a/mkosi/kmod.py b/mkosi/kmod.py index 9d7e4c917..d91133e04 100644 --- a/mkosi/kmod.py +++ b/mkosi/kmod.py @@ -150,7 +150,6 @@ def filter_firmware( include: Iterable[str], exclude: Iterable[str], ) -> set[Path]: - log_step("Applying firmware include/exclude configuration") if include: logging.debug(f"Firmware include directives: {' '.join(include)}") if exclude: @@ -251,17 +250,16 @@ def resolve_module_dependencies( allmodules = set(modulesd.rglob("*.ko*")) nametofile = {module_path_to_name(m): m for m in allmodules} - log_step("Running modinfo to fetch kernel module dependencies") - - # We could run modinfo once for each module but that's slow. Luckily we can pass multiple modules to - # modinfo and it'll process them all in a single go. We get the modinfo for all modules to build two maps - # that map the path of the module to its module dependencies and its firmware dependencies - # respectively. Because there's more kernel modules than the max number of accepted CLI arguments, we - # split the modules list up into chunks. - info = "" - for i in range(0, len(nametofile.keys()), 8500): - chunk = list(nametofile.keys())[i : i + 8500] - info += modinfo(context, kver, chunk) + with complete_step("Running modinfo to fetch kernel module dependencies"): + # We could run modinfo once for each module but that's slow. Luckily we can pass multiple modules to + # modinfo and it'll process them all in a single go. We get the modinfo for all modules to build + # two maps that map the path of the module to its module dependencies and its firmware dependencies + # respectively. Because there's more kernel modules than the max number of accepted CLI arguments, we + # split the modules list up into chunks. + info = "" + for i in range(0, len(nametofile.keys()), 8500): + chunk = list(nametofile.keys())[i : i + 8500] + info += modinfo(context, kver, chunk) log_step("Calculating required kernel modules and firmware") @@ -362,7 +360,10 @@ def gen_required_kernel_modules( firmware = set() # Include or exclude firmware explicitly configured - firmware = filter_firmware(context.root, firmware, include=firmware_include, exclude=firmware_exclude) + with complete_step("Applying firmware include/exclude configuration"): + firmware = filter_firmware( + context.root, firmware, include=firmware_include, exclude=firmware_exclude + ) # /usr/lib/firmware makes use of symbolic links so we have to make sure the symlinks and their targets # are all included. @@ -468,18 +469,18 @@ def process_kernel_modules( modulesd = Path("usr/lib/modules") / kver firmwared = Path("usr/lib/firmware") - with complete_step("Applying kernel module filters"): - required = set( - gen_required_kernel_modules( - context, - kver, - modules_include=modules_include, - modules_exclude=modules_exclude, - firmware_include=firmware_include, - firmware_exclude=firmware_exclude, - ) + required = set( + gen_required_kernel_modules( + context, + kver, + modules_include=modules_include, + modules_exclude=modules_exclude, + firmware_include=firmware_include, + firmware_exclude=firmware_exclude, ) + ) + with complete_step("Applying kernel module filters"): with chdir(context.root): modules = sorted(modulesd.rglob("*.ko*"), reverse=True) firmware = sorted(firmwared.rglob("*"), reverse=True)