From: Daan De Meyer Date: Mon, 20 Jun 2022 12:24:21 +0000 (+0200) Subject: Refactor run_workspace_command() X-Git-Tag: v13~10^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d29dc2265d9ff11de9f522184b36ea99134a19f;p=thirdparty%2Fmkosi.git Refactor run_workspace_command() --- diff --git a/mkosi/backend.py b/mkosi/backend.py index 3d37d8e17..a0ed865d0 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -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 diff --git a/mkosi/manifest.py b/mkosi/manifest.py index 42ee32e08..ab0781557 100644 --- a/mkosi/manifest.py +++ b/mkosi/manifest.py @@ -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)