offload: Send build logs to file descriptor 4.
* guix/scripts/offload.scm (with-error-to-port): New macro. (remote-pipe): Add #:error-port parameter. Use 'with-error-to-port' around 'open-pipe*' call. (build-log-port): New procedure. (offload): Change #:log-port to default to (build-log-port). Call 'remote-pipe' with #:error-port LOG-PORT.
This commit is contained in:
parent
19ee8c7dc5
commit
d81195bffd
|
@ -159,19 +159,35 @@ determined."
|
||||||
;; (leave (_ "failed to execute '~a': ~a~%")
|
;; (leave (_ "failed to execute '~a': ~a~%")
|
||||||
;; %lsh-command (strerror (system-error-errno args))))))
|
;; %lsh-command (strerror (system-error-errno args))))))
|
||||||
|
|
||||||
(define (remote-pipe machine mode command)
|
(define-syntax with-error-to-port
|
||||||
|
(syntax-rules ()
|
||||||
|
((_ port exp0 exp ...)
|
||||||
|
(let ((new port)
|
||||||
|
(old (current-error-port)))
|
||||||
|
(dynamic-wind
|
||||||
|
(lambda ()
|
||||||
|
(set-current-error-port new))
|
||||||
|
(lambda ()
|
||||||
|
exp0 exp ...)
|
||||||
|
(lambda ()
|
||||||
|
(set-current-error-port old)))))))
|
||||||
|
|
||||||
|
(define* (remote-pipe machine mode command
|
||||||
|
#:key (error-port (current-error-port)))
|
||||||
"Run COMMAND on MACHINE, assuming an lsh gateway has been set up."
|
"Run COMMAND on MACHINE, assuming an lsh gateway has been set up."
|
||||||
(catch 'system-error
|
(catch 'system-error
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(apply open-pipe* mode %lshg-command "-z"
|
;; Let the child inherit ERROR-PORT.
|
||||||
"-l" (build-machine-user machine)
|
(with-error-to-port error-port
|
||||||
"-p" (number->string (build-machine-port machine))
|
(apply open-pipe* mode %lshg-command "-z"
|
||||||
|
"-l" (build-machine-user machine)
|
||||||
|
"-p" (number->string (build-machine-port machine))
|
||||||
|
|
||||||
;; XXX: Remove '-i' when %LSHG-COMMAND really is lshg.
|
;; XXX: Remove '-i' when %LSHG-COMMAND really is lshg.
|
||||||
"-i" (build-machine-private-key machine)
|
"-i" (build-machine-private-key machine)
|
||||||
|
|
||||||
(build-machine-name machine)
|
(build-machine-name machine)
|
||||||
command))
|
command)))
|
||||||
(lambda args
|
(lambda args
|
||||||
(warning (_ "failed to execute '~a': ~a~%")
|
(warning (_ "failed to execute '~a': ~a~%")
|
||||||
%lshg-command (strerror (system-error-errno args)))
|
%lshg-command (strerror (system-error-errno args)))
|
||||||
|
@ -257,9 +273,18 @@ connections allowed to MACHINE."
|
||||||
;;; Offloading.
|
;;; Offloading.
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
|
(define (build-log-port)
|
||||||
|
"Return the default port where build logs should be sent. The default is
|
||||||
|
file descriptor 4, which is open by the daemon before running the offload
|
||||||
|
hook."
|
||||||
|
(let ((port (fdopen 4 "w0")))
|
||||||
|
;; Make sure file descriptor 4 isn't closed when PORT is GC'd.
|
||||||
|
(set-port-revealed! port 1)
|
||||||
|
port))
|
||||||
|
|
||||||
(define* (offload drv machine
|
(define* (offload drv machine
|
||||||
#:key print-build-trace? (max-silent-time 3600)
|
#:key print-build-trace? (max-silent-time 3600)
|
||||||
build-timeout (log-port (current-output-port)))
|
build-timeout (log-port (build-log-port)))
|
||||||
"Perform DRV on MACHINE, assuming DRV and its prerequisites are available
|
"Perform DRV on MACHINE, assuming DRV and its prerequisites are available
|
||||||
there, and write the build log to LOG-PORT. Return the exit status."
|
there, and write the build log to LOG-PORT. Return the exit status."
|
||||||
(format (current-error-port) "offloading '~a' to '~a'...~%"
|
(format (current-error-port) "offloading '~a' to '~a'...~%"
|
||||||
|
@ -276,7 +301,11 @@ there, and write the build log to LOG-PORT. Return the exit status."
|
||||||
(list (format #f "--timeout=~a"
|
(list (format #f "--timeout=~a"
|
||||||
build-timeout))
|
build-timeout))
|
||||||
'())
|
'())
|
||||||
,(derivation-file-name drv)))))
|
,(derivation-file-name drv))
|
||||||
|
|
||||||
|
;; Since 'guix build' writes the build log to its
|
||||||
|
;; stderr, everything will go directly to LOG-PORT.
|
||||||
|
#:error-port log-port)))
|
||||||
(let loop ((line (read-line pipe)))
|
(let loop ((line (read-line pipe)))
|
||||||
(unless (eof-object? line)
|
(unless (eof-object? line)
|
||||||
(display line log-port)
|
(display line log-port)
|
||||||
|
@ -597,6 +626,7 @@ This tool is meant to be used internally by 'guix-daemon'.\n"))
|
||||||
;;; Local Variables:
|
;;; Local Variables:
|
||||||
;;; eval: (put 'with-machine-lock 'scheme-indent-function 2)
|
;;; eval: (put 'with-machine-lock 'scheme-indent-function 2)
|
||||||
;;; eval: (put 'with-file-lock 'scheme-indent-function 1)
|
;;; eval: (put 'with-file-lock 'scheme-indent-function 1)
|
||||||
|
;;; eval: (put 'with-error-to-port 'scheme-indent-function 1)
|
||||||
;;; End:
|
;;; End:
|
||||||
|
|
||||||
;;; offload.scm ends here
|
;;; offload.scm ends here
|
||||||
|
|
Loading…
Reference in New Issue