1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
4 # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
6 # This file is part of GNU Guix.
8 # GNU Guix is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
13 # GNU Guix is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 # Test the `guix build' command-line utility.
30 # Source-less packages are accepted; they just return nothing.
31 guix build
-e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
32 test "`guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S`" = ""
35 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
37 guix build hello
-d | \
38 grep -e '-hello-[0-9\.]\+\.drv$'
41 drv
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
42 out
="`guix build "$drv"`"
43 out2
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
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
50 guix build
"$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
51 |
grep "missing derivation"
54 GUIX_DAEMON_SOCKET
="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
55 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
57 ( if GUIX_DAEMON_SOCKET
="weird://uri" \
58 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
61 # Passing one '-s' flag.
62 test `guix build sed -s x86_64-linux -d | wc -l` = 1
64 # Passing multiple '-s' flags.
65 all_systems
="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux \
67 test `guix build sed $all_systems -d | sort -u | wc -l` = 5
69 # Check there's no weird memoization effect leading to erroneous results.
70 # See <https://bugs.gnu.org/40482>.
71 drv1
="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
72 drv2
="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
73 test "$drv1" = "$drv2"
75 # Check --sources option with its arguments
76 module_dir
="t-guix-build-$$"
78 trap "rm -rf $module_dir" EXIT
80 # Check error reporting for '-f'.
81 cat > "$module_dir/foo.scm" <<EOF
83 ) ;extra closing paren
85 ! guix build
-f "$module_dir/foo.scm" 2> "$module_dir/stderr"
86 grep "read error" "$module_dir/stderr"
87 rm "$module_dir/stderr" "$module_dir/foo.scm"
89 # Check 'GUIX_PACKAGE_PATH' & co.
90 cat > "$module_dir/foo.scm"<<EOF
92 #:use-module (guix tests)
93 #:use-module (guix packages)
94 #:use-module (guix download)
95 #:use-module (guix build-system trivial))
103 (uri "http://www.example.com/foo.tar.gz")
106 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
107 (build-system trivial-build-system)
109 (quasiquote (("bar" ,bar))))
110 (home-page "www.example.com")
111 (synopsis "Dummy package")
112 (description "foo is a dummy package for testing.")
121 (uri "http://www.example.com/bar.tar.gz")
124 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
125 (build-system trivial-build-system)
130 (uri "http://www.example.com/bar.dat")
133 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
134 (home-page "www.example.com")
135 (synopsis "Dummy package")
136 (description "bar is a dummy package for testing.")
140 (dummy-package "baz" (replacement foo)))
142 (define-public superseded
143 (deprecated-package "superseded" bar))
147 GUIX_PACKAGE_PATH
="$module_dir"
148 export GUIX_PACKAGE_PATH
152 guix build
-d -S foo |
grep -e 'foo\.tar\.gz'
154 # 'baz' has a replacement so we should be getting the replacement's source.
155 (unset GUIX_BUILD_OPTIONS
;
156 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
158 guix build
-d --sources=package foo
159 guix build
-d --sources=package foo |
grep -e 'foo\.tar\.gz'
161 # bar.tar.gz and bar.dat
162 guix build
-d --sources bar
163 test `guix build -d --sources bar \
164 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
167 # bar.tar.gz and bar.dat
168 guix build
-d --sources=all bar
169 test `guix build -d --sources bar \
170 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
173 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
174 guix build
-d --sources=transitive foo
175 test `guix build -d --sources=transitive foo \
176 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
180 # Unbound variable in thunked field.
181 cat > "$module_dir/foo.scm" <<EOF
183 #:use-module (guix tests)
184 #:use-module (guix build-system trivial))
187 (dummy-package "package-with-something-wrong"
188 (build-system trivial-build-system)
189 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
192 ! guix build package-with-something-wrong
-n
193 guix build package-with-something-wrong
-n 2> "$module_dir/err" || true
194 grep "unbound" "$module_dir/err" # actual error
195 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
197 # Unbound variable at the top level.
198 cat > "$module_dir/foo.scm" <<EOF
200 #:use-module (guix tests))
203 (dummy-package "package-with-something-wrong"
204 (build-system gnu-build-system))) ;unbound variable
207 guix build
sed -n 2> "$module_dir/err"
208 grep "unbound" "$module_dir/err" # actual error
209 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
211 rm -f "$module_dir"/*
213 # Unbound variable: don't suggest modules that do not export the variable.
214 cat > "$module_dir/aa-private.scm" <<EOF
215 (define-module (aa-private))
216 (define make-thing #f)
217 (set! make-thing make-thing) ;don't inline
220 cat > "$module_dir/bb-public.scm" <<EOF
221 (define-module (bb-public) #:export (make-thing))
222 (define make-thing identity)
225 cat > "$module_dir/cc-user.scm" <<EOF
226 ;; Make those module available in the global name space.
227 (load-from-path "aa-private.scm")
228 (load-from-path "bb-public.scm")
230 (define-module (cc-user))
233 ! guix build
-f "$module_dir/cc-user.scm" -n 2> "$module_dir/err"
234 cat "$module_dir/err"
235 grep "make-thing.*unbound" "$module_dir/err" # actual error
236 grep "forget.*(bb-public)" "$module_dir/err" # hint
238 rm -f "$module_dir"/*
240 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
241 cat > "$module_dir/foo.scm" <<EOF
242 (define-module (something foo)
246 guix build guile-bootstrap
-n 2> "$module_dir/err"
247 grep "does not match file name" "$module_dir/err"
251 # Should all return valid log files.
252 drv
="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
253 out
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
254 log
="`guix build --log-file $drv`"
255 echo "$log" |
grep log
/.
*guile.
*drv
257 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
259 test "`guix build --log-file guile-bootstrap`" = "$log"
260 test "`guix build --log-file $out`" = "$log"
262 # Should fail because the name/version combination could not be found.
263 ! guix build hello-0.0
.1 -n
265 # Keep a symlink to the result, registered as a root.
267 guix build
-r "$result" \
268 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
269 test -x "$result/bin/guile"
271 # Should fail, because $result already exists.
272 ! guix build
-r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
276 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
278 guix build
-r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
279 test -x "$result/x/bin/guile"
284 guix build coreutils
--target=mips64el-linux-gnu
--dry-run --no-substitutes
286 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
287 guix build
--target=arm-linux-gnueabihf
--dry-run \
288 -e '(@ (gnu packages base) coreutils)'
291 drv1
=`guix build guix --with-input=guile-zstd=idutils -d`
292 drv2
=`guix build guix -d`
293 test "$drv1" != "$drv2"
295 drv1
=`guix build guile -d`
296 drv2
=`guix build guile --with-input=gimp=ruby -d`
297 test "$drv1" = "$drv2"
299 # See <https://bugs.gnu.org/42156>.
300 drv1
=`guix build glib -d`
301 drv2
=`guix build glib -d --with-input=libreoffice=inkscape`
302 test "$drv1" = "$drv2"
304 # '--with-graft' should have no effect when using '--no-grafts'.
305 # See <https://bugs.gnu.org/43890>.
306 drv1
=`guix build inkscape -d --no-grafts`
307 drv2
=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking`
308 test "$drv1" = "$drv2"
310 # Rewriting implicit inputs.
311 drv1
=`guix build hello -d`
312 drv2
=`guix build hello -d --with-input=gcc=gcc-toolchain`
313 test "$drv1" != "$drv2"
314 guix gc
-R "$drv2" |
grep `guix build -d gcc-toolchain`
316 ! guix build guile
--with-input=libunistring
=something-really-silly
318 # Deprecated/superseded packages.
319 test "`guix build superseded -d`" = "`guix build bar -d`"
321 # Parsing package names and versions.
322 guix build
-n time # PASS
323 guix build
-n time@
1.9 # PASS, version found
324 ! guix build
-n time@
3.2 # FAIL, version not found
325 ! guix build
-n something-that-will-never-exist
# FAIL
327 # Invoking a monadic procedure.
328 guix build
-e "(begin
329 (use-modules (guix gexp))
331 (gexp->derivation \"test\"
332 (gexp (mkdir (ungexp output))))))" \
336 guix build
-e '#~(mkdir #$output)' -d
337 guix build
-e '#~(mkdir #$output)' -d |
grep 'gexp\.drv'
339 # Same with a file-like object.
340 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d
341 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d |
grep 'foo\.drv'
343 # Building from a package file.
344 cat > "$module_dir/package.scm"<<EOF
346 (use-package-modules bootstrap)
350 guix build
--file="$module_dir/package.scm"
352 # Building from a monadic procedure file.
353 cat > "$module_dir/proc.scm"<<EOF
354 (use-modules (guix gexp))
356 (gexp->derivation "test"
357 (gexp (mkdir (ungexp output)))))
359 guix build
--file="$module_dir/proc.scm" --dry-run
361 # Building from a gexp file.
362 cat > "$module_dir/gexp.scm"<<EOF
363 (use-modules (guix gexp))
365 (gexp (mkdir (ungexp output)))
367 guix build
--file="$module_dir/gexp.scm" -d
368 guix build
--file="$module_dir/gexp.scm" -d |
grep 'gexp\.drv'
370 # Building from a manifest file.
371 cat > "$module_dir/manifest.scm"<<EOF
372 (specifications->manifest '("hello" "guix"))
374 test `guix build -d --manifest="$module_dir/manifest.scm" \
375 | grep -e '-hello-' -e '-guix-' \
378 # Building from a manifest that contains a non-package object.
379 cat > "$module_dir/manifest.scm"<<EOF
381 (list (manifest-entry (name "foo") (version "0")
382 (item (computed-file "computed-thingie"
383 #~(mkdir (ungexp output)))))))
385 guix build
-d -m "$module_dir/manifest.scm" \
386 |
grep 'computed-thingie\.drv$'
388 rm "$module_dir"/*.scm
390 # Using 'GUIX_BUILD_OPTIONS'.
391 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
392 export GUIX_BUILD_OPTIONS
396 GUIX_BUILD_OPTIONS
="--something-completely-crazy"