From c3628af8cc4ec79dc03b47db724b29da7b3d47ba Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 22 Jun 2023 13:40:09 +0200 Subject: refactor(tools/magrathea): introduce read-chomping helper function Change-Id: I2ee6903686fd210755c40eb9555c938e8c1ab52b Reviewed-on: https://cl.tvl.fyi/c/depot/+/8843 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: tazjin --- tools/magrathea/mg.scm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/magrathea/mg.scm b/tools/magrathea/mg.scm index 2de60c8d4873..0caf7843ef62 100644 --- a/tools/magrathea/mg.scm +++ b/tools/magrathea/mg.scm @@ -174,9 +174,8 @@ USAGE (begin (set! mg--repository-root (or (get-environment-variable "MG_ROOT") - (string-chomp - (call-with-input-pipe "git rev-parse --show-toplevel" - (lambda (p) (read-string #f p)))))) + (call-with-input-pipe "git rev-parse --show-toplevel" + (lambda (p) (read-chomping p))))) mg--repository-root))) ;; determine the current path relative to the root of the repository @@ -294,6 +293,10 @@ if you meant to pass these arguments to nix, please separate them with (define (repl args) (process-execute "nix" (append (list "repl" "--show-trace" (repository-root)) args))) +(define (read-chomping pipe) + (let ((s (read-string #f pipe))) + (if (eq? s #!eof) "" (string-chomp s)))) + (define (execute-run t #!optional cmd-args) (fprintf (current-error-port) "[mg] building target ~A~%" t) (let* ((expr (nix-expr-for t)) @@ -301,14 +304,11 @@ if you meant to pass these arguments to nix, please separate them with (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))))) + (let ((stdout (read-chomping pipe))) (receive (_ _ status) (process-wait pid) (when (not (eq? status 0)) - (mg-error (format "Couldn't build target ~A" t)) - (exit status)) + (mg-error (format "Couldn't build target ~A" t))) stdout))))) (fprintf (current-error-port) "[mg] running target ~A~%" t) -- cgit 1.4.1