1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 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/>.
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))
34 ;; Exercise the (guix build union) module.
37 (false-if-exception (open-connection)))
40 ;; By default, use %BOOTSTRAP-GUILE for the current system.
41 (let ((drv (package-derivation %store %bootstrap-guile)))
42 (%guile-for-build drv)))
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
54 (use-modules (guix build utils) (srfi srfi-26))
55 (let ((foo (string-append %output "/foo")))
57 (call-with-output-file (string-append foo "/one")
58 (cut display "one" <>))))
59 #:modules '((guix build utils))))
60 (two (build-expression->derivation
63 (use-modules (guix build utils) (srfi srfi-26))
64 (let ((foo (string-append %output "/foo"))
65 (bar (string-append %output "/bar")))
67 (call-with-output-file (string-append bar "/two")
68 (cut display "two" <>))
70 #:modules '((guix build utils))))
72 (use-modules (guix build union))
74 (union-build (assoc-ref %outputs "out")
75 (list (assoc-ref %build-inputs "one")
76 (assoc-ref %build-inputs "two")))))
78 (build-expression->derivation %store "union-collision-symlink"
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))
85 (call-with-input-file "foo/one" get-string-all))
87 (call-with-input-file "foo/two" get-string-all))
89 (call-with-input-file "bar/two" get-string-all))
90 (not (file-exists? "bar/one")))))))
92 (test-skip (if (and %store
94 (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
98 (test-assert "union-build"
99 (let* ((inputs (map (match-lambda
101 `(,name ,(package-derivation %store package))))
103 ;; Purposefully leave duplicate entries.
104 (append %bootstrap-inputs
105 (take %bootstrap-inputs 3))))
107 (use-modules (guix build union))
108 (union-build (assoc-ref %outputs "out")
109 (map cdr %build-inputs))))
111 (build-expression->derivation %store "union-test"
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")
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++")))
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"))))))))
137 (exit (= (test-runner-fail-count (test-runner-current)) 0))