From: Daan De Meyer Date: Fri, 11 Feb 2022 12:12:58 +0000 (+0000) Subject: Error when trying to build an image without --bootable and run it with qemu X-Git-Tag: v13~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3347c17de558c488501b0c8ee9cd61f1b61aef79;p=thirdparty%2Fmkosi.git Error when trying to build an image without --bootable and run it with qemu We can only check this when we're building the image, since when we're not building the image it's not required to pass the --bootable option in order to be able to use the qemu verb to run it in qemu. This also fixes needs_build() to take the args.force option into account. This fixes usage of needs_build() before unlink_output() is called. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 4f04b7406..188309e5e 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -6491,6 +6491,9 @@ def load_args(args: argparse.Namespace) -> MkosiArgs: if not args.output_format.is_disk(): die("Sorry, can't boot non-disk images with qemu.") + if needs_build(args) and args.verb == "qemu" and not args.bootable: + die("Images built without the --bootable option cannot be booted using qemu") + if needs_build(args) and args.qemu_headless and not args.bootable: die("--qemu-headless requires --bootable") @@ -7842,7 +7845,7 @@ def expand_specifier(s: str) -> str: def needs_build(args: Union[argparse.Namespace, MkosiArgs]) -> bool: - return args.verb == "build" or (not args.output.exists() and args.verb in MKOSI_COMMANDS_NEED_BUILD) + return args.verb == "build" or (not args.output.exists() and args.verb in MKOSI_COMMANDS_NEED_BUILD) or args.force > 0 def run_verb(raw: argparse.Namespace) -> None: diff --git a/tests/test_parse_load_args.py b/tests/test_parse_load_args.py index 7f6f418ba..6a6e46f9d 100644 --- a/tests/test_parse_load_args.py +++ b/tests/test_parse_load_args.py @@ -39,7 +39,7 @@ def test_parse_load_verb(): assert parse(["build"]).verb == "build" assert parse(["shell"]).verb == "shell" assert parse(["boot"]).verb == "boot" - assert parse(["qemu"]).verb == "qemu" + assert parse(["--bootable", "qemu"]).verb == "qemu" with pytest.raises(SystemExit): parse(["invalid"])