From 982022826da18904092be5e282f538662802228b Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 10 Nov 2022 12:44:13 +0100 Subject: fix(tools/magrathea): pass through nix-build exit status Something I missed last time reading through the process documentation is that you can use a combination of `process` and `process-wait` to determine the exit status of a child process *and* read from its standard output. With `process*` we could even capture stderr, but we probably want it mounted to the parent process' stderr anyways. Change-Id: I9840f607df465caa80d28109e344e5fc1402949d Reviewed-on: https://cl.tvl.fyi/c/depot/+/7259 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: tazjin --- tools/magrathea/mg.scm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/magrathea/mg.scm b/tools/magrathea/mg.scm index ab8e5bb77e..4a2a5ca6de 100644 --- a/tools/magrathea/mg.scm +++ b/tools/magrathea/mg.scm @@ -296,19 +296,19 @@ if you meant to pass these arguments to nix, please separate them with (define (execute-run t #!optional cmd-args) (fprintf (current-error-port) "[mg] building target ~A~%" t) (let* ((expr (nix-expr-for t)) - (out (call-with-input-pipe - (apply string-append - ;; TODO(sterni): temporary gc root - (intersperse `("nix-build" "-E" ,(qs expr) "--no-out-link") - " ")) - (lambda (p) - (string-chomp (let ((s (read-string #f p))) - (if (eq? s #!eof) "" s))))))) - - ;; TODO(sterni): can we get the exit code of nix-build somehow? - (when (= (string-length out) 0) - (mg-error (string-append "Couldn't build target " (format "~A" t))) - (exit 1)) + (out + (receive (pipe _ pid) + ;; TODO(sterni): temporary gc root + (process "nix-build" (list "-E" expr "--no-out-link")) + (let ((stdout (string-chomp + (let ((s (read-string #f pipe))) + (if (eq? s #!eof) "" s))))) + (receive (_ _ status) + (process-wait pid) + (when (not (eq? status 0)) + (mg-error (format "Couldn't build target ~A" t)) + (exit status)) + stdout))))) (fprintf (current-error-port) "[mg] running target ~A~%" t) (process-execute -- cgit 1.4.1