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, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
4 #
5 # This file is part of GNU Guix.
6 #
7 # GNU Guix is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # GNU Guix is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 #
21 # Test the `guix build' command-line utility.
22 #
23
24 guix build --version
25
26 # Should fail.
27 if guix build -e +;
28 then false; else true; fi
29
30 # Source-less packages are accepted; they just return nothing.
31 guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
32 test "`guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S`" = ""
33
34 # Should pass.
35 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
36 grep -e '-guile-'
37 guix build hello -d | \
38 grep -e '-hello-[0-9\.]\+\.drv$'
39
40 # Passing a .drv.
41 drv="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
42 out="`guix build "$drv"`"
43 out2="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
44 test "$out" = "$out2"
45
46 # Passing the name of a .drv that doesn't exist. The daemon should try to
47 # substitute the .drv. Here we just look for the "cannot build missing
48 # derivation" error that indicates that the daemon did try to substitute the
49 # .drv.
50 guix build "$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
51 | grep "missing derivation"
52
53 # Passing a URI.
54 GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
55 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
56
57 ( if GUIX_DAEMON_SOCKET="weird://uri" \
58 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
59 then exit 1; fi )
60
61 # Passing one '-s' flag.
62 test `guix build sed -s x86_64-linux -d | wc -l` = 1
63
64 # Passing multiple '-s' flags.
65 all_systems="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux"
66 test `guix build sed $all_systems -d | sort -u | wc -l` = 4
67
68 # Check --sources option with its arguments
69 module_dir="t-guix-build-$$"
70 mkdir "$module_dir"
71 trap "rm -rf $module_dir" EXIT
72
73 cat > "$module_dir/foo.scm"<<EOF
74 (define-module (foo)
75 #:use-module (guix tests)
76 #:use-module (guix packages)
77 #:use-module (guix download)
78 #:use-module (guix build-system trivial))
79
80 (define-public foo
81 (package
82 (name "foo")
83 (version "42")
84 (source (origin
85 (method url-fetch)
86 (uri "http://www.example.com/foo.tar.gz")
87 (sha256
88 (base32
89 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
90 (build-system trivial-build-system)
91 (inputs
92 (quasiquote (("bar" ,bar))))
93 (home-page "www.example.com")
94 (synopsis "Dummy package")
95 (description "foo is a dummy package for testing.")
96 (license #f)))
97
98 (define-public bar
99 (package
100 (name "bar")
101 (version "9001")
102 (source (origin
103 (method url-fetch)
104 (uri "http://www.example.com/bar.tar.gz")
105 (sha256
106 (base32
107 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
108 (build-system trivial-build-system)
109 (inputs
110 (quasiquote
111 (("data" ,(origin
112 (method url-fetch)
113 (uri "http://www.example.com/bar.dat")
114 (sha256
115 (base32
116 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
117 (home-page "www.example.com")
118 (synopsis "Dummy package")
119 (description "bar is a dummy package for testing.")
120 (license #f)))
121
122 (define-public baz
123 (dummy-package "baz" (replacement foo)))
124
125 (define-public superseded
126 (deprecated-package "superseded" bar))
127
128 EOF
129
130 GUIX_PACKAGE_PATH="$module_dir"
131 export GUIX_PACKAGE_PATH
132
133 # foo.tar.gz
134 guix build -d -S foo
135 guix build -d -S foo | grep -e 'foo\.tar\.gz'
136
137 # 'baz' has a replacement so we should be getting the replacement's source.
138 (unset GUIX_BUILD_OPTIONS;
139 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
140
141 guix build -d --sources=package foo
142 guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
143
144 # bar.tar.gz and bar.dat
145 guix build -d --sources bar
146 test `guix build -d --sources bar \
147 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
148 | wc -l` -eq 2
149
150 # bar.tar.gz and bar.dat
151 guix build -d --sources=all bar
152 test `guix build -d --sources bar \
153 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
154 | wc -l` -eq 2
155
156 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
157 guix build -d --sources=transitive foo
158 test `guix build -d --sources=transitive foo \
159 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
160 | wc -l` -eq 3
161
162
163 # Unbound variable in thunked field.
164 cat > "$module_dir/foo.scm" <<EOF
165 (define-module (foo)
166 #:use-module (guix tests)
167 #:use-module (guix build-system trivial))
168
169 (define-public foo
170 (dummy-package "package-with-something-wrong"
171 (build-system trivial-build-system)
172 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
173 EOF
174
175 if guix build package-with-something-wrong -n; then false; else true; fi
176 guix build package-with-something-wrong -n 2> "$module_dir/err" || true
177 grep "unbound" "$module_dir/err" # actual error
178 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
179
180 # Unbound variable at the top level.
181 cat > "$module_dir/foo.scm" <<EOF
182 (define-module (foo)
183 #:use-module (guix tests))
184
185 (define-public foo
186 (dummy-package "package-with-something-wrong"
187 (build-system gnu-build-system))) ;unbound variable
188 EOF
189
190 guix build sed -n 2> "$module_dir/err"
191 grep "unbound" "$module_dir/err" # actual error
192 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
193
194 rm -f "$module_dir"/*
195
196 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
197 cat > "$module_dir/foo.scm" <<EOF
198 (define-module (something foo)
199 #:use-module (guix)
200 #:use-module (gnu))
201 EOF
202 guix build guile-bootstrap -n 2> "$module_dir/err"
203 grep "does not match file name" "$module_dir/err"
204
205 rm "$module_dir"/*
206
207 # Should all return valid log files.
208 drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
209 out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
210 log="`guix build --log-file $drv`"
211 echo "$log" | grep log/.*guile.*drv
212 test -f "$log"
213 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
214 = "$log"
215 test "`guix build --log-file guile-bootstrap`" = "$log"
216 test "`guix build --log-file $out`" = "$log"
217
218 # Should fail because the name/version combination could not be found.
219 if guix build hello-0.0.1 -n; then false; else true; fi
220
221 # Keep a symlink to the result, registered as a root.
222 result="t-result-$$"
223 guix build -r "$result" \
224 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
225 test -x "$result/bin/guile"
226
227 # Should fail, because $result already exists.
228 if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
229 then false; else true; fi
230
231 rm -f "$result"
232
233 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
234 mkdir "$result"
235 guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
236 test -x "$result/x/bin/guile"
237 rm "$result/x"
238 rmdir "$result"
239
240 # Cross building.
241 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
242
243 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
244 guix build --target=arm-linux-gnueabihf --dry-run \
245 -e '(@ (gnu packages base) coreutils)'
246
247 # Replacements.
248 drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
249 drv2=`guix build guix -d`
250 test "$drv1" != "$drv2"
251
252 drv1=`guix build guile -d`
253 drv2=`guix build guile --with-input=gimp=ruby -d`
254 test "$drv1" = "$drv2"
255
256 if guix build guile --with-input=libunistring=something-really-silly
257 then false; else true; fi
258
259 # Deprecated/superseded packages.
260 test "`guix build superseded -d`" = "`guix build bar -d`"
261
262 # Parsing package names and versions.
263 guix build -n time # PASS
264 guix build -n time@1.9 # PASS, version found
265 if guix build -n time@3.2; # FAIL, version not found
266 then false; else true; fi
267 if guix build -n something-that-will-never-exist; # FAIL
268 then false; else true; fi
269
270 # Invoking a monadic procedure.
271 guix build -e "(begin
272 (use-modules (guix gexp))
273 (lambda ()
274 (gexp->derivation \"test\"
275 (gexp (mkdir (ungexp output))))))" \
276 --dry-run
277
278 # Running a gexp.
279 guix build -e '#~(mkdir #$output)' -d
280 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
281
282 # Same with a file-like object.
283 guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
284 guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
285
286 # Building from a package file.
287 cat > "$module_dir/package.scm"<<EOF
288 (use-modules (gnu))
289 (use-package-modules bootstrap)
290
291 %bootstrap-guile
292 EOF
293 guix build --file="$module_dir/package.scm"
294
295 # Building from a monadic procedure file.
296 cat > "$module_dir/proc.scm"<<EOF
297 (use-modules (guix gexp))
298 (lambda ()
299 (gexp->derivation "test"
300 (gexp (mkdir (ungexp output)))))
301 EOF
302 guix build --file="$module_dir/proc.scm" --dry-run
303
304 # Building from a gexp file.
305 cat > "$module_dir/gexp.scm"<<EOF
306 (use-modules (guix gexp))
307
308 (gexp (mkdir (ungexp output)))
309 EOF
310 guix build --file="$module_dir/gexp.scm" -d
311 guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
312
313 # Building from a manifest file.
314 cat > "$module_dir/manifest.scm"<<EOF
315 (specifications->manifest '("hello" "guix"))
316 EOF
317 test `guix build -d --manifest="$module_dir/manifest.scm" \
318 | grep -e '-hello-' -e '-guix-' \
319 | wc -l` -eq 2
320 rm "$module_dir"/*.scm
321
322 # Using 'GUIX_BUILD_OPTIONS'.
323 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
324 export GUIX_BUILD_OPTIONS
325
326 guix build emacs
327
328 GUIX_BUILD_OPTIONS="--something-completely-crazy"
329 if guix build emacs;
330 then false; else true; fi