about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2023-06-22T11·40+0200
committerclbot <clbot@tvl.fyi>2023-06-23T16·47+0000
commitc3628af8cc4ec79dc03b47db724b29da7b3d47ba (patch)
tree0a3933a154e0e09b3d94440e968c919ba9a5f6d7 /tools
parent227dc9421f38999cbb59ad024c7f636464e79134 (diff)
refactor(tools/magrathea): introduce read-chomping helper function r/6349
Change-Id: I2ee6903686fd210755c40eb9555c938e8c1ab52b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8843
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tools')
-rw-r--r--tools/magrathea/mg.scm16
1 files 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)