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