diff --git a/guix/derivations.scm b/guix/derivations.scm index 186d7a3f8f..caa76bd16c 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -352,6 +352,16 @@ (define (dependencies drv) (#f #f) ((key . value) value))))) +(define (dependencies-of-substitutables substitutables inputs) + "Return the subset of INPUTS whose output file names is among the references +of SUBSTITUTABLES." + (let ((items (fold set-insert (set) + (append-map substitutable-references substitutables)))) + (filter (lambda (input) + (any (cut set-contains? items <>) + (derivation-input-output-paths input))) + inputs))) + (define* (derivation-build-plan store inputs #:key (mode (build-mode normal)) @@ -391,7 +401,9 @@ (define (input-substitutable-info input) (() (values build substitute)) ((input rest ...) - (let ((key (derivation-input-key input))) + (let ((key (derivation-input-key input)) + (deps (derivation-inputs + (derivation-input-derivation input)))) (cond ((set-contains? visited key) (loop rest build substitute visited)) ((input-built? input) @@ -400,16 +412,17 @@ (define (input-substitutable-info input) ((input-substitutable-info input) => (lambda (substitutables) - (loop rest build + (loop (append (dependencies-of-substitutables substitutables + deps) + rest) + build (append substitutables substitute) (set-insert key visited)))) (else - (let ((deps (derivation-inputs - (derivation-input-derivation input)))) - (loop (append deps rest) - (cons (derivation-input-derivation input) build) - substitute - (set-insert key visited)))))))))) + (loop (append deps rest) + (cons (derivation-input-derivation input) build) + substitute + (set-insert key visited))))))))) (define-deprecated (derivation-prerequisites-to-build store drv #:rest rest) derivation-build-plan diff --git a/guix/ui.scm b/guix/ui.scm index 6d243ef041..2ce82ff658 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -844,18 +844,6 @@ (define substitutable-info #:mode mode #:substitutable-info substitutable-info)) - ((download) ; add the references of DOWNLOAD - (if use-substitutes? - (delete-duplicates - (append download - (filter-map (lambda (item) - (if (valid-path? store item) - #f - (substitutable-info item))) - (append-map - substitutable-references - download)))) - download)) ((graft hook build) (match (fold (lambda (drv acc) (let ((file (derivation-file-name drv))) diff --git a/tests/derivations.scm b/tests/derivations.scm index d173a78906..7be7726163 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm @@ -896,6 +896,35 @@ (define %coreutils (((= derivation-file-name build)) (string=? build (derivation-file-name drv))))))))) +(test-assert "derivation-build-plan and substitutes, non-substitutable dep" + (with-store store + (let* ((drv1 (build-expression->derivation store "prereq-no-subst" + (random 1000) + #:substitutable? #f)) + (drv2 (build-expression->derivation store "substitutable" + (random 1000) + #:inputs `(("dep" ,drv1))))) + + ;; Make sure substitutes are usable. + (set-build-options store #:use-substitutes? #t + #:substitute-urls (%test-substitute-urls)) + + (with-derivation-narinfo drv2 + (sha256 => (make-bytevector 32 0)) + (references => (list (derivation->output-path drv1))) + + (let-values (((build download) + (derivation-build-plan store + (list (derivation-input drv2))))) + ;; Although DRV2 is available as a substitute, we must build its + ;; dependency, DRV1, due to #:substitutable? #f. + (and (match download + (((= substitutable-path item)) + (string=? item (derivation->output-path drv2)))) + (match build + (((= derivation-file-name build)) + (string=? build (derivation-file-name drv1)))))))))) + (test-assert "derivation-build-plan and substitutes, local build" (with-store store (let* ((drv (build-expression->derivation store "prereq-subst-local"