Commit | Line | Data |
---|---|---|
629a064f | 1 | ;;; GNU Guix --- Functional package management for GNU |
2bf6f962 | 2 | ;;; Copyright © 2016, 2017, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
629a064f LC |
3 | ;;; |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
f68b3ba1 | 19 | (define-module (test-transformations) |
629a064f LC |
20 | #:use-module (guix tests) |
21 | #:use-module (guix store) | |
1ae33664 | 22 | #:use-module ((guix gexp) #:select (lower-object)) |
2bf6f962 | 23 | #:use-module (guix derivations) |
629a064f | 24 | #:use-module (guix packages) |
845c4401 | 25 | #:use-module (guix git-download) |
abd7a474 LC |
26 | #:use-module (guix build-system) |
27 | #:use-module (guix build-system gnu) | |
f68b3ba1 | 28 | #:use-module (guix transformations) |
629a064f | 29 | #:use-module (guix ui) |
9a2a2005 | 30 | #:use-module (guix utils) |
880916ac | 31 | #:use-module (guix git) |
904c6c42 | 32 | #:use-module (gnu packages) |
47c0f92c LC |
33 | #:use-module (gnu packages base) |
34 | #:use-module (gnu packages busybox) | |
35 | #:use-module (ice-9 match) | |
abd7a474 LC |
36 | #:use-module (srfi srfi-1) |
37 | #:use-module (srfi srfi-26) | |
629a064f LC |
38 | #:use-module (srfi srfi-64)) |
39 | ||
40 | \f | |
f68b3ba1 | 41 | (test-begin "transformations") |
629a064f LC |
42 | |
43 | (test-assert "options->transformation, no transformations" | |
44 | (let ((p (dummy-package "foo")) | |
45 | (t (options->transformation '()))) | |
1ae33664 | 46 | (eq? (t p) p))) |
629a064f LC |
47 | |
48 | (test-assert "options->transformation, with-source" | |
49 | ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm' source should | |
50 | ;; be applicable. | |
51 | (let* ((p (dummy-package "guix.scm")) | |
52 | (s (search-path %load-path "guix.scm")) | |
53 | (t (options->transformation `((with-source . ,s))))) | |
54 | (with-store store | |
1ae33664 LC |
55 | (let* ((new (t p)) |
56 | (source (run-with-store store | |
57 | (lower-object (package-source new))))) | |
629a064f | 58 | (and (not (eq? new p)) |
1ae33664 | 59 | (string=? source |
629a064f LC |
60 | (add-to-store store "guix.scm" #t |
61 | "sha256" s))))))) | |
62 | ||
7c247809 LC |
63 | (test-assert "options->transformation, with-source, replacement" |
64 | ;; Same, but this time the original package has a 'replacement' field. We | |
65 | ;; expect that replacement to be set to #f in the new package. | |
66 | (let* ((p (dummy-package "guix.scm" (replacement coreutils))) | |
67 | (s (search-path %load-path "guix.scm")) | |
68 | (t (options->transformation `((with-source . ,s))))) | |
1ae33664 LC |
69 | (let ((new (t p))) |
70 | (and (not (eq? new p)) | |
71 | (not (package-replacement new)))))) | |
7c247809 | 72 | |
9a2a2005 LC |
73 | (test-assert "options->transformation, with-source, with version" |
74 | ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source | |
75 | ;; should be applicable, and its version should be extracted. | |
76 | (let ((p (dummy-package "foo")) | |
77 | (s (search-path %load-path "guix.scm"))) | |
78 | (call-with-temporary-directory | |
79 | (lambda (directory) | |
80 | (let* ((f (string-append directory "/foo-42.0.tar.gz")) | |
81 | (t (options->transformation `((with-source . ,f))))) | |
82 | (copy-file s f) | |
83 | (with-store store | |
1ae33664 LC |
84 | (let* ((new (t p)) |
85 | (source (run-with-store store | |
86 | (lower-object (package-source new))))) | |
9a2a2005 LC |
87 | (and (not (eq? new p)) |
88 | (string=? (package-name new) (package-name p)) | |
89 | (string=? (package-version new) "42.0") | |
1ae33664 | 90 | (string=? source |
9a2a2005 LC |
91 | (add-to-store store (basename f) #t |
92 | "sha256" f)))))))))) | |
93 | ||
629a064f LC |
94 | (test-assert "options->transformation, with-source, no matches" |
95 | ;; When a transformation in not applicable, a warning must be raised. | |
96 | (let* ((p (dummy-package "foobar")) | |
97 | (s (search-path %load-path "guix.scm")) | |
98 | (t (options->transformation `((with-source . ,s))))) | |
1ae33664 LC |
99 | (let* ((port (open-output-string)) |
100 | (new (parameterize ((guix-warning-port port)) | |
101 | (t p)))) | |
102 | (and (eq? new p) | |
103 | (string-contains (get-output-string port) | |
104 | "had no effect"))))) | |
629a064f | 105 | |
3e30cdf1 LC |
106 | (test-assert "options->transformation, with-source, PKG=URI" |
107 | (let* ((p (dummy-package "foo")) | |
108 | (s (search-path %load-path "guix.scm")) | |
109 | (f (string-append "foo=" s)) | |
110 | (t (options->transformation `((with-source . ,f))))) | |
111 | (with-store store | |
1ae33664 LC |
112 | (let* ((new (t p)) |
113 | (source (run-with-store store | |
114 | (lower-object (package-source new))))) | |
3e30cdf1 LC |
115 | (and (not (eq? new p)) |
116 | (string=? (package-name new) (package-name p)) | |
117 | (string=? (package-version new) | |
118 | (package-version p)) | |
1ae33664 | 119 | (string=? source |
3e30cdf1 LC |
120 | (add-to-store store (basename s) #t |
121 | "sha256" s))))))) | |
122 | ||
123 | (test-assert "options->transformation, with-source, PKG@VER=URI" | |
124 | (let* ((p (dummy-package "foo")) | |
125 | (s (search-path %load-path "guix.scm")) | |
126 | (f (string-append "foo@42.0=" s)) | |
127 | (t (options->transformation `((with-source . ,f))))) | |
128 | (with-store store | |
1ae33664 LC |
129 | (let* ((new (t p)) |
130 | (source (run-with-store store | |
131 | (lower-object (package-source new))))) | |
3e30cdf1 LC |
132 | (and (not (eq? new p)) |
133 | (string=? (package-name new) (package-name p)) | |
134 | (string=? (package-version new) "42.0") | |
1ae33664 | 135 | (string=? source |
3e30cdf1 LC |
136 | (add-to-store store (basename s) #t |
137 | "sha256" s))))))) | |
138 | ||
47c0f92c LC |
139 | (test-assert "options->transformation, with-input" |
140 | (let* ((p (dummy-package "guix.scm" | |
904c6c42 LC |
141 | (inputs `(("foo" ,(specification->package "coreutils")) |
142 | ("bar" ,(specification->package "grep")) | |
47c0f92c LC |
143 | ("baz" ,(dummy-package "chbouib" |
144 | (native-inputs `(("x" ,grep))))))))) | |
145 | (t (options->transformation '((with-input . "coreutils=busybox") | |
146 | (with-input . "grep=findutils"))))) | |
1ae33664 LC |
147 | (let ((new (t p))) |
148 | (and (not (eq? new p)) | |
149 | (match (package-inputs new) | |
150 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
151 | (and (string=? (package-full-name dep1) | |
152 | (package-full-name busybox)) | |
153 | (string=? (package-full-name dep2) | |
154 | (package-full-name findutils)) | |
155 | (string=? (package-name dep3) "chbouib") | |
156 | (match (package-native-inputs dep3) | |
157 | ((("x" dep)) | |
158 | (string=? (package-full-name dep) | |
159 | (package-full-name findutils))))))))))) | |
47c0f92c | 160 | |
645b9df8 LC |
161 | (test-assert "options->transformation, with-graft" |
162 | (let* ((p (dummy-package "guix.scm" | |
163 | (inputs `(("foo" ,grep) | |
164 | ("bar" ,(dummy-package "chbouib" | |
165 | (native-inputs `(("x" ,grep))))))))) | |
0d7034ca | 166 | (t (options->transformation '((with-graft . "grep=findutils"))))) |
1ae33664 LC |
167 | (let ((new (t p))) |
168 | (and (not (eq? new p)) | |
169 | (match (package-inputs new) | |
170 | ((("foo" dep1) ("bar" dep2)) | |
171 | (and (string=? (package-full-name dep1) | |
172 | (package-full-name grep)) | |
173 | (string=? (package-full-name (package-replacement dep1)) | |
174 | (package-full-name findutils)) | |
175 | (string=? (package-name dep2) "chbouib") | |
176 | (match (package-native-inputs dep2) | |
177 | ((("x" dep)) | |
178 | (with-store store | |
179 | (string=? (derivation-file-name | |
180 | (package-derivation store findutils)) | |
181 | (derivation-file-name | |
182 | (package-derivation store dep))))))))))))) | |
645b9df8 | 183 | |
845c4401 LC |
184 | (test-equal "options->transformation, with-branch" |
185 | (git-checkout (url "https://example.org") | |
186 | (branch "devel") | |
187 | (recursive? #t)) | |
188 | (let* ((p (dummy-package "guix.scm" | |
189 | (inputs `(("foo" ,grep) | |
190 | ("bar" ,(dummy-package "chbouib" | |
191 | (source (origin | |
192 | (method git-fetch) | |
193 | (uri (git-reference | |
194 | (url "https://example.org") | |
195 | (commit "cabba9e"))) | |
196 | (sha256 #f))))))))) | |
197 | (t (options->transformation '((with-branch . "chbouib=devel"))))) | |
1ae33664 LC |
198 | (let ((new (t p))) |
199 | (and (not (eq? new p)) | |
200 | (match (package-inputs new) | |
201 | ((("foo" dep1) ("bar" dep2)) | |
202 | (and (string=? (package-full-name dep1) | |
203 | (package-full-name grep)) | |
204 | (string=? (package-name dep2) "chbouib") | |
205 | (package-source dep2)))))))) | |
845c4401 LC |
206 | |
207 | (test-equal "options->transformation, with-commit" | |
208 | (git-checkout (url "https://example.org") | |
209 | (commit "abcdef") | |
210 | (recursive? #t)) | |
211 | (let* ((p (dummy-package "guix.scm" | |
212 | (inputs `(("foo" ,grep) | |
213 | ("bar" ,(dummy-package "chbouib" | |
214 | (source (origin | |
215 | (method git-fetch) | |
216 | (uri (git-reference | |
217 | (url "https://example.org") | |
218 | (commit "cabba9e"))) | |
219 | (sha256 #f))))))))) | |
220 | (t (options->transformation '((with-commit . "chbouib=abcdef"))))) | |
1ae33664 LC |
221 | (let ((new (t p))) |
222 | (and (not (eq? new p)) | |
223 | (match (package-inputs new) | |
224 | ((("foo" dep1) ("bar" dep2)) | |
225 | (and (string=? (package-full-name dep1) | |
226 | (package-full-name grep)) | |
227 | (string=? (package-name dep2) "chbouib") | |
228 | (package-source dep2)))))))) | |
845c4401 | 229 | |
880916ac LC |
230 | (test-equal "options->transformation, with-git-url" |
231 | (let ((source (git-checkout (url "https://example.org") | |
232 | (recursive? #t)))) | |
233 | (list source source)) | |
234 | (let* ((p (dummy-package "guix.scm" | |
235 | (inputs `(("foo" ,grep) | |
236 | ("bar" ,(dummy-package "chbouib" | |
237 | (native-inputs `(("x" ,grep))))))))) | |
238 | (t (options->transformation '((with-git-url . "grep=https://example.org"))))) | |
1ae33664 LC |
239 | (let ((new (t p))) |
240 | (and (not (eq? new p)) | |
241 | (match (package-inputs new) | |
242 | ((("foo" dep1) ("bar" dep2)) | |
243 | (and (string=? (package-full-name dep1) | |
244 | (package-full-name grep)) | |
245 | (string=? (package-name dep2) "chbouib") | |
246 | (match (package-native-inputs dep2) | |
247 | ((("x" dep3)) | |
248 | (map package-source (list dep1 dep3))))))))))) | |
880916ac | 249 | |
14328b81 LC |
250 | (test-equal "options->transformation, with-git-url + with-branch" |
251 | ;; Combine the two options and make sure the 'with-branch' transformation | |
252 | ;; comes after the 'with-git-url' transformation. | |
253 | (let ((source (git-checkout (url "https://example.org") | |
254 | (branch "BRANCH") | |
255 | (recursive? #t)))) | |
256 | (list source source)) | |
257 | (let* ((p (dummy-package "guix.scm" | |
258 | (inputs `(("foo" ,grep) | |
259 | ("bar" ,(dummy-package "chbouib" | |
260 | (native-inputs `(("x" ,grep))))))))) | |
261 | (t (options->transformation | |
262 | (reverse '((with-git-url | |
263 | . "grep=https://example.org") | |
264 | (with-branch . "grep=BRANCH")))))) | |
1ae33664 LC |
265 | (let ((new (t p))) |
266 | (and (not (eq? new p)) | |
267 | (match (package-inputs new) | |
268 | ((("foo" dep1) ("bar" dep2)) | |
269 | (and (string=? (package-name dep1) "grep") | |
270 | (string=? (package-name dep2) "chbouib") | |
271 | (match (package-native-inputs dep2) | |
272 | ((("x" dep3)) | |
273 | (map package-source (list dep1 dep3))))))))))) | |
14328b81 | 274 | |
abd7a474 LC |
275 | (define* (depends-on-toolchain? p #:optional (toolchain "gcc-toolchain")) |
276 | "Return true if P depends on TOOLCHAIN instead of the default tool chain." | |
277 | (define toolchain-packages | |
278 | '("gcc" "binutils" "glibc" "ld-wrapper")) | |
279 | ||
280 | (define (package-name* obj) | |
281 | (and (package? obj) (package-name obj))) | |
282 | ||
283 | (match (bag-build-inputs (package->bag p)) | |
284 | (((_ (= package-name* packages) . _) ...) | |
285 | (and (not (any (cut member <> packages) toolchain-packages)) | |
286 | (member toolchain packages))))) | |
287 | ||
288 | (test-assert "options->transformation, with-c-toolchain" | |
289 | (let* ((dep0 (dummy-package "chbouib" | |
290 | (build-system gnu-build-system) | |
291 | (native-inputs `(("y" ,grep))))) | |
292 | (dep1 (dummy-package "stuff" | |
293 | (native-inputs `(("x" ,dep0))))) | |
294 | (p (dummy-package "thingie" | |
295 | (build-system gnu-build-system) | |
296 | (inputs `(("foo" ,grep) | |
297 | ("bar" ,dep1))))) | |
298 | (t (options->transformation | |
299 | '((with-c-toolchain . "chbouib=gcc-toolchain"))))) | |
300 | ;; Here we check that the transformation applies to DEP0 and all its | |
301 | ;; dependents: DEP0 must use GCC-TOOLCHAIN, DEP1 must use GCC-TOOLCHAIN | |
302 | ;; and the DEP0 that uses GCC-TOOLCHAIN, and so on. | |
1ae33664 LC |
303 | (let ((new (t p))) |
304 | (and (depends-on-toolchain? new "gcc-toolchain") | |
305 | (match (bag-build-inputs (package->bag new)) | |
306 | ((("foo" dep0) ("bar" dep1) _ ...) | |
307 | (and (depends-on-toolchain? dep1 "gcc-toolchain") | |
308 | (not (depends-on-toolchain? dep0 "gcc-toolchain")) | |
309 | (string=? (package-full-name dep0) | |
310 | (package-full-name grep)) | |
311 | (match (bag-build-inputs (package->bag dep1)) | |
312 | ((("x" dep) _ ...) | |
313 | (and (depends-on-toolchain? dep "gcc-toolchain") | |
314 | (match (bag-build-inputs (package->bag dep)) | |
315 | ((("y" dep) _ ...) ;this one is unchanged | |
316 | (eq? dep grep))))))))))))) | |
abd7a474 LC |
317 | |
318 | (test-equal "options->transformation, with-c-toolchain twice" | |
319 | (package-full-name grep) | |
320 | (let* ((dep0 (dummy-package "chbouib")) | |
321 | (dep1 (dummy-package "stuff")) | |
322 | (p (dummy-package "thingie" | |
323 | (build-system gnu-build-system) | |
324 | (inputs `(("foo" ,dep0) | |
325 | ("bar" ,dep1) | |
326 | ("baz" ,grep))))) | |
327 | (t (options->transformation | |
328 | '((with-c-toolchain . "chbouib=clang-toolchain") | |
329 | (with-c-toolchain . "stuff=clang-toolchain"))))) | |
1ae33664 LC |
330 | (let ((new (t p))) |
331 | (and (depends-on-toolchain? new "clang-toolchain") | |
332 | (match (bag-build-inputs (package->bag new)) | |
333 | ((("foo" dep0) ("bar" dep1) ("baz" dep2) _ ...) | |
334 | (and (depends-on-toolchain? dep0 "clang-toolchain") | |
335 | (depends-on-toolchain? dep1 "clang-toolchain") | |
336 | (not (depends-on-toolchain? dep2 "clang-toolchain")) | |
337 | (package-full-name dep2)))))))) | |
abd7a474 LC |
338 | |
339 | (test-assert "options->transformation, with-c-toolchain, no effect" | |
340 | (let ((p (dummy-package "thingie")) | |
341 | (t (options->transformation | |
342 | '((with-c-toolchain . "does-not-exist=gcc-toolchain"))))) | |
343 | ;; When it has no effect, '--with-c-toolchain' returns P. | |
1ae33664 | 344 | (eq? (t p) p))) |
abd7a474 | 345 | |
6aeda816 LC |
346 | (test-equal "options->transformation, with-debug-info" |
347 | '(#:strip-binaries? #f) | |
348 | (let* ((dep (dummy-package "chbouib")) | |
349 | (p (dummy-package "thingie" | |
350 | (build-system gnu-build-system) | |
351 | (inputs `(("foo" ,dep) | |
352 | ("bar" ,grep))))) | |
353 | (t (options->transformation | |
354 | '((with-debug-info . "chbouib"))))) | |
1ae33664 LC |
355 | (let ((new (t p))) |
356 | (match (package-inputs new) | |
357 | ((("foo" dep0) ("bar" dep1)) | |
358 | (and (string=? (package-full-name dep1) | |
359 | (package-full-name grep)) | |
360 | (package-arguments (package-replacement dep0)))))))) | |
6aeda816 | 361 | |
f458cfbc LC |
362 | (test-assert "options->transformation, without-tests" |
363 | (let* ((dep (dummy-package "dep")) | |
364 | (p (dummy-package "foo" | |
365 | (inputs `(("dep" ,dep))))) | |
366 | (t (options->transformation '((without-tests . "dep") | |
367 | (without-tests . "tar"))))) | |
1ae33664 LC |
368 | (let ((new (t p))) |
369 | (match (bag-direct-inputs (package->bag new)) | |
370 | ((("dep" dep) ("tar" tar) _ ...) | |
371 | ;; TODO: Check whether TAR has #:tests? #f when transformations | |
372 | ;; apply to implicit inputs. | |
373 | (equal? (package-arguments dep) | |
374 | '(#:tests? #f))))))) | |
14328b81 | 375 | |
629a064f | 376 | (test-end) |
abd7a474 LC |
377 | |
378 | ;;; Local Variables: | |
379 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) | |
380 | ;;; End: |