guix-build: Add `--cores'.
* guix-build.in (leave): New macro, formerly in `guix-build'. (show-help): Document `--cores'. (%options): Add `--cores'. (guix-build): Remove `leave' macro from here. Pass the `cores' option value to `set-build-options'.master
parent
febaa88569
commit
fa14d96e6f
144
guix-build.in
144
guix-build.in
|
@ -64,6 +64,12 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \
|
||||||
;; Alist of default option values.
|
;; Alist of default option values.
|
||||||
'())
|
'())
|
||||||
|
|
||||||
|
(define-syntax-rule (leave fmt args ...)
|
||||||
|
"Format FMT and ARGS to the error port and exit."
|
||||||
|
(begin
|
||||||
|
(format (current-error-port) fmt args ...)
|
||||||
|
(exit 1)))
|
||||||
|
|
||||||
(define (show-version)
|
(define (show-version)
|
||||||
(display "guix-build (@PACKAGE_NAME@) @PACKAGE_VERSION@\n"))
|
(display "guix-build (@PACKAGE_NAME@) @PACKAGE_VERSION@\n"))
|
||||||
|
|
||||||
|
@ -76,6 +82,8 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
|
||||||
-K, --keep-failed keep build tree of failed builds"))
|
-K, --keep-failed keep build tree of failed builds"))
|
||||||
(display (_ "
|
(display (_ "
|
||||||
-n, --dry-run do not build the derivations"))
|
-n, --dry-run do not build the derivations"))
|
||||||
|
(display (_ "
|
||||||
|
-c, --cores=N allow the use of up to N CPU cores for the build"))
|
||||||
(newline)
|
(newline)
|
||||||
(display (_ "
|
(display (_ "
|
||||||
-h, --help display this help and exit"))
|
-h, --help display this help and exit"))
|
||||||
|
@ -104,6 +112,12 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
|
||||||
(option '(#\K "keep-failed") #f #f
|
(option '(#\K "keep-failed") #f #f
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'keep-failed? #t result)))
|
(alist-cons 'keep-failed? #t result)))
|
||||||
|
(option '(#\c "cores") #t #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(let ((c (false-if-exception (string->number arg))))
|
||||||
|
(if c
|
||||||
|
(alist-cons 'cores c result)
|
||||||
|
(leave (_ "~a: not a number~%") arg)))))
|
||||||
(option '(#\n "dry-run") #f #F
|
(option '(#\n "dry-run") #f #F
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'dry-run? #t result)))))
|
(alist-cons 'dry-run? #t result)))))
|
||||||
|
@ -114,74 +128,70 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(define (guix-build . args)
|
(define (guix-build . args)
|
||||||
(let-syntax ((leave (syntax-rules ()
|
(define (parse-options)
|
||||||
((_ fmt args ...)
|
;; Return the alist of option values.
|
||||||
(begin
|
(args-fold args %options
|
||||||
(format (current-error-port) fmt args ...)
|
(lambda (opt name arg result)
|
||||||
(exit 1))))))
|
(leave (_ "~A: unrecognized option~%") opt))
|
||||||
(define (parse-options)
|
(lambda (arg result)
|
||||||
;; Return the alist of option values.
|
(alist-cons 'argument arg result))
|
||||||
(args-fold args %options
|
%default-options))
|
||||||
(lambda (opt name arg result)
|
|
||||||
(leave (_ "~A: unrecognized option") opt))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
|
|
||||||
(setlocale LC_ALL "")
|
(setlocale LC_ALL "")
|
||||||
(textdomain "guix")
|
(textdomain "guix")
|
||||||
(setvbuf (current-output-port) _IOLBF)
|
(setvbuf (current-output-port) _IOLBF)
|
||||||
(setvbuf (current-error-port) _IOLBF)
|
(setvbuf (current-error-port) _IOLBF)
|
||||||
|
|
||||||
(let* ((opts (parse-options))
|
(let* ((opts (parse-options))
|
||||||
(drv (filter-map (match-lambda
|
(drv (filter-map (match-lambda
|
||||||
(('expression . exp)
|
(('expression . exp)
|
||||||
(derivations-from-package-expressions exp))
|
(derivations-from-package-expressions exp))
|
||||||
(('argument . (? derivation-path? drv))
|
(('argument . (? derivation-path? drv))
|
||||||
drv)
|
drv)
|
||||||
(('argument . (? string? x))
|
(('argument . (? string? x))
|
||||||
(match (find-packages-by-name x)
|
(match (find-packages-by-name x)
|
||||||
((p _ ...)
|
((p _ ...)
|
||||||
(package-derivation %store p))
|
(package-derivation %store p))
|
||||||
(_
|
(_
|
||||||
(leave (_ "~A: unknown package") x))))
|
(leave (_ "~A: unknown package~%") x))))
|
||||||
(_ #f))
|
(_ #f))
|
||||||
opts))
|
opts))
|
||||||
(req (append-map (lambda (drv-path)
|
(req (append-map (lambda (drv-path)
|
||||||
(let ((d (call-with-input-file drv-path
|
(let ((d (call-with-input-file drv-path
|
||||||
read-derivation)))
|
read-derivation)))
|
||||||
(derivation-prerequisites-to-build %store d)))
|
(derivation-prerequisites-to-build %store d)))
|
||||||
drv))
|
drv))
|
||||||
(req* (delete-duplicates
|
(req* (delete-duplicates
|
||||||
(append (remove (compose (cut valid-path? %store <>)
|
(append (remove (compose (cut valid-path? %store <>)
|
||||||
derivation-path->output-path)
|
derivation-path->output-path)
|
||||||
drv)
|
drv)
|
||||||
(map derivation-input-path req)))))
|
(map derivation-input-path req)))))
|
||||||
(if (assoc-ref opts 'dry-run?)
|
(if (assoc-ref opts 'dry-run?)
|
||||||
(format (current-error-port)
|
(format (current-error-port)
|
||||||
(N_ "~:[the following derivation would be built:~%~{ ~a~%~}~;~]"
|
(N_ "~:[the following derivation would be built:~%~{ ~a~%~}~;~]"
|
||||||
"~:[the following derivations would be built:~%~{ ~a~%~}~;~]"
|
"~:[the following derivations would be built:~%~{ ~a~%~}~;~]"
|
||||||
(length req*))
|
(length req*))
|
||||||
(null? req*) req*)
|
(null? req*) req*)
|
||||||
(format (current-error-port)
|
(format (current-error-port)
|
||||||
(N_ "~:[the following derivation will be built:~%~{ ~a~%~}~;~]"
|
(N_ "~:[the following derivation will be built:~%~{ ~a~%~}~;~]"
|
||||||
"~:[the following derivations will be built:~%~{ ~a~%~}~;~]"
|
"~:[the following derivations will be built:~%~{ ~a~%~}~;~]"
|
||||||
(length req*))
|
(length req*))
|
||||||
(null? req*) req*))
|
(null? req*) req*))
|
||||||
|
|
||||||
;; TODO: Add more options.
|
;; TODO: Add more options.
|
||||||
(set-build-options %store
|
(set-build-options %store
|
||||||
#:keep-failed? (assoc-ref opts 'keep-failed?))
|
#:keep-failed? (assoc-ref opts 'keep-failed?)
|
||||||
|
#:build-cores (or (assoc-ref opts 'cores) 1))
|
||||||
|
|
||||||
(or (assoc-ref opts 'dry-run?)
|
(or (assoc-ref opts 'dry-run?)
|
||||||
(and (build-derivations %store drv)
|
(and (build-derivations %store drv)
|
||||||
(for-each (lambda (d)
|
(for-each (lambda (d)
|
||||||
(let ((drv (call-with-input-file d
|
(let ((drv (call-with-input-file d
|
||||||
read-derivation)))
|
read-derivation)))
|
||||||
(format #t "~{~a~%~}"
|
(format #t "~{~a~%~}"
|
||||||
(map (match-lambda
|
(map (match-lambda
|
||||||
((out-name . out)
|
((out-name . out)
|
||||||
(derivation-path->output-path
|
(derivation-path->output-path
|
||||||
d out-name)))
|
d out-name)))
|
||||||
(derivation-outputs drv)))))
|
(derivation-outputs drv)))))
|
||||||
drv))))))
|
drv)))))
|
||||||
|
|
Reference in New Issue