]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Refactor run_workspace_command()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 20 Jun 2022 12:24:21 +0000 (14:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 20 Jun 2022 12:24:21 +0000 (14:24 +0200)
mkosi/backend.py
mkosi/manifest.py

index 3d37d8e17027380edcdd3d245d08e03cb602c47d..a0ed865d014eb2998acdfaf560da06353179de0b 100644 (file)
@@ -658,7 +658,8 @@ def run_workspace_command(
     env: Optional[Mapping[str, str]] = None,
     nspawn_params: Optional[List[str]] = None,
     capture_stdout: bool = False,
-) -> Optional[str]:
+    check: bool = True,
+) -> CompletedProcess:
     nspawn = [
         nspawn_executable(),
         "--quiet",
@@ -694,13 +695,12 @@ def run_workspace_command(
     if args.nspawn_keep_unit:
         nspawn += ["--keep-unit"]
 
-    result = run([*nspawn, "--", *cmd], check=False, stdout=stdout, text=capture_stdout)
-    if result.returncode != 0:
+    try:
+        return run([*nspawn, "--", *cmd], check=check, stdout=stdout, text=capture_stdout)
+    except subprocess.CalledProcessError as e:
         if "workspace-command" in ARG_DEBUG:
             run(nspawn, check=False)
-        die(f"Workspace command {shell_join(cmd)} returned non-zero exit code {result.returncode}.")
-
-    return result.stdout.strip() if capture_stdout else None
+        die(f"Workspace command {shell_join(cmd)} returned non-zero exit code {e.returncode}.")
 
 
 @contextlib.contextmanager
index 42ee32e08cb7d3937495b871fe99ee2f9c3574c1..ab07815578927c428a8fda469b2895c6c3a2a26c 100644 (file)
@@ -190,8 +190,8 @@ class Manifest:
                 # We have to run from the root, because if we use the RootDir option to make
                 # apt from the host look at the repositories in the image, it will also pick
                 # the 'methods' executables from there, but the ABI might not be compatible.
-                changelog = run_workspace_command(self.args, root, cmd, network=not self.args.with_docs, capture_stdout=True)
-                source_package = SourcePackageManifest(source, changelog)
+                result = run_workspace_command(self.args, root, cmd, network=not self.args.with_docs, capture_stdout=True)
+                source_package = SourcePackageManifest(source, result.stdout.strip())
                 self.source_packages[source] = source_package
 
             source_package.add(package)