Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
a53a9aed | 2 | ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org> |
c8c88afa | 3 | ;;; |
233e7676 | 4 | ;;; This file is part of GNU Guix. |
c8c88afa | 5 | ;;; |
233e7676 | 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
c8c88afa LC |
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 | ;;; | |
233e7676 | 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
c8c88afa LC |
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 | |
233e7676 | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
c8c88afa LC |
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?)) | |
1ffa7090 | 28 | #:use-module (gnu packages bootstrap) |
97d3998e | 29 | #:use-module (srfi srfi-1) |
c8c88afa | 30 | #:use-module (srfi srfi-64) |
a53a9aed | 31 | #:use-module (rnrs io ports) |
c8c88afa LC |
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 | ||
c8c88afa LC |
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 | ||
a53a9aed LC |
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 | ||
ad1ebab3 LC |
92 | (test-skip (if (and %store |
93 | (false-if-exception | |
94 | (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))) | |
95 | 0 | |
96 | 1)) | |
c8c88afa LC |
97 | |
98 | (test-assert "union-build" | |
99 | (let* ((inputs (map (match-lambda | |
100 | ((name package) | |
101 | `(,name ,(package-derivation %store package)))) | |
62112230 LC |
102 | |
103 | ;; Purposefully leave duplicate entries. | |
104 | (append %bootstrap-inputs | |
105 | (take %bootstrap-inputs 3)))) | |
c8c88afa LC |
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" | |
dd1a5a15 LC |
112 | builder |
113 | #:inputs inputs | |
c8c88afa LC |
114 | #:modules '((guix build union))))) |
115 | (and (build-derivations %store (list (pk 'drv drv))) | |
59688fc4 | 116 | (with-directory-excursion (derivation->output-path drv) |
c8c88afa LC |
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") | |
43dd9202 LC |
122 | (file-exists? "include/unistd.h") |
123 | ||
127ed6a9 LC |
124 | ;; The 'include/c++' sub-directory is only found in |
125 | ;; gcc-bootstrap, so it should be unified in a | |
43dd9202 | 126 | ;; straightforward way, without traversing it. |
127ed6a9 | 127 | (eq? 'symlink (stat:type (lstat "include/c++"))) |
43dd9202 LC |
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")))))))) | |
c8c88afa LC |
133 | |
134 | (test-end) | |
135 | ||
136 | \f | |
137 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) |