Subject: [bug#75810] [PATCH v5 10/14] tests: Add missing derivation inputs.

From: Ludovic Courtès <[email-masked]>
Date: Fri, 14 Mar 2025 18:48:07 +0100

These missing inputs go unnoticed when running ‘guix-daemon
--disable-chroot’ but are immediately visible otherwise.

* tests/derivations.scm ("fixed-output derivation"): Add %BASH to #:sources.
("fixed-output derivation: output paths are equal"):
("fixed-output derivation, recursive"):
("derivation with a fixed-output input"):
("derivation with duplicate fixed-output inputs"):
("derivation with equivalent fixed-output inputs"):
("build derivation with coreutils"): Likewise.
* tests/packages.scm (bootstrap-binary): New procedure.
("package-source-derivation, origin, sha512"): Use it instead of
‘search-bootstrap-binary’ and add BASH to #:sources.
("package-source-derivation, origin, sha3-512"): Likewise.

Change-Id: I4c9087df23c47729a3aff15e9e1435b7266e36e2
---
 tests/derivations.scm | 24 +++++++++++++++---------
 tests/packages.scm    | 13 +++++++++----
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/tests/derivations.scm b/tests/derivations.scm
index 72ea9aa9cc..f30f05474e 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012-2024 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2012-2025 Ludovic Courtès <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -443,7 +443,7 @@ (define* (directory-contents dir #:optional (slurp get-bytevector-all))
                                      (string-append
                                       "fixed-" (symbol->string hash-algorithm))
                                      %bash `(,builder)
-                                     #:sources `(,builder) ;optional
+                                     #:sources (list %bash builder)
                                      #:hash hash
                                      #:hash-algo hash-algorithm)))
            (build-derivations %store (list drv))
@@ -462,9 +462,11 @@ (define* (directory-contents dir #:optional (slurp get-bytevector-all))
          (hash       (gcrypt:sha256 (string->utf8 "hello")))
          (drv1       (derivation %store "fixed"
                                  %bash `(,builder1)
+                                 #:sources (list %bash builder1)
                                  #:hash hash #:hash-algo 'sha256))
          (drv2       (derivation %store "fixed"
                                  %bash `(,builder2)
+                                 #:sources (list %bash builder2)
                                  #:hash hash #:hash-algo 'sha256))
          (succeeded? (build-derivations %store (list drv1 drv2))))
     (and succeeded?
@@ -477,7 +479,7 @@ (define* (directory-contents dir #:optional (slurp get-bytevector-all))
          (hash       (gcrypt:sha256 (string->utf8 "hello")))
          (drv        (derivation %store "fixed-rec"
                                  %bash `(,builder)
-                                 #:sources (list builder)
+                                 #:sources (list %bash builder)
                                  #:hash (base32 "0sg9f58l1jj88w6pdrfdpj5x9b1zrwszk84j81zvby36q9whhhqa")
                                  #:hash-algo 'sha256
                                  #:recursive? #t))
@@ -511,9 +513,11 @@ (define* (directory-contents dir #:optional (slurp get-bytevector-all))
          (hash       (gcrypt:sha256 (string->utf8 "hello")))
          (fixed1     (derivation %store "fixed"
                                  %bash `(,builder1)
+                                 #:sources (list %bash builder1)
                                  #:hash hash #:hash-algo 'sha256))
          (fixed2     (derivation %store "fixed"
                                  %bash `(,builder2)
+                                 #:sources (list %bash builder2)
                                  #:hash hash #:hash-algo 'sha256))
          (fixed-out  (derivation->output-path fixed1))
          (builder3   (add-text-to-store
@@ -548,9 +552,11 @@ (define* (directory-contents dir #:optional (slurp get-bytevector-all))
          (hash       (gcrypt:sha256 (string->utf8 "hello")))
          (fixed1     (derivation %store "fixed"
                                  %bash `(,builder1)
+                                 #:sources (list %bash builder1)
                                  #:hash hash #:hash-algo 'sha256))
          (fixed2     (derivation %store "fixed"
                                  %bash `(,builder2)
+                                 #:sources (list %bash builder2)
                                  #:hash hash #:hash-algo 'sha256))
          (builder3   (add-text-to-store %store "builder.sh"
                                         "echo fake builder"))
@@ -580,21 +586,21 @@ (define* (directory-contents dir #:optional (slurp get-bytevector-all))
                                       '()))
          (hash     (gcrypt:sha256 (string->utf8 "hello")))
          (drv1     (derivation %store "fixed" %bash (list builder1)
-                               #:sources (list builder1)
+                               #:sources (list %bash builder1)
                                #:hash hash #:hash-algo 'sha256))
          (drv2     (derivation %store "fixed" %bash (list builder2)
-                               #:sources (list builder2)
+                               #:sources (list %bash builder2)
                                #:hash hash #:hash-algo 'sha256))
          (drv3a    (derivation %store "fixed-user" %bash (list builder3)
                                #:outputs '("one" "two")
-                               #:sources (list builder3)
+                               #:sources (list %bash builder3)
                                #:inputs (list (derivation-input drv1))))
          (drv3b    (derivation %store "fixed-user" %bash (list builder3)
                                #:outputs '("one" "two")
-                               #:sources (list builder3)
+                               #:sources (list %bash builder3)
                                #:inputs (list (derivation-input drv2))))
          (drv4     (derivation %store "fixed-user-user" %bash (list builder1)
-                               #:sources (list builder1)
+                               #:sources (list %bash builder1)
                                #:inputs (list (derivation-input drv3a '("one"))
                                               (derivation-input drv3b '("two"))))))
     (match (derivation-inputs drv4)
@@ -878,7 +884,7 @@ (define %coreutils
                                     ,(string-append
                                       (derivation->output-path %coreutils)
                                       "/bin")))
-                      #:sources (list builder)
+                      #:sources (list %bash builder)
                       #:inputs (list (derivation-input %coreutils))))
          (succeeded?
           (build-derivations %store (list drv))))
diff --git a/tests/packages.scm b/tests/packages.scm
index 50c1cab915..f56c63128d 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -80,6 +80,11 @@ (define %store
 ;; When grafting, do not add dependency on 'glibc-utf8-locales'.
 (%graft-with-utf8-locale? #f)
 
+(define (bootstrap-binary name)
+  (let ((bin (search-bootstrap-binary name (%current-system))))
+    (and %store
+         (add-to-store %store name #t "sha256" bin))))
+
 
 (test-begin "packages")
 
@@ -609,14 +614,14 @@ (define %store
 
 (test-equal "package-source-derivation, origin, sha512"
   "hello"
-  (let* ((bash    (search-bootstrap-binary "bash" (%current-system)))
+  (let* ((bash    (bootstrap-binary "bash"))
          (builder (add-text-to-store %store "my-fixed-builder.sh"
                                      "echo -n hello > $out" '()))
          (method  (lambda* (url hash-algo hash #:optional name
                                 #:rest rest)
                     (and (eq? hash-algo 'sha512)
                          (raw-derivation name bash (list builder)
-                                         #:sources (list builder)
+                                         #:sources (list bash builder)
                                          #:hash hash
                                          #:hash-algo hash-algo))))
          (source  (origin
@@ -635,14 +640,14 @@ (define %store
 
 (test-equal "package-source-derivation, origin, sha3-512"
   "hello, sha3"
-  (let* ((bash    (search-bootstrap-binary "bash" (%current-system)))
+  (let* ((bash    (bootstrap-binary "bash"))
          (builder (add-text-to-store %store "my-fixed-builder.sh"
                                      "echo -n hello, sha3 > $out" '()))
          (method  (lambda* (url hash-algo hash #:optional name
                                 #:rest rest)
                     (and (eq? hash-algo 'sha3-512)
                          (raw-derivation name bash (list builder)
-                                         #:sources (list builder)
+                                         #:sources (list bash builder)
                                          #:hash hash
                                          #:hash-algo hash-algo))))
          (source  (origin
-- 
2.48.1