]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Error when trying to build an image without --bootable and run it with qemu
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 11 Feb 2022 12:12:58 +0000 (12:12 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 11 Feb 2022 17:57:36 +0000 (17:57 +0000)
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.

mkosi/__init__.py
tests/test_parse_load_args.py

index 4f04b7406f67a3326ee1562ec12229ae1be9ec8a..188309e5e60a5838f2fb0ce8ae1ec45a282bd1eb 100644 (file)
@@ -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:
index 7f6f418ba8600a19e5397340360fc4e4e9c81af0..6a6e46f9d54aefedffa56be27e74863da424f186 100644 (file)
@@ -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"])