Merge branch 'master' into staging
[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, 2020 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 there's no weird memoization effect leading to erroneous results.
69 # See <https://bugs.gnu.org/40482>.
70 drv1="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
71 drv2="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
72 test "$drv1" = "$drv2"
73
74 # Check --sources option with its arguments
75 module_dir="t-guix-build-$$"
76 mkdir "$module_dir"
77 trap "rm -rf $module_dir" EXIT
78
79 cat > "$module_dir/foo.scm"<<EOF
80 (define-module (foo)
81 #:use-module (guix tests)
82 #:use-module (guix packages)
83 #:use-module (guix download)
84 #:use-module (guix build-system trivial))
85
86 (define-public foo
87 (package
88 (name "foo")
89 (version "42")
90 (source (origin
91 (method url-fetch)
92 (uri "http://www.example.com/foo.tar.gz")
93 (sha256
94 (base32
95 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
96 (build-system trivial-build-system)
97 (inputs
98 (quasiquote (("bar" ,bar))))
99 (home-page "www.example.com")
100 (synopsis "Dummy package")
101 (description "foo is a dummy package for testing.")
102 (license #f)))
103
104 (define-public bar
105 (package
106 (name "bar")
107 (version "9001")
108 (source (origin
109 (method url-fetch)
110 (uri "http://www.example.com/bar.tar.gz")
111 (sha256
112 (base32
113 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
114 (build-system trivial-build-system)
115 (inputs
116 (quasiquote
117 (("data" ,(origin
118 (method url-fetch)
119 (uri "http://www.example.com/bar.dat")
120 (sha256
121 (base32
122 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
123 (home-page "www.example.com")
124 (synopsis "Dummy package")
125 (description "bar is a dummy package for testing.")
126 (license #f)))
127
128 (define-public baz
129 (dummy-package "baz" (replacement foo)))
130
131 (define-public superseded
132 (deprecated-package "superseded" bar))
133
134 EOF
135
136 GUIX_PACKAGE_PATH="$module_dir"
137 export GUIX_PACKAGE_PATH
138
139 # foo.tar.gz
140 guix build -d -S foo
141 guix build -d -S foo | grep -e 'foo\.tar\.gz'
142
143 # 'baz' has a replacement so we should be getting the replacement's source.
144 (unset GUIX_BUILD_OPTIONS;
145 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
146
147 guix build -d --sources=package foo
148 guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
149
150 # bar.tar.gz and bar.dat
151 guix build -d --sources bar
152 test `guix build -d --sources bar \
153 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
154 | wc -l` -eq 2
155
156 # bar.tar.gz and bar.dat
157 guix build -d --sources=all bar
158 test `guix build -d --sources bar \
159 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
160 | wc -l` -eq 2
161
162 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
163 guix build -d --sources=transitive foo
164 test `guix build -d --sources=transitive foo \
165 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
166 | wc -l` -eq 3
167
168
169 # Unbound variable in thunked field.
170 cat > "$module_dir/foo.scm" <<EOF
171 (define-module (foo)
172 #:use-module (guix tests)
173 #:use-module (guix build-system trivial))
174
175 (define-public foo
176 (dummy-package "package-with-something-wrong"
177 (build-system trivial-build-system)
178 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
179 EOF
180
181 if guix build package-with-something-wrong -n; then false; else true; fi
182 guix build package-with-something-wrong -n 2> "$module_dir/err" || true
183 grep "unbound" "$module_dir/err" # actual error
184 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
185
186 # Unbound variable at the top level.
187 cat > "$module_dir/foo.scm" <<EOF
188 (define-module (foo)
189 #:use-module (guix tests))
190
191 (define-public foo
192 (dummy-package "package-with-something-wrong"
193 (build-system gnu-build-system))) ;unbound variable
194 EOF
195
196 guix build sed -n 2> "$module_dir/err"
197 grep "unbound" "$module_dir/err" # actual error
198 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
199
200 rm -f "$module_dir"/*
201
202 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
203 cat > "$module_dir/foo.scm" <<EOF
204 (define-module (something foo)
205 #:use-module (guix)
206 #:use-module (gnu))
207 EOF
208 guix build guile-bootstrap -n 2> "$module_dir/err"
209 grep "does not match file name" "$module_dir/err"
210
211 rm "$module_dir"/*
212
213 # Should all return valid log files.
214 drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
215 out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
216 log="`guix build --log-file $drv`"
217 echo "$log" | grep log/.*guile.*drv
218 test -f "$log"
219 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
220 = "$log"
221 test "`guix build --log-file guile-bootstrap`" = "$log"
222 test "`guix build --log-file $out`" = "$log"
223
224 # Should fail because the name/version combination could not be found.
225 if guix build hello-0.0.1 -n; then false; else true; fi
226
227 # Keep a symlink to the result, registered as a root.
228 result="t-result-$$"
229 guix build -r "$result" \
230 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
231 test -x "$result/bin/guile"
232
233 # Should fail, because $result already exists.
234 if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
235 then false; else true; fi
236
237 rm -f "$result"
238
239 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
240 mkdir "$result"
241 guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
242 test -x "$result/x/bin/guile"
243 rm "$result/x"
244 rmdir "$result"
245
246 # Cross building.
247 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
248
249 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
250 guix build --target=arm-linux-gnueabihf --dry-run \
251 -e '(@ (gnu packages base) coreutils)'
252
253 # Replacements.
254 drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
255 drv2=`guix build guix -d`
256 test "$drv1" != "$drv2"
257
258 drv1=`guix build guile -d`
259 drv2=`guix build guile --with-input=gimp=ruby -d`
260 test "$drv1" = "$drv2"
261
262 if guix build guile --with-input=libunistring=something-really-silly
263 then false; else true; fi
264
265 # Deprecated/superseded packages.
266 test "`guix build superseded -d`" = "`guix build bar -d`"
267
268 # Parsing package names and versions.
269 guix build -n time # PASS
270 guix build -n time@1.9 # PASS, version found
271 if guix build -n time@3.2; # FAIL, version not found
272 then false; else true; fi
273 if guix build -n something-that-will-never-exist; # FAIL
274 then false; else true; fi
275
276 # Invoking a monadic procedure.
277 guix build -e "(begin
278 (use-modules (guix gexp))
279 (lambda ()
280 (gexp->derivation \"test\"
281 (gexp (mkdir (ungexp output))))))" \
282 --dry-run
283
284 # Running a gexp.
285 guix build -e '#~(mkdir #$output)' -d
286 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
287
288 # Same with a file-like object.
289 guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
290 guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
291
292 # Building from a package file.
293 cat > "$module_dir/package.scm"<<EOF
294 (use-modules (gnu))
295 (use-package-modules bootstrap)
296
297 %bootstrap-guile
298 EOF
299 guix build --file="$module_dir/package.scm"
300
301 # Building from a monadic procedure file.
302 cat > "$module_dir/proc.scm"<<EOF
303 (use-modules (guix gexp))
304 (lambda ()
305 (gexp->derivation "test"
306 (gexp (mkdir (ungexp output)))))
307 EOF
308 guix build --file="$module_dir/proc.scm" --dry-run
309
310 # Building from a gexp file.
311 cat > "$module_dir/gexp.scm"<<EOF
312 (use-modules (guix gexp))
313
314 (gexp (mkdir (ungexp output)))
315 EOF
316 guix build --file="$module_dir/gexp.scm" -d
317 guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
318
319 # Building from a manifest file.
320 cat > "$module_dir/manifest.scm"<<EOF
321 (specifications->manifest '("hello" "guix"))
322 EOF
323 test `guix build -d --manifest="$module_dir/manifest.scm" \
324 | grep -e '-hello-' -e '-guix-' \
325 | wc -l` -eq 2
326
327 # Building from a manifest that contains a non-package object.
328 cat > "$module_dir/manifest.scm"<<EOF
329 (manifest
330 (list (manifest-entry (name "foo") (version "0")
331 (item (computed-file "computed-thingie"
332 #~(mkdir (ungexp output)))))))
333 EOF
334 guix build -d -m "$module_dir/manifest.scm" \
335 | grep 'computed-thingie\.drv$'
336
337 rm "$module_dir"/*.scm
338
339 # Using 'GUIX_BUILD_OPTIONS'.
340 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
341 export GUIX_BUILD_OPTIONS
342
343 guix build emacs
344
345 GUIX_BUILD_OPTIONS="--something-completely-crazy"
346 if guix build emacs;
347 then false; else true; fi