gnu: easyrpg-player: Update to 0.6.2.2.
[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.
e49951eb 27if guix build -e +;
912209ee
LC
28then false; else true; fi
29
d223ac4a
LC
30# Source-less packages are accepted; they just return nothing.
31guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
32test "`guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S`" = ""
97298ffa
LC
33
34# Should pass.
af9142dc 35guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
97298ffa 36 grep -e '-guile-'
e49951eb 37guix build hello -d | \
97298ffa
LC
38 grep -e '-hello-[0-9\.]\+\.drv$'
39
16ac7403
LC
40# Passing a .drv.
41drv="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
42out="`guix build "$drv"`"
43out2="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
44test "$out" = "$out2"
45
9c9982dc
LC
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.
50guix build "$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
51 | grep "missing derivation"
52
1397b422 53# Passing a URI.
a87d66f3 54GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
1397b422
LC
55guix 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
ea261dea
LC
61# Passing one '-s' flag.
62test `guix build sed -s x86_64-linux -d | wc -l` = 1
63
64# Passing multiple '-s' flags.
65all_systems="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux"
66test `guix build sed $all_systems -d | sort -u | wc -l` = 4
67
e85d4cec
LC
68# Check there's no weird memoization effect leading to erroneous results.
69# See <https://bugs.gnu.org/40482>.
70drv1="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
71drv2="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
72test "$drv1" = "$drv2"
73
2cdfe13d
EB
74# Check --sources option with its arguments
75module_dir="t-guix-build-$$"
76mkdir "$module_dir"
77trap "rm -rf $module_dir" EXIT
78
79cat > "$module_dir/foo.scm"<<EOF
80(define-module (foo)
94d609ab 81 #:use-module (guix tests)
2cdfe13d
EB
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)))
94d609ab
LC
127
128(define-public baz
129 (dummy-package "baz" (replacement foo)))
130
01afdab8
LC
131(define-public superseded
132 (deprecated-package "superseded" bar))
133
2cdfe13d
EB
134EOF
135
136GUIX_PACKAGE_PATH="$module_dir"
137export GUIX_PACKAGE_PATH
138
139# foo.tar.gz
140guix build -d -S foo
141guix build -d -S foo | grep -e 'foo\.tar\.gz'
142
94d609ab
LC
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
2cdfe13d
EB
147guix build -d --sources=package foo
148guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
149
150# bar.tar.gz and bar.dat
151guix build -d --sources bar
152test `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
157guix build -d --sources=all bar
158test `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
163guix build -d --sources=transitive foo
164test `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
2d2f98ef 168
723bdb8e
LC
169# Unbound variable in thunked field.
170cat > "$module_dir/foo.scm" <<EOF
2d2f98ef
LC
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
179EOF
180
181if guix build package-with-something-wrong -n; then false; else true; fi
182guix build package-with-something-wrong -n 2> "$module_dir/err" || true
183grep "unbound" "$module_dir/err" # actual error
184grep "forget.*(gnu packages base)" "$module_dir/err" # hint
723bdb8e
LC
185
186# Unbound variable at the top level.
187cat > "$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
194EOF
195
196guix build sed -n 2> "$module_dir/err"
197grep "unbound" "$module_dir/err" # actual error
198grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
199
2d2f98ef
LC
200rm -f "$module_dir"/*
201
a2a94b6e
LC
202# Wrong 'define-module' clause reported by 'warn-about-load-error'.
203cat > "$module_dir/foo.scm" <<EOF
204(define-module (something foo)
205 #:use-module (guix)
206 #:use-module (gnu))
207EOF
208guix build guile-bootstrap -n 2> "$module_dir/err"
209grep "does not match file name" "$module_dir/err"
210
211rm "$module_dir"/*
212
bf421152 213# Should all return valid log files.
af9142dc
LC
214drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
215out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
bf421152
LC
216log="`guix build --log-file $drv`"
217echo "$log" | grep log/.*guile.*drv
218test -f "$log"
af9142dc 219test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
bf421152
LC
220 = "$log"
221test "`guix build --log-file guile-bootstrap`" = "$log"
222test "`guix build --log-file $out`" = "$log"
223
97298ffa 224# Should fail because the name/version combination could not be found.
e49951eb 225if guix build hello-0.0.1 -n; then false; else true; fi
97298ffa
LC
226
227# Keep a symlink to the result, registered as a root.
228result="t-result-$$"
e49951eb 229guix build -r "$result" \
af9142dc 230 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
97298ffa
LC
231test -x "$result/bin/guile"
232
233# Should fail, because $result already exists.
af9142dc 234if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
97298ffa
LC
235then false; else true; fi
236
237rm -f "$result"
5401dd75 238
4aea820f
LC
239# Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
240mkdir "$result"
241guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
242test -x "$result/x/bin/guile"
243rm "$result/x"
244rmdir "$result"
245
e55ec43d
LC
246# Cross building.
247guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
248
537b2dab
LC
249# Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
250guix build --target=arm-linux-gnueabihf --dry-run \
251 -e '(@ (gnu packages base) coreutils)'
252
47c0f92c 253# Replacements.
f6396d86 254drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
47c0f92c
LC
255drv2=`guix build guix -d`
256test "$drv1" != "$drv2"
257
258drv1=`guix build guile -d`
259drv2=`guix build guile --with-input=gimp=ruby -d`
260test "$drv1" = "$drv2"
261
262if guix build guile --with-input=libunistring=something-really-silly
263then false; else true; fi
264
01afdab8
LC
265# Deprecated/superseded packages.
266test "`guix build superseded -d`" = "`guix build bar -d`"
267
5401dd75 268# Parsing package names and versions.
e49951eb 269guix build -n time # PASS
64f925cb 270guix build -n time@1.9 # PASS, version found
1b846da8 271if guix build -n time@3.2; # FAIL, version not found
5401dd75 272then false; else true; fi
e49951eb 273if guix build -n something-that-will-never-exist; # FAIL
5401dd75 274then false; else true; fi
ac5de156
LC
275
276# Invoking a monadic procedure.
277guix build -e "(begin
ada3df03 278 (use-modules (guix gexp))
ac5de156 279 (lambda ()
ada3df03
LC
280 (gexp->derivation \"test\"
281 (gexp (mkdir (ungexp output))))))" \
ac5de156 282 --dry-run
56b82106
LC
283
284# Running a gexp.
285guix build -e '#~(mkdir #$output)' -d
286guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
16eb115e 287
b33e191c
LC
288# Same with a file-like object.
289guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
290guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
291
34a1783f
DT
292# Building from a package file.
293cat > "$module_dir/package.scm"<<EOF
294(use-modules (gnu))
295(use-package-modules bootstrap)
296
297%bootstrap-guile
298EOF
299guix build --file="$module_dir/package.scm"
300
301# Building from a monadic procedure file.
302cat > "$module_dir/proc.scm"<<EOF
303(use-modules (guix gexp))
304(lambda ()
305 (gexp->derivation "test"
306 (gexp (mkdir (ungexp output)))))
307EOF
308guix build --file="$module_dir/proc.scm" --dry-run
309
310# Building from a gexp file.
311cat > "$module_dir/gexp.scm"<<EOF
312(use-modules (guix gexp))
313
314(gexp (mkdir (ungexp output)))
315EOF
316guix build --file="$module_dir/gexp.scm" -d
317guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
11415d35
MB
318
319# Building from a manifest file.
320cat > "$module_dir/manifest.scm"<<EOF
321(specifications->manifest '("hello" "guix"))
322EOF
323test `guix build -d --manifest="$module_dir/manifest.scm" \
324 | grep -e '-hello-' -e '-guix-' \
325 | wc -l` -eq 2
5a675b2c
LC
326
327# Building from a manifest that contains a non-package object.
328cat > "$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)))))))
333EOF
334guix build -d -m "$module_dir/manifest.scm" \
335 | grep 'computed-thingie\.drv$'
336
a2a94b6e 337rm "$module_dir"/*.scm
34a1783f 338
16eb115e 339# Using 'GUIX_BUILD_OPTIONS'.
442a6ff5 340GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
16eb115e
DP
341export GUIX_BUILD_OPTIONS
342
343guix build emacs
344
345GUIX_BUILD_OPTIONS="--something-completely-crazy"
346if guix build emacs;
347then false; else true; fi