1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-grafts)
20 #:use-module (guix gexp)
21 #:use-module (guix monads)
22 #:use-module (guix derivations)
23 #:use-module (guix store)
24 #:use-module (guix utils)
25 #:use-module (guix grafts)
26 #:use-module (guix tests)
27 #:use-module ((gnu packages) #:select (search-bootstrap-binary))
28 #:use-module (gnu packages bootstrap)
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-64)
31 #:use-module (rnrs io ports))
34 (open-connection-for-tests))
36 (define (bootstrap-binary name)
37 (let ((bin (search-bootstrap-binary name (%current-system))))
39 (add-to-store %store name #t "sha256" bin))))
42 (bootstrap-binary "bash"))
44 (bootstrap-binary "mkdir"))
49 (test-assert "graft-derivation, grafted item is a direct dependency"
53 (symlink %output "self")
54 (call-with-output-file "text"
56 (format output "foo/~a/bar" ,%mkdir)))
57 (symlink ,%bash "sh")))
58 (orig (build-expression->derivation %store "grafted" build
59 #:inputs `(("a" ,%bash)
61 (one (add-text-to-store %store "bash" "fake bash"))
62 (two (build-expression->derivation %store "mkdir"
63 '(call-with-output-file %output
65 (display "fake mkdir" port)))))
66 (grafted (graft-derivation %store orig
72 (replacement two))))))
73 (and (build-derivations %store (list grafted))
74 (let ((two (derivation->output-path two))
75 (grafted (derivation->output-path grafted)))
76 (and (string=? (format #f "foo/~a/bar" two)
77 (call-with-input-file (string-append grafted "/text")
79 (string=? (readlink (string-append grafted "/sh")) one)
80 (string=? (readlink (string-append grafted "/self"))
83 (test-assert "graft-derivation, grafted item uses a different name"
87 (symlink %output "self")
88 (symlink ,%bash "sh")))
89 (orig (build-expression->derivation %store "grafted" build
90 #:inputs `(("a" ,%bash))))
91 (repl (add-text-to-store %store "BaSH" "fake bash"))
92 (grafted (graft-derivation %store orig
95 (replacement repl))))))
96 (and (build-derivations %store (list grafted))
97 (let ((grafted (derivation->output-path grafted)))
98 (and (string=? (readlink (string-append grafted "/sh")) repl)
99 (string=? (readlink (string-append grafted "/self"))
102 ;; Make sure 'derivation-file-name' always gets to see an absolute file name.
103 (fluid-set! %file-port-name-canonicalization 'absolute)
105 (test-assert "graft-derivation, grafted item is an indirect dependency"
106 (let* ((build `(begin
109 (symlink %output "self")
110 (call-with-output-file "text"
112 (format output "foo/~a/bar" ,%mkdir)))
113 (symlink ,%bash "sh")))
114 (dep (build-expression->derivation %store "dep" build
115 #:inputs `(("a" ,%bash)
117 (orig (build-expression->derivation %store "thing"
119 (assoc-ref %build-inputs
122 #:inputs `(("dep" ,dep))))
123 (one (add-text-to-store %store "bash" "fake bash"))
124 (two (build-expression->derivation %store "mkdir"
125 '(call-with-output-file %output
127 (display "fake mkdir" port)))))
128 (grafted (graft-derivation %store orig
134 (replacement two))))))
135 (and (build-derivations %store (list grafted))
136 (let* ((two (derivation->output-path two))
137 (grafted (derivation->output-path grafted))
138 (dep (readlink grafted)))
139 (and (string=? (format #f "foo/~a/bar" two)
140 (call-with-input-file (string-append dep "/text")
142 (string=? (readlink (string-append dep "/sh")) one)
143 (string=? (readlink (string-append dep "/self")) dep)
144 (equal? (references %store grafted) (list dep))
147 (references %store dep)))))))
149 (test-assert "graft-derivation, preserve empty directories"
150 (run-with-store %store
151 (mlet* %store-monad ((fake (text-file "bash" "Fake bash."))
155 (drv (gexp->derivation
157 (with-imported-modules '((guix build utils))
159 (use-modules (guix build utils))
160 (mkdir-p (string-append #$output
163 (string-append #$output
165 (grafted ((store-lift graft-derivation) drv
167 (_ (built-derivations (list grafted)))
168 (out -> (derivation->output-path grafted)))
169 (return (and (string=? (readlink (string-append out "/bash"))
171 (file-is-directory? (string-append out "/a/b/c/d")))))))
173 (test-assert "graft-derivation, no dependencies on grafted output"
174 (run-with-store %store
175 (mlet* %store-monad ((fake (text-file "bash" "Fake bash."))
179 (drv (gexp->derivation "foo" #~(mkdir #$output)))
180 (grafted ((store-lift graft-derivation) drv
182 (return (eq? grafted drv)))))
184 (test-assert "graft-derivation, multiple outputs"
185 (let* ((build `(begin
186 (symlink (assoc-ref %build-inputs "a")
187 (assoc-ref %outputs "one"))
188 (symlink (assoc-ref %outputs "one")
189 (assoc-ref %outputs "two"))))
190 (orig (build-expression->derivation %store "grafted" build
191 #:inputs `(("a" ,%bash))
192 #:outputs '("one" "two")))
193 (repl (add-text-to-store %store "bash" "fake bash"))
194 (grafted (graft-derivation %store orig
197 (replacement repl))))))
198 (and (build-derivations %store (list grafted))
199 (let ((one (derivation->output-path grafted "one"))
200 (two (derivation->output-path grafted "two")))
201 (and (string=? (readlink one) repl)
202 (string=? (readlink two) one))))))
204 (test-assert "graft-derivation, renaming" ;<http://bugs.gnu.org/23132>
205 (let* ((build `(begin
206 (use-modules (guix build utils))
207 (mkdir-p (string-append (assoc-ref %outputs "out") "/"
208 (assoc-ref %build-inputs "in")))))
209 (orig (build-expression->derivation %store "thing-to-graft" build
210 #:modules '((guix build utils))
211 #:inputs `(("in" ,%bash))))
212 (repl (add-text-to-store %store "bash" "fake bash"))
213 (grafted (graft-derivation %store orig
216 (replacement repl))))))
217 (and (build-derivations %store (list grafted))
218 (let ((out (derivation->output-path grafted)))
219 (file-is-directory? (string-append out "/" repl))))))