epiphany w/ gtk4 and webkitgtk 2.38
[jackhill/guix/guix.git] / tests / guix-build.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012-2014, 2016-2022 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
4 # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
5 #
6 # This file is part of GNU Guix.
7 #
8 # GNU Guix is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GNU Guix is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 #
22 # Test the `guix build' command-line utility.
23 #
24
25 guix build --version
26
27 # Should fail.
28 ! guix build -e +
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 # Warn when attempting to build an unsupported package.
35 case "$(guix build intelmetool -s armhf-linux -v0 -n 2>&1)" in
36 *warning:*intelmetool*support*armhf*)
37 true
38 break;;
39 *)
40 false;
41 break;;
42 esac
43
44 # Should pass.
45 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
46 grep -e '-guile-'
47 guix build hello -d | \
48 grep -e '-hello-[0-9\.]\+\.drv$'
49
50 # Passing a .drv.
51 drv="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
52 out="`guix build "$drv"`"
53 out2="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
54 test "$out" = "$out2"
55
56 # Passing the name of a .drv that doesn't exist. The daemon should try to
57 # substitute the .drv. Here we just look for the "cannot build missing
58 # derivation" error that indicates that the daemon did try to substitute the
59 # .drv.
60 guix build "$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
61 | grep "missing derivation"
62
63 # Passing a URI.
64 GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
65 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
66
67 ( if GUIX_DAEMON_SOCKET="weird://uri" \
68 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
69 then exit 1; fi )
70
71 # Passing one '-s' flag.
72 test `guix build sed -s x86_64-linux -d | wc -l` = 1
73
74 # Passing multiple '-s' flags.
75 all_systems="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux \
76 -s powerpc64le-linux"
77 test `guix build sed $all_systems -d | sort -u | wc -l` = 5
78
79 # Check there's no weird memoization effect leading to erroneous results.
80 # See <https://bugs.gnu.org/40482>.
81 drv1="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
82 drv2="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
83 test "$drv1" = "$drv2"
84
85 # Check --sources option with its arguments
86 module_dir="t-guix-build-$$"
87 mkdir "$module_dir"
88 trap "rm -rf $module_dir" EXIT
89
90 # Check error reporting for '-f'.
91 cat > "$module_dir/foo.scm" <<EOF
92 (use-modules (guix))
93 ) ;extra closing paren
94 EOF
95 ! guix build -f "$module_dir/foo.scm" 2> "$module_dir/stderr"
96 grep "read error" "$module_dir/stderr"
97 rm "$module_dir/stderr" "$module_dir/foo.scm"
98
99 # Check 'GUIX_PACKAGE_PATH' & co.
100 cat > "$module_dir/foo.scm"<<EOF
101 (define-module (foo)
102 #:use-module (guix tests)
103 #:use-module (guix packages)
104 #:use-module (guix download)
105 #:use-module (guix build-system trivial))
106
107 (define-public foo
108 (package
109 (name "foo")
110 (version "42")
111 (source (origin
112 (method url-fetch)
113 (uri "http://www.example.com/foo.tar.gz")
114 (sha256
115 (base32
116 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
117 (build-system trivial-build-system)
118 (inputs
119 (quasiquote (("bar" ,bar))))
120 (home-page "www.example.com")
121 (synopsis "Dummy package")
122 (description "foo is a dummy package for testing.")
123 (license #f)))
124
125 (define-public bar
126 (package
127 (name "bar")
128 (version "9001")
129 (source (origin
130 (method url-fetch)
131 (uri "http://www.example.com/bar.tar.gz")
132 (sha256
133 (base32
134 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
135 (build-system trivial-build-system)
136 (inputs
137 (quasiquote
138 (("data" ,(origin
139 (method url-fetch)
140 (uri "http://www.example.com/bar.dat")
141 (sha256
142 (base32
143 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
144 (home-page "www.example.com")
145 (synopsis "Dummy package")
146 (description "bar is a dummy package for testing.")
147 (license #f)))
148
149 (define-public baz
150 (dummy-package "baz" (replacement foo)))
151
152 (define-public superseded
153 (deprecated-package "superseded" bar))
154
155 EOF
156
157 GUIX_PACKAGE_PATH="$module_dir"
158 export GUIX_PACKAGE_PATH
159
160 # foo.tar.gz
161 guix build -d -S foo
162 guix build -d -S foo | grep -e 'foo\.tar\.gz'
163
164 # 'baz' has a replacement so we should be getting the replacement's source.
165 (unset GUIX_BUILD_OPTIONS;
166 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
167
168 guix build -d --sources=package foo
169 guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
170
171 # bar.tar.gz and bar.dat
172 guix build -d --sources bar
173 test `guix build -d --sources bar \
174 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
175 | wc -l` -eq 2
176
177 # bar.tar.gz and bar.dat
178 guix build -d --sources=all bar
179 test `guix build -d --sources bar \
180 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
181 | wc -l` -eq 2
182
183 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
184 guix build -d --sources=transitive foo
185 test `guix build -d --sources=transitive foo \
186 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
187 | wc -l` -eq 3
188
189
190 # Unbound variable in thunked field.
191 cat > "$module_dir/foo.scm" <<EOF
192 (define-module (foo)
193 #:use-module (guix tests)
194 #:use-module (guix build-system trivial))
195
196 (define-public foo
197 (dummy-package "package-with-something-wrong"
198 (build-system trivial-build-system)
199 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
200 EOF
201
202 ! guix build package-with-something-wrong -n
203 guix build package-with-something-wrong -n 2> "$module_dir/err" || true
204 grep "unbound" "$module_dir/err" # actual error
205 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
206
207 # Unbound variable at the top level.
208 cat > "$module_dir/foo.scm" <<EOF
209 (define-module (foo)
210 #:use-module (guix tests))
211
212 (define-public foo
213 (dummy-package "package-with-something-wrong"
214 (build-system gnu-build-system))) ;unbound variable
215 EOF
216
217 guix build sed -n 2> "$module_dir/err"
218 grep "unbound" "$module_dir/err" # actual error
219 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
220
221 rm -f "$module_dir"/*
222
223 # Unbound variable: don't suggest modules that do not export the variable.
224 cat > "$module_dir/aa-private.scm" <<EOF
225 (define-module (aa-private))
226 (define make-thing #f)
227 (set! make-thing make-thing) ;don't inline
228 EOF
229
230 cat > "$module_dir/bb-public.scm" <<EOF
231 (define-module (bb-public) #:export (make-thing))
232 (define make-thing identity)
233 EOF
234
235 cat > "$module_dir/cc-user.scm" <<EOF
236 ;; Make those module available in the global name space.
237 (load-from-path "aa-private.scm")
238 (load-from-path "bb-public.scm")
239
240 (define-module (cc-user))
241 (make-thing 42)
242 EOF
243 ! guix build -f "$module_dir/cc-user.scm" -n 2> "$module_dir/err"
244 cat "$module_dir/err"
245 grep "make-thing.*unbound" "$module_dir/err" # actual error
246 grep "forget.*(bb-public)" "$module_dir/err" # hint
247
248 rm -f "$module_dir"/*
249
250 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
251 cat > "$module_dir/foo.scm" <<EOF
252 (define-module (something foo)
253 #:use-module (guix)
254 #:use-module (gnu))
255 EOF
256 guix build guile-bootstrap -n 2> "$module_dir/err"
257 grep "does not match file name" "$module_dir/err"
258
259 rm "$module_dir"/*
260
261 # Should all return valid log files.
262 drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
263 out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
264 log="`guix build --log-file $drv`"
265 echo "$log" | grep log/.*guile.*drv
266 test -f "$log"
267 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
268 = "$log"
269 test "`guix build --log-file guile-bootstrap`" = "$log"
270 test "`guix build --log-file $out`" = "$log"
271
272 # Should fail because the name/version combination could not be found.
273 ! guix build hello-0.0.1 -n
274
275 # Keep a symlink to the result, registered as a root.
276 result="t-result-$$"
277 guix build -r "$result" \
278 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
279 test -x "$result/bin/guile"
280
281 # Should fail, because $result already exists.
282 ! guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
283
284 rm -f "$result"
285
286 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
287 mkdir "$result"
288 guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
289 test -x "$result/x/bin/guile"
290 rm "$result/x"
291 rmdir "$result"
292
293 # Cross building.
294 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
295
296 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
297 guix build --target=arm-linux-gnueabihf --dry-run \
298 -e '(@ (gnu packages base) coreutils)'
299
300 # Replacements.
301 drv1=`guix build guix --with-input=guile-zstd=idutils -d`
302 drv2=`guix build guix -d`
303 test "$drv1" != "$drv2"
304
305 drv1=`guix build guile -d`
306 drv2=`guix build guile --with-input=gimp=ruby -d`
307 test "$drv1" = "$drv2"
308
309 # See <https://bugs.gnu.org/42156>.
310 drv1=`guix build glib -d`
311 drv2=`guix build glib -d --with-input=libreoffice=inkscape`
312 test "$drv1" = "$drv2"
313
314 # '--with-graft' should have no effect when using '--no-grafts'.
315 # See <https://bugs.gnu.org/43890>.
316 drv1=`guix build inkscape -d --no-grafts`
317 drv2=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking`
318 test "$drv1" = "$drv2"
319
320 # Rewriting implicit inputs.
321 drv1=`guix build hello -d`
322 drv2=`guix build hello -d --with-input=gcc=gcc-toolchain`
323 test "$drv1" != "$drv2"
324 guix gc -R "$drv2" | grep `guix build -d gcc-toolchain`
325
326 ! guix build guile --with-input=libunistring=something-really-silly
327
328 # Deprecated/superseded packages.
329 test "`guix build superseded -d`" = "`guix build bar -d`"
330
331 # Parsing package names and versions.
332 guix build -n time # PASS
333 guix build -n time@1.9 # PASS, version found
334 ! guix build -n time@3.2 # FAIL, version not found
335 ! guix build -n something-that-will-never-exist # FAIL
336
337 # Invoking a monadic procedure.
338 guix build -e "(begin
339 (use-modules (guix gexp))
340 (lambda ()
341 (gexp->derivation \"test\"
342 (gexp (mkdir (ungexp output))))))" \
343 --dry-run
344
345 # Running a gexp.
346 guix build -e '#~(mkdir #$output)' -d
347 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
348
349 # Same with a file-like object.
350 guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
351 guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
352
353 # Building from a package file.
354 cat > "$module_dir/package.scm"<<EOF
355 (use-modules (gnu))
356 (use-package-modules bootstrap)
357
358 %bootstrap-guile
359 EOF
360 guix build --file="$module_dir/package.scm"
361
362 # Building from a monadic procedure file.
363 cat > "$module_dir/proc.scm"<<EOF
364 (use-modules (guix gexp))
365 (lambda ()
366 (gexp->derivation "test"
367 (gexp (mkdir (ungexp output)))))
368 EOF
369 guix build --file="$module_dir/proc.scm" --dry-run
370
371 # Building from a gexp file.
372 cat > "$module_dir/gexp.scm"<<EOF
373 (use-modules (guix gexp))
374
375 (gexp (mkdir (ungexp output)))
376 EOF
377 guix build --file="$module_dir/gexp.scm" -d
378 guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
379
380 # Building from a manifest file.
381 cat > "$module_dir/manifest.scm"<<EOF
382 (specifications->manifest '("hello" "guix"))
383 EOF
384 test `guix build -d --manifest="$module_dir/manifest.scm" \
385 | grep -e '-hello-' -e '-guix-' \
386 | wc -l` -eq 2
387
388 # Building from a manifest that contains a non-package object.
389 cat > "$module_dir/manifest.scm"<<EOF
390 (manifest
391 (list (manifest-entry (name "foo") (version "0")
392 (item (computed-file "computed-thingie"
393 #~(mkdir (ungexp output)))))))
394 EOF
395 guix build -d -m "$module_dir/manifest.scm" \
396 | grep 'computed-thingie\.drv$'
397
398 rm "$module_dir"/*.scm
399
400 # Using 'GUIX_BUILD_OPTIONS'.
401 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
402 export GUIX_BUILD_OPTIONS
403
404 guix build emacs
405
406 GUIX_BUILD_OPTIONS="--something-completely-crazy"
407 ! guix build emacs