gnu: guix: Update to 0.7.
[jackhill/guix/guix.git] / tests / union.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
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
19
20 (define-module (test-union)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix packages)
25 #:use-module (guix build union)
26 #:use-module ((guix build utils)
27 #:select (with-directory-excursion directory-exists?))
28 #:use-module (gnu packages bootstrap)
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-64)
31 #:use-module (rnrs io ports)
32 #:use-module (ice-9 match))
33
34 ;; Exercise the (guix build union) module.
35
36 (define %store
37 (false-if-exception (open-connection)))
38
39 (when %store
40 ;; By default, use %BOOTSTRAP-GUILE for the current system.
41 (let ((drv (package-derivation %store %bootstrap-guile)))
42 (%guile-for-build drv)))
43
44 \f
45 (test-begin "union")
46
47 (test-assert "union-build with symlink to directory"
48 ;; http://bugs.gnu.org/17083
49 ;; Here both ONE and TWO provide an element called 'foo', but in ONE it's a
50 ;; directory whereas in TWO it's a symlink to a directory.
51 (let* ((one (build-expression->derivation
52 %store "one"
53 '(begin
54 (use-modules (guix build utils) (srfi srfi-26))
55 (let ((foo (string-append %output "/foo")))
56 (mkdir-p foo)
57 (call-with-output-file (string-append foo "/one")
58 (cut display "one" <>))))
59 #:modules '((guix build utils))))
60 (two (build-expression->derivation
61 %store "two"
62 '(begin
63 (use-modules (guix build utils) (srfi srfi-26))
64 (let ((foo (string-append %output "/foo"))
65 (bar (string-append %output "/bar")))
66 (mkdir-p bar)
67 (call-with-output-file (string-append bar "/two")
68 (cut display "two" <>))
69 (symlink "bar" foo)))
70 #:modules '((guix build utils))))
71 (builder '(begin
72 (use-modules (guix build union))
73
74 (union-build (assoc-ref %outputs "out")
75 (list (assoc-ref %build-inputs "one")
76 (assoc-ref %build-inputs "two")))))
77 (drv
78 (build-expression->derivation %store "union-collision-symlink"
79 builder
80 #:inputs `(("one" ,one) ("two" ,two))
81 #:modules '((guix build union)))))
82 (and (build-derivations %store (list drv))
83 (with-directory-excursion (pk (derivation->output-path drv))
84 (and (string=? "one"
85 (call-with-input-file "foo/one" get-string-all))
86 (string=? "two"
87 (call-with-input-file "foo/two" get-string-all))
88 (string=? "two"
89 (call-with-input-file "bar/two" get-string-all))
90 (not (file-exists? "bar/one")))))))
91
92 (test-skip (if (and %store
93 (false-if-exception
94 (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
95 0
96 1))
97
98 (test-assert "union-build"
99 (let* ((inputs (map (match-lambda
100 ((name package)
101 `(,name ,(package-derivation %store package))))
102
103 ;; Purposefully leave duplicate entries.
104 (append %bootstrap-inputs
105 (take %bootstrap-inputs 3))))
106 (builder `(begin
107 (use-modules (guix build union))
108 (union-build (assoc-ref %outputs "out")
109 (map cdr %build-inputs))))
110 (drv
111 (build-expression->derivation %store "union-test"
112 builder
113 #:inputs inputs
114 #:modules '((guix build union)))))
115 (and (build-derivations %store (list (pk 'drv drv)))
116 (with-directory-excursion (derivation->output-path drv)
117 (and (file-exists? "bin/touch")
118 (file-exists? "bin/gcc")
119 (file-exists? "bin/ld")
120 (file-exists? "lib/libc.so")
121 (directory-exists? "lib/gcc")
122 (file-exists? "include/unistd.h")
123
124 ;; The 'include/c++' sub-directory is only found in
125 ;; gcc-bootstrap, so it should be unified in a
126 ;; straightforward way, without traversing it.
127 (eq? 'symlink (stat:type (lstat "include/c++")))
128
129 ;; Conversely, several inputs have a 'bin' sub-directory, so
130 ;; unifying it requires traversing them all, and creating a
131 ;; new 'bin' sub-directory in the profile.
132 (eq? 'directory (stat:type (lstat "bin"))))))))
133
134 (test-end)
135
136 \f
137 (exit (= (test-runner-fail-count (test-runner-current)) 0))