refactor(tools/magrathea): introduce read-chomping helper function
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>
This commit is contained in:
parent
227dc9421f
commit
c3628af8cc
1 changed files with 8 additions and 8 deletions
|
@ -174,9 +174,8 @@ USAGE
|
||||||
(begin
|
(begin
|
||||||
(set! mg--repository-root
|
(set! mg--repository-root
|
||||||
(or (get-environment-variable "MG_ROOT")
|
(or (get-environment-variable "MG_ROOT")
|
||||||
(string-chomp
|
(call-with-input-pipe "git rev-parse --show-toplevel"
|
||||||
(call-with-input-pipe "git rev-parse --show-toplevel"
|
(lambda (p) (read-chomping p)))))
|
||||||
(lambda (p) (read-string #f p))))))
|
|
||||||
mg--repository-root)))
|
mg--repository-root)))
|
||||||
|
|
||||||
;; determine the current path relative to the root of the repository
|
;; 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)
|
(define (repl args)
|
||||||
(process-execute "nix" (append (list "repl" "--show-trace" (repository-root)) 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)
|
(define (execute-run t #!optional cmd-args)
|
||||||
(fprintf (current-error-port) "[mg] building target ~A~%" t)
|
(fprintf (current-error-port) "[mg] building target ~A~%" t)
|
||||||
(let* ((expr (nix-expr-for 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)
|
(receive (pipe _ pid)
|
||||||
;; TODO(sterni): temporary gc root
|
;; TODO(sterni): temporary gc root
|
||||||
(process "nix-build" (list "-E" expr "--no-out-link"))
|
(process "nix-build" (list "-E" expr "--no-out-link"))
|
||||||
(let ((stdout (string-chomp
|
(let ((stdout (read-chomping pipe)))
|
||||||
(let ((s (read-string #f pipe)))
|
|
||||||
(if (eq? s #!eof) "" s)))))
|
|
||||||
(receive (_ _ status)
|
(receive (_ _ status)
|
||||||
(process-wait pid)
|
(process-wait pid)
|
||||||
(when (not (eq? status 0))
|
(when (not (eq? status 0))
|
||||||
(mg-error (format "Couldn't build target ~A" t))
|
(mg-error (format "Couldn't build target ~A" t)))
|
||||||
(exit status))
|
|
||||||
stdout)))))
|
stdout)))))
|
||||||
|
|
||||||
(fprintf (current-error-port) "[mg] running target ~A~%" t)
|
(fprintf (current-error-port) "[mg] running target ~A~%" t)
|
||||||
|
|
Loading…
Reference in a new issue