Merge branch 'staging' into core-updates
[jackhill/guix/guix.git] / tests / builders.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015 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-builders)
21 #:use-module (guix download)
22 #:use-module (guix build-system)
23 #:use-module (guix build-system gnu)
24 #:use-module (guix store)
25 #:use-module (guix utils)
26 #:use-module (guix base32)
27 #:use-module (guix derivations)
28 #:use-module (gcrypt hash)
29 #:use-module (guix tests)
30 #:use-module ((guix packages)
31 #:select (package?
32 package-derivation package-native-search-paths))
33 #:use-module (gnu packages bootstrap)
34 #:use-module (ice-9 match)
35 #:use-module (srfi srfi-1)
36 #:use-module (srfi srfi-64))
37
38 ;; Test the higher-level builders.
39
40 (define %store
41 (open-connection-for-tests))
42
43 (define (%bootstrap-inputs)
44 ;; Use the bootstrap inputs so it doesn't take ages to run these tests.
45 ;; This still involves building Make, Diffutils, and Findutils.
46 ;; XXX: We're relying on the higher-level `package-derivations' here.
47 (and %store
48 (map (match-lambda
49 ((name package)
50 (list name (package-derivation %store package))))
51 (filter
52 (compose package? cadr)
53 ((@@ (gnu packages commencement) %boot0-inputs))))))
54
55 (define (%bootstrap-search-paths)
56 ;; Search path specifications that go with %BOOTSTRAP-INPUTS.
57 (append-map (match-lambda
58 ((name package _ ...)
59 (package-native-search-paths package)))
60 (filter
61 (compose package? cadr)
62 ((@@ (gnu packages commencement) %boot0-inputs)))))
63
64 (define url-fetch*
65 (store-lower url-fetch))
66
67 \f
68 (test-begin "builders")
69
70 (unless (network-reachable?) (test-skip 1))
71 (test-assert "url-fetch"
72 (let* ((url '("http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"
73 "ftp://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"))
74 (hash (nix-base32-string->bytevector
75 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))
76 (drv (url-fetch* %store url 'sha256 hash
77 #:guile %bootstrap-guile))
78 (out-path (derivation->output-path drv)))
79 (and (build-derivations %store (list drv))
80 (file-exists? out-path)
81 (valid-path? %store out-path))))
82
83 (test-assert "url-fetch, file"
84 (let* ((file (search-path %load-path "guix.scm"))
85 (hash (call-with-input-file file port-sha256))
86 (out (url-fetch* %store file 'sha256 hash)))
87 (and (file-exists? out)
88 (valid-path? %store out))))
89
90 (test-assert "url-fetch, file URI"
91 (let* ((file (search-path %load-path "guix.scm"))
92 (hash (call-with-input-file file port-sha256))
93 (out (url-fetch* %store
94 (string-append "file://" (canonicalize-path file))
95 'sha256 hash)))
96 (and (file-exists? out)
97 (valid-path? %store out))))
98
99 (test-assert "gnu-build-system"
100 (build-system? gnu-build-system))
101
102 (when (or (not (network-reachable?)) (shebang-too-long?))
103 (test-skip 1))
104 (test-assert "gnu-build"
105 (let* ((url "http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz")
106 (hash (nix-base32-string->bytevector
107 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))
108 (tarball (url-fetch* %store url 'sha256 hash
109 #:guile %bootstrap-guile))
110 (build (gnu-build %store "hello-2.8"
111 `(("source" ,tarball)
112 ,@(%bootstrap-inputs))
113 #:guile %bootstrap-guile
114 #:search-paths (%bootstrap-search-paths)))
115 (out (derivation->output-path build)))
116 (and (build-derivations %store (list (pk 'hello-drv build)))
117 (valid-path? %store out)
118 (file-exists? (string-append out "/bin/hello")))))
119
120 (test-end "builders")