guix build: Set the build options early.

This fixes a bug whereby, with grafts leading to builds very early,
build options such as --substitute-urls would not be taken into account
yet.

Reported by Andreas Enge <andreas@enge.fr>.

* guix/scripts/build.scm (guix-build): Move 'opts' to the beginning.
Use 'with-store' instead of 'open-connection'.  Call
'set-build-options-from-command-line' right after 'with-store'.
This commit is contained in:
Ludovic Courtès 2016-03-04 17:50:30 +01:00
parent eda0522aab
commit c8f9f24776
1 changed files with 50 additions and 46 deletions

View File

@ -634,55 +634,59 @@ needed."
;;; ;;;
(define (guix-build . args) (define (guix-build . args)
(define opts
(parse-command-line args %options
(list %default-options)))
(with-error-handling (with-error-handling
;; Ask for absolute file names so that .drv file names passed from the ;; Ask for absolute file names so that .drv file names passed from the
;; user to 'read-derivation' are absolute when it returns. ;; user to 'read-derivation' are absolute when it returns.
(with-fluids ((%file-port-name-canonicalization 'absolute)) (with-fluids ((%file-port-name-canonicalization 'absolute))
(let* ((opts (parse-command-line args %options (with-store store
(list %default-options))) ;; Set the build options before we do anything else.
(store (open-connection))
(mode (assoc-ref opts 'build-mode))
(drv (options->derivations store opts))
(urls (map (cut string-append <> "/log")
(if (assoc-ref opts 'substitutes?)
(or (assoc-ref opts 'substitute-urls)
;; XXX: This does not necessarily match the
;; daemon's substitute URLs.
%default-substitute-urls)
'())))
(items (filter-map (match-lambda
(('argument . (? store-path? file))
file)
(_ #f))
opts))
(roots (filter-map (match-lambda
(('gc-root . root) root)
(_ #f))
opts)))
(set-build-options-from-command-line store opts) (set-build-options-from-command-line store opts)
(unless (assoc-ref opts 'log-file?)
(show-what-to-build store drv
#:use-substitutes? (assoc-ref opts 'substitutes?)
#:dry-run? (assoc-ref opts 'dry-run?)
#:mode mode))
(cond ((assoc-ref opts 'log-file?) (let* ((mode (assoc-ref opts 'build-mode))
(for-each (cut show-build-log store <> urls) (drv (options->derivations store opts))
(delete-duplicates (urls (map (cut string-append <> "/log")
(append (map derivation-file-name drv) (if (assoc-ref opts 'substitutes?)
items)))) (or (assoc-ref opts 'substitute-urls)
((assoc-ref opts 'derivations-only?) ;; XXX: This does not necessarily match the
(format #t "~{~a~%~}" (map derivation-file-name drv)) ;; daemon's substitute URLs.
(for-each (cut register-root store <> <>) %default-substitute-urls)
(map (compose list derivation-file-name) drv) '())))
roots)) (items (filter-map (match-lambda
((not (assoc-ref opts 'dry-run?)) (('argument . (? store-path? file))
(and (build-derivations store drv mode) file)
(for-each show-derivation-outputs drv) (_ #f))
(for-each (cut register-root store <> <>) opts))
(map (lambda (drv) (roots (filter-map (match-lambda
(map cdr (('gc-root . root) root)
(derivation->output-paths drv))) (_ #f))
drv) opts)))
roots))))))))
(unless (assoc-ref opts 'log-file?)
(show-what-to-build store drv
#:use-substitutes? (assoc-ref opts 'substitutes?)
#:dry-run? (assoc-ref opts 'dry-run?)
#:mode mode))
(cond ((assoc-ref opts 'log-file?)
(for-each (cut show-build-log store <> urls)
(delete-duplicates
(append (map derivation-file-name drv)
items))))
((assoc-ref opts 'derivations-only?)
(format #t "~{~a~%~}" (map derivation-file-name drv))
(for-each (cut register-root store <> <>)
(map (compose list derivation-file-name) drv)
roots))
((not (assoc-ref opts 'dry-run?))
(and (build-derivations store drv mode)
(for-each show-derivation-outputs drv)
(for-each (cut register-root store <> <>)
(map (lambda (drv)
(map cdr
(derivation->output-paths drv)))
drv)
roots)))))))))