gnu: gsettings-desktop-schemas: Fix file name of default background.
[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
1397b422 39# Passing a URI.
a87d66f3 40GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
1397b422
LC
41guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
42
43( if GUIX_DAEMON_SOCKET="weird://uri" \
44 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
45 then exit 1; fi )
46
ea261dea
LC
47# Passing one '-s' flag.
48test `guix build sed -s x86_64-linux -d | wc -l` = 1
49
50# Passing multiple '-s' flags.
51all_systems="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux"
52test `guix build sed $all_systems -d | sort -u | wc -l` = 4
53
2cdfe13d
EB
54# Check --sources option with its arguments
55module_dir="t-guix-build-$$"
56mkdir "$module_dir"
57trap "rm -rf $module_dir" EXIT
58
59cat > "$module_dir/foo.scm"<<EOF
60(define-module (foo)
94d609ab 61 #:use-module (guix tests)
2cdfe13d
EB
62 #:use-module (guix packages)
63 #:use-module (guix download)
64 #:use-module (guix build-system trivial))
65
66(define-public foo
67 (package
68 (name "foo")
69 (version "42")
70 (source (origin
71 (method url-fetch)
72 (uri "http://www.example.com/foo.tar.gz")
73 (sha256
74 (base32
75 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
76 (build-system trivial-build-system)
77 (inputs
78 (quasiquote (("bar" ,bar))))
79 (home-page "www.example.com")
80 (synopsis "Dummy package")
81 (description "foo is a dummy package for testing.")
82 (license #f)))
83
84(define-public bar
85 (package
86 (name "bar")
87 (version "9001")
88 (source (origin
89 (method url-fetch)
90 (uri "http://www.example.com/bar.tar.gz")
91 (sha256
92 (base32
93 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
94 (build-system trivial-build-system)
95 (inputs
96 (quasiquote
97 (("data" ,(origin
98 (method url-fetch)
99 (uri "http://www.example.com/bar.dat")
100 (sha256
101 (base32
102 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
103 (home-page "www.example.com")
104 (synopsis "Dummy package")
105 (description "bar is a dummy package for testing.")
106 (license #f)))
94d609ab
LC
107
108(define-public baz
109 (dummy-package "baz" (replacement foo)))
110
01afdab8
LC
111(define-public superseded
112 (deprecated-package "superseded" bar))
113
2cdfe13d
EB
114EOF
115
116GUIX_PACKAGE_PATH="$module_dir"
117export GUIX_PACKAGE_PATH
118
119# foo.tar.gz
120guix build -d -S foo
121guix build -d -S foo | grep -e 'foo\.tar\.gz'
122
94d609ab
LC
123# 'baz' has a replacement so we should be getting the replacement's source.
124(unset GUIX_BUILD_OPTIONS;
125 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
126
2cdfe13d
EB
127guix build -d --sources=package foo
128guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
129
130# bar.tar.gz and bar.dat
131guix build -d --sources bar
132test `guix build -d --sources bar \
133 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
134 | wc -l` -eq 2
135
136# bar.tar.gz and bar.dat
137guix build -d --sources=all bar
138test `guix build -d --sources bar \
139 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
140 | wc -l` -eq 2
141
142# Should include foo.tar.gz, bar.tar.gz, and bar.dat
143guix build -d --sources=transitive foo
144test `guix build -d --sources=transitive foo \
145 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
146 | wc -l` -eq 3
147
2d2f98ef 148
723bdb8e
LC
149# Unbound variable in thunked field.
150cat > "$module_dir/foo.scm" <<EOF
2d2f98ef
LC
151(define-module (foo)
152 #:use-module (guix tests)
153 #:use-module (guix build-system trivial))
154
155(define-public foo
156 (dummy-package "package-with-something-wrong"
157 (build-system trivial-build-system)
158 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
159EOF
160
161if guix build package-with-something-wrong -n; then false; else true; fi
162guix build package-with-something-wrong -n 2> "$module_dir/err" || true
163grep "unbound" "$module_dir/err" # actual error
164grep "forget.*(gnu packages base)" "$module_dir/err" # hint
723bdb8e
LC
165
166# Unbound variable at the top level.
167cat > "$module_dir/foo.scm" <<EOF
168(define-module (foo)
169 #:use-module (guix tests))
170
171(define-public foo
172 (dummy-package "package-with-something-wrong"
173 (build-system gnu-build-system))) ;unbound variable
174EOF
175
176guix build sed -n 2> "$module_dir/err"
177grep "unbound" "$module_dir/err" # actual error
178grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
179
2d2f98ef
LC
180rm -f "$module_dir"/*
181
a2a94b6e
LC
182# Wrong 'define-module' clause reported by 'warn-about-load-error'.
183cat > "$module_dir/foo.scm" <<EOF
184(define-module (something foo)
185 #:use-module (guix)
186 #:use-module (gnu))
187EOF
188guix build guile-bootstrap -n 2> "$module_dir/err"
189grep "does not match file name" "$module_dir/err"
190
191rm "$module_dir"/*
192
bf421152 193# Should all return valid log files.
af9142dc
LC
194drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
195out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
bf421152
LC
196log="`guix build --log-file $drv`"
197echo "$log" | grep log/.*guile.*drv
198test -f "$log"
af9142dc 199test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
bf421152
LC
200 = "$log"
201test "`guix build --log-file guile-bootstrap`" = "$log"
202test "`guix build --log-file $out`" = "$log"
203
97298ffa 204# Should fail because the name/version combination could not be found.
e49951eb 205if guix build hello-0.0.1 -n; then false; else true; fi
97298ffa
LC
206
207# Keep a symlink to the result, registered as a root.
208result="t-result-$$"
e49951eb 209guix build -r "$result" \
af9142dc 210 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
97298ffa
LC
211test -x "$result/bin/guile"
212
213# Should fail, because $result already exists.
af9142dc 214if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
97298ffa
LC
215then false; else true; fi
216
217rm -f "$result"
5401dd75 218
4aea820f
LC
219# Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
220mkdir "$result"
221guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
222test -x "$result/x/bin/guile"
223rm "$result/x"
224rmdir "$result"
225
e55ec43d
LC
226# Cross building.
227guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
228
537b2dab
LC
229# Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
230guix build --target=arm-linux-gnueabihf --dry-run \
231 -e '(@ (gnu packages base) coreutils)'
232
47c0f92c 233# Replacements.
f6396d86 234drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
47c0f92c
LC
235drv2=`guix build guix -d`
236test "$drv1" != "$drv2"
237
238drv1=`guix build guile -d`
239drv2=`guix build guile --with-input=gimp=ruby -d`
240test "$drv1" = "$drv2"
241
242if guix build guile --with-input=libunistring=something-really-silly
243then false; else true; fi
244
01afdab8
LC
245# Deprecated/superseded packages.
246test "`guix build superseded -d`" = "`guix build bar -d`"
247
5401dd75 248# Parsing package names and versions.
e49951eb 249guix build -n time # PASS
64f925cb 250guix build -n time@1.9 # PASS, version found
1b846da8 251if guix build -n time@3.2; # FAIL, version not found
5401dd75 252then false; else true; fi
e49951eb 253if guix build -n something-that-will-never-exist; # FAIL
5401dd75 254then false; else true; fi
ac5de156
LC
255
256# Invoking a monadic procedure.
257guix build -e "(begin
ada3df03 258 (use-modules (guix gexp))
ac5de156 259 (lambda ()
ada3df03
LC
260 (gexp->derivation \"test\"
261 (gexp (mkdir (ungexp output))))))" \
ac5de156 262 --dry-run
56b82106
LC
263
264# Running a gexp.
265guix build -e '#~(mkdir #$output)' -d
266guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
16eb115e 267
b33e191c
LC
268# Same with a file-like object.
269guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
270guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
271
34a1783f
DT
272# Building from a package file.
273cat > "$module_dir/package.scm"<<EOF
274(use-modules (gnu))
275(use-package-modules bootstrap)
276
277%bootstrap-guile
278EOF
279guix build --file="$module_dir/package.scm"
280
281# Building from a monadic procedure file.
282cat > "$module_dir/proc.scm"<<EOF
283(use-modules (guix gexp))
284(lambda ()
285 (gexp->derivation "test"
286 (gexp (mkdir (ungexp output)))))
287EOF
288guix build --file="$module_dir/proc.scm" --dry-run
289
290# Building from a gexp file.
291cat > "$module_dir/gexp.scm"<<EOF
292(use-modules (guix gexp))
293
294(gexp (mkdir (ungexp output)))
295EOF
296guix build --file="$module_dir/gexp.scm" -d
297guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
a2a94b6e 298rm "$module_dir"/*.scm
34a1783f 299
16eb115e 300# Using 'GUIX_BUILD_OPTIONS'.
442a6ff5 301GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
16eb115e
DP
302export GUIX_BUILD_OPTIONS
303
304guix build emacs
305
306GUIX_BUILD_OPTIONS="--something-completely-crazy"
307if guix build emacs;
308then false; else true; fi