`--debug=`
-: Enable additional debugging output. Takes a comma-separated list of
- arguments specifying the area of interest. Pass any invalid value
- (e.g. empty) to list currently accepted values.
+: Enable additional debugging output.
+
+`--debug-shell=`
+
+: When executing a command in the image fails, mkosi will start an interactive
+ shell in the image allowing further debugging.
`--version`
for kver, kimg in gen_kernel_images(state):
cmd: list[PathString] = ["kernel-install", "add", kver, Path("/") / kimg]
- if ARG_DEBUG:
+ if ARG_DEBUG.get():
cmd.insert(1, "--verbose")
# Make dracut think --no-host-only was passed via the CLI.
try:
yield
except SystemExit as e:
- if ARG_DEBUG:
+ if ARG_DEBUG.get():
raise e
sys.exit(e.code)
except KeyboardInterrupt as e:
- if ARG_DEBUG:
+ if ARG_DEBUG.get():
raise e
logging.error("Interrupted")
sys.exit(1)
except subprocess.CalledProcessError as e:
- if ARG_DEBUG:
+ if ARG_DEBUG.get():
raise e
# We always log when subprocess.CalledProcessError is raised, so we don't log again here.
sys.exit(e.returncode)
except Exception as e:
- if ARG_DEBUG:
+ if ARG_DEBUG.get():
raise e
elif not isinstance(e, RuntimeError):
# RuntimeError is used to wrap generic errors, and the message that was printed should be enough.
log_setup()
args = MkosiConfigParser().parse()
- if ARG_DEBUG:
+ if ARG_DEBUG.get():
logging.getLogger().setLevel(logging.DEBUG)
if args.directory:
from pathlib import Path
from typing import Any, Callable, Optional, Type, Union, cast
-from mkosi.log import ARG_DEBUG, Style, die
+from mkosi.log import ARG_DEBUG, ARG_DEBUG_SHELL, Style, die
from mkosi.pager import page
from mkosi.run import run
from mkosi.util import (
parser.add_argument(
"--debug",
help="Turn on debugging output",
- action="append",
- default=[],
+ action="store_true",
+ default=False,
+ )
+ parser.add_argument(
+ "--debug-shell",
+ help="Spawn an interactive shell in the image if a chroot command fails",
+ action="store_true",
+ default=False,
)
parser.add_argument(
"--no-pager",
ssh: bool
credentials: dict[str, str]
directory: Optional[Path]
- debug: list[str]
+ debug: bool
+ debug_shell: bool
auto_bump: bool
workspace_dir: Optional[Path]
initrds: list[Path]
def load_args(args: argparse.Namespace) -> MkosiConfig:
- ARG_DEBUG.update(args.debug)
+ ARG_DEBUG.set(args.debug)
+ ARG_DEBUG_SHELL.set(args.debug_shell)
find_image_version(args)
f"--load-average={jobs+1}",
"--nospinner",
]
- if "build-script" in ARG_DEBUG:
+ if ARG_DEBUG.get():
emerge_default_opts += ["--verbose", "--quiet=n", "--quiet-fail=n"]
else:
emerge_default_opts += ["--quiet-build", "--quiet"]
import contextlib
+import contextvars
import logging
import os
import sys
from typing import Any, Iterator, NoReturn, Optional
# This global should be initialized after parsing arguments
-ARG_DEBUG: set[str] = set()
+ARG_DEBUG = contextvars.ContextVar("debug", default=False)
+ARG_DEBUG_SHELL = contextvars.ContextVar("debug-shell", default=False)
LEVEL = 0
from types import TracebackType
from typing import Any, Callable, Mapping, Optional, Sequence, Type, TypeVar
-from mkosi.log import ARG_DEBUG, die
+from mkosi.log import ARG_DEBUG, ARG_DEBUG_SHELL, die
from mkosi.types import _FILE, CompletedProcess, PathString, Popen
from mkosi.util import current_user
log: bool = True,
**kwargs: Any,
) -> CompletedProcess:
- if "run" in ARG_DEBUG:
+ if ARG_DEBUG.get():
logging.info(f"+ {shlex.join(str(s) for s in cmdline)}")
cmdline = [os.fspath(x) for x in cmdline]
LANG="C.UTF-8",
) | env
- if "run" in ARG_DEBUG:
+ if ARG_DEBUG.get():
env["SYSTEMD_LOG_LEVEL"] = "debug"
if "input" in kwargs:
stderr: _FILE = None,
**kwargs: Any,
) -> Popen:
- if "run" in ARG_DEBUG:
+ if ARG_DEBUG.get():
logging.info(f"+ {shlex.join(str(s) for s in cmdline)}")
if not stdout and not stderr:
try:
return run([*cmdline, *cmd], text=True, stdout=stdout, env=env, log=False)
except subprocess.CalledProcessError as e:
- if "run" in ARG_DEBUG:
+ if ARG_DEBUG_SHELL.get():
run([*cmdline, "sh"], stdin=sys.stdin, check=False, env=env, log=False)
die(f'"{shlex.join(str(s) for s in cmd)}" returned non-zero exit code {e.returncode}.')
try:
return run([*cmdline, *cmd], text=True, stdout=stdout, env=env, log=False)
except subprocess.CalledProcessError as e:
- if "run" in ARG_DEBUG:
+ if ARG_DEBUG_SHELL.get():
run([*cmdline, "sh"], stdin=sys.stdin, check=False, env=env, log=False)
die(f'"{shlex.join(str(s) for s in cmd)}" returned non-zero exit code {e.returncode}.')
finally: