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 <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
sterni 2022-11-10 12:44:13 +01:00
parent 3d8849e68b
commit 982022826d

View file

@ -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