diff --git a/pmb/chroot/apk.py b/pmb/chroot/apk.py index 85d26f63..ee23bfda 100644 --- a/pmb/chroot/apk.py +++ b/pmb/chroot/apk.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import os from pathlib import Path +import traceback import pmb.chroot.apk_static from pmb.core.arch import Arch from pmb.helpers import logging @@ -204,6 +205,15 @@ def install_run_apk(to_add: List[str], to_add_local: List[Path], to_del: List[st channel = pmb.config.pmaports.read_config()["channel"] user_repo = work / "packages" / channel + # There are still some edgecases where we manage to get here while the chroot is not + # initialized. To not break the build, we initialize it here but print a big warning + # and a stack trace so hopefully folks report it. + if not chroot.is_mounted(): + logging.warning(f"({chroot}) chroot not initialized! This is a bug! Please report it.") + logging.warning(f"({chroot}) initializing the chroot for you...") + traceback.print_stack(file=logging.logfd) + pmb.chroot.init(chroot) + for (i, command) in enumerate(commands): # --no-interactive is a parameter to `add`, so it must be appended or apk # gets confused diff --git a/pmb/chroot/other.py b/pmb/chroot/other.py index cb676309..726dca74 100644 --- a/pmb/chroot/other.py +++ b/pmb/chroot/other.py @@ -23,6 +23,8 @@ def kernel_flavor_installed(chroot: Chroot, autoinstall=True): """ # Automatically install the selected kernel if autoinstall: + if not chroot.is_mounted(): + pmb.chroot.init(chroot) config = get_context().config packages = ([f"device-{config.device}"] + pmb.install.get_kernel_package(config)) diff --git a/pmb/core/chroot.py b/pmb/core/chroot.py index dcce2d1f..7ac98736 100644 --- a/pmb/core/chroot.py +++ b/pmb/core/chroot.py @@ -91,6 +91,10 @@ class Chroot: return (self / "bin/sh").is_symlink() + def is_mounted(self) -> bool: + return self.exists() and pmb.helpers.mount.ismount(self.path / "etc/apk/keys") + + @property def arch(self) -> Arch: if self.type == ChrootType.NATIVE: