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