Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / tests / guix-build.sh
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 # Test the `guix build' command-line utility.
21 #
22
23 guix build --version
24
25 # Should fail.
26 if guix build -e +;
27 then false; else true; fi
28
29 # Should fail because this is a source-less package.
30 if guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
31 then false; else true; fi
32
33 # Should pass.
34 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
35 grep -e '-guile-'
36 guix build hello -d | \
37 grep -e '-hello-[0-9\.]\+\.drv$'
38
39 # Check --sources option with its arguments
40 module_dir="t-guix-build-$$"
41 mkdir "$module_dir"
42 trap "rm -rf $module_dir" EXIT
43
44 cat > "$module_dir/foo.scm"<<EOF
45 (define-module (foo)
46 #:use-module (guix packages)
47 #:use-module (guix download)
48 #:use-module (guix build-system trivial))
49
50 (define-public foo
51 (package
52 (name "foo")
53 (version "42")
54 (source (origin
55 (method url-fetch)
56 (uri "http://www.example.com/foo.tar.gz")
57 (sha256
58 (base32
59 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
60 (build-system trivial-build-system)
61 (inputs
62 (quasiquote (("bar" ,bar))))
63 (home-page "www.example.com")
64 (synopsis "Dummy package")
65 (description "foo is a dummy package for testing.")
66 (license #f)))
67
68 (define-public bar
69 (package
70 (name "bar")
71 (version "9001")
72 (source (origin
73 (method url-fetch)
74 (uri "http://www.example.com/bar.tar.gz")
75 (sha256
76 (base32
77 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
78 (build-system trivial-build-system)
79 (inputs
80 (quasiquote
81 (("data" ,(origin
82 (method url-fetch)
83 (uri "http://www.example.com/bar.dat")
84 (sha256
85 (base32
86 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
87 (home-page "www.example.com")
88 (synopsis "Dummy package")
89 (description "bar is a dummy package for testing.")
90 (license #f)))
91 EOF
92
93 GUIX_PACKAGE_PATH="$module_dir"
94 export GUIX_PACKAGE_PATH
95
96 # foo.tar.gz
97 guix build -d -S foo
98 guix build -d -S foo | grep -e 'foo\.tar\.gz'
99
100 guix build -d --sources=package foo
101 guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
102
103 # bar.tar.gz and bar.dat
104 guix build -d --sources bar
105 test `guix build -d --sources bar \
106 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
107 | wc -l` -eq 2
108
109 # bar.tar.gz and bar.dat
110 guix build -d --sources=all bar
111 test `guix build -d --sources bar \
112 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
113 | wc -l` -eq 2
114
115 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
116 guix build -d --sources=transitive foo
117 test `guix build -d --sources=transitive foo \
118 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
119 | wc -l` -eq 3
120
121 # Should all return valid log files.
122 drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
123 out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
124 log="`guix build --log-file $drv`"
125 echo "$log" | grep log/.*guile.*drv
126 test -f "$log"
127 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
128 = "$log"
129 test "`guix build --log-file guile-bootstrap`" = "$log"
130 test "`guix build --log-file $out`" = "$log"
131
132 # Should fail because the name/version combination could not be found.
133 if guix build hello-0.0.1 -n; then false; else true; fi
134
135 # Keep a symlink to the result, registered as a root.
136 result="t-result-$$"
137 guix build -r "$result" \
138 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
139 test -x "$result/bin/guile"
140
141 # Should fail, because $result already exists.
142 if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
143 then false; else true; fi
144
145 rm -f "$result"
146
147 # Cross building.
148 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
149
150 # Parsing package names and versions.
151 guix build -n time # PASS
152 guix build -n time-1.7 # PASS, version found
153 if guix build -n time-3.2; # FAIL, version not found
154 then false; else true; fi
155 if guix build -n something-that-will-never-exist; # FAIL
156 then false; else true; fi
157
158 # Invoking a monadic procedure.
159 guix build -e "(begin
160 (use-modules (guix gexp))
161 (lambda ()
162 (gexp->derivation \"test\"
163 (gexp (mkdir (ungexp output))))))" \
164 --dry-run
165
166 # Running a gexp.
167 guix build -e '#~(mkdir #$output)' -d
168 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
169
170 # Building from a package file.
171 cat > "$module_dir/package.scm"<<EOF
172 (use-modules (gnu))
173 (use-package-modules bootstrap)
174
175 %bootstrap-guile
176 EOF
177 guix build --file="$module_dir/package.scm"
178
179 # Building from a monadic procedure file.
180 cat > "$module_dir/proc.scm"<<EOF
181 (use-modules (guix gexp))
182 (lambda ()
183 (gexp->derivation "test"
184 (gexp (mkdir (ungexp output)))))
185 EOF
186 guix build --file="$module_dir/proc.scm" --dry-run
187
188 # Building from a gexp file.
189 cat > "$module_dir/gexp.scm"<<EOF
190 (use-modules (guix gexp))
191
192 (gexp (mkdir (ungexp output)))
193 EOF
194 guix build --file="$module_dir/gexp.scm" -d
195 guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
196
197 # Using 'GUIX_BUILD_OPTIONS'.
198 GUIX_BUILD_OPTIONS="--dry-run"
199 export GUIX_BUILD_OPTIONS
200
201 guix build emacs
202
203 GUIX_BUILD_OPTIONS="--something-completely-crazy"
204 if guix build emacs;
205 then false; else true; fi