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