1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012-2014, 2016-2022 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`" = ""
34 # Warn when attempting to build an unsupported package.
35 case "$(guix build intelmetool -s armhf-linux -v0 -n 2>&1)" in
36 *warning
:*intelmetool
*support
*armhf
*)
45 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
47 guix build hello
-d | \
48 grep -e '-hello-[0-9\.]\+\.drv$'
51 drv
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
52 out
="`guix build "$drv"`"
53 out2
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
56 # Passing the name of a .drv that doesn't exist. The daemon should try to
57 # substitute the .drv. Here we just look for the "cannot build missing
58 # derivation" error that indicates that the daemon did try to substitute the
60 guix build
"$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
61 |
grep "missing derivation"
64 GUIX_DAEMON_SOCKET
="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
65 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
67 ( if GUIX_DAEMON_SOCKET
="weird://uri" \
68 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
71 # Passing one '-s' flag.
72 test `guix build sed -s x86_64-linux -d | wc -l` = 1
74 # Passing multiple '-s' flags.
75 all_systems
="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux \
77 test `guix build sed $all_systems -d | sort -u | wc -l` = 5
79 # Check there's no weird memoization effect leading to erroneous results.
80 # See <https://bugs.gnu.org/40482>.
81 drv1
="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
82 drv2
="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
83 test "$drv1" = "$drv2"
85 # Check --sources option with its arguments
86 module_dir
="t-guix-build-$$"
88 trap "rm -rf $module_dir" EXIT
90 # Check error reporting for '-f'.
91 cat > "$module_dir/foo.scm" <<EOF
93 ) ;extra closing paren
95 ! guix build
-f "$module_dir/foo.scm" 2> "$module_dir/stderr"
96 grep "read error" "$module_dir/stderr"
97 rm "$module_dir/stderr" "$module_dir/foo.scm"
99 # Check 'GUIX_PACKAGE_PATH' & co.
100 cat > "$module_dir/foo.scm"<<EOF
102 #:use-module (guix tests)
103 #:use-module (guix packages)
104 #:use-module (guix download)
105 #:use-module (guix build-system trivial))
113 (uri "http://www.example.com/foo.tar.gz")
116 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
117 (build-system trivial-build-system)
119 (quasiquote (("bar" ,bar))))
120 (home-page "www.example.com")
121 (synopsis "Dummy package")
122 (description "foo is a dummy package for testing.")
131 (uri "http://www.example.com/bar.tar.gz")
134 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
135 (build-system trivial-build-system)
140 (uri "http://www.example.com/bar.dat")
143 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
144 (home-page "www.example.com")
145 (synopsis "Dummy package")
146 (description "bar is a dummy package for testing.")
150 (dummy-package "baz" (replacement foo)))
152 (define-public superseded
153 (deprecated-package "superseded" bar))
157 GUIX_PACKAGE_PATH
="$module_dir"
158 export GUIX_PACKAGE_PATH
162 guix build
-d -S foo |
grep -e 'foo\.tar\.gz'
164 # 'baz' has a replacement so we should be getting the replacement's source.
165 (unset GUIX_BUILD_OPTIONS
;
166 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
168 guix build
-d --sources=package foo
169 guix build
-d --sources=package foo |
grep -e 'foo\.tar\.gz'
171 # bar.tar.gz and bar.dat
172 guix build
-d --sources bar
173 test `guix build -d --sources bar \
174 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
177 # bar.tar.gz and bar.dat
178 guix build
-d --sources=all bar
179 test `guix build -d --sources bar \
180 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
183 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
184 guix build
-d --sources=transitive foo
185 test `guix build -d --sources=transitive foo \
186 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
190 # Unbound variable in thunked field.
191 cat > "$module_dir/foo.scm" <<EOF
193 #:use-module (guix tests)
194 #:use-module (guix build-system trivial))
197 (dummy-package "package-with-something-wrong"
198 (build-system trivial-build-system)
199 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
202 ! guix build package-with-something-wrong
-n
203 guix build package-with-something-wrong
-n 2> "$module_dir/err" || true
204 grep "unbound" "$module_dir/err" # actual error
205 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
207 # Unbound variable at the top level.
208 cat > "$module_dir/foo.scm" <<EOF
210 #:use-module (guix tests))
213 (dummy-package "package-with-something-wrong"
214 (build-system gnu-build-system))) ;unbound variable
217 guix build
sed -n 2> "$module_dir/err"
218 grep "unbound" "$module_dir/err" # actual error
219 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
221 rm -f "$module_dir"/*
223 # Unbound variable: don't suggest modules that do not export the variable.
224 cat > "$module_dir/aa-private.scm" <<EOF
225 (define-module (aa-private))
226 (define make-thing #f)
227 (set! make-thing make-thing) ;don't inline
230 cat > "$module_dir/bb-public.scm" <<EOF
231 (define-module (bb-public) #:export (make-thing))
232 (define make-thing identity)
235 cat > "$module_dir/cc-user.scm" <<EOF
236 ;; Make those module available in the global name space.
237 (load-from-path "aa-private.scm")
238 (load-from-path "bb-public.scm")
240 (define-module (cc-user))
243 ! guix build
-f "$module_dir/cc-user.scm" -n 2> "$module_dir/err"
244 cat "$module_dir/err"
245 grep "make-thing.*unbound" "$module_dir/err" # actual error
246 grep "forget.*(bb-public)" "$module_dir/err" # hint
248 rm -f "$module_dir"/*
250 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
251 cat > "$module_dir/foo.scm" <<EOF
252 (define-module (something foo)
256 guix build guile-bootstrap
-n 2> "$module_dir/err"
257 grep "does not match file name" "$module_dir/err"
261 # Should all return valid log files.
262 drv
="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
263 out
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
264 log
="`guix build --log-file $drv`"
265 echo "$log" |
grep log
/.
*guile.
*drv
267 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
269 test "`guix build --log-file guile-bootstrap`" = "$log"
270 test "`guix build --log-file $out`" = "$log"
272 # Should fail because the name/version combination could not be found.
273 ! guix build hello-0.0
.1 -n
275 # Keep a symlink to the result, registered as a root.
277 guix build
-r "$result" \
278 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
279 test -x "$result/bin/guile"
281 # Should fail, because $result already exists.
282 ! guix build
-r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
286 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
288 guix build
-r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
289 test -x "$result/x/bin/guile"
294 guix build coreutils
--target=mips64el-linux-gnu
--dry-run --no-substitutes
296 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
297 guix build
--target=arm-linux-gnueabihf
--dry-run \
298 -e '(@ (gnu packages base) coreutils)'
301 drv1
=`guix build guix --with-input=guile-zstd=idutils -d`
302 drv2
=`guix build guix -d`
303 test "$drv1" != "$drv2"
305 drv1
=`guix build guile -d`
306 drv2
=`guix build guile --with-input=gimp=ruby -d`
307 test "$drv1" = "$drv2"
309 # See <https://bugs.gnu.org/42156>.
310 drv1
=`guix build glib -d`
311 drv2
=`guix build glib -d --with-input=libreoffice=inkscape`
312 test "$drv1" = "$drv2"
314 # '--with-graft' should have no effect when using '--no-grafts'.
315 # See <https://bugs.gnu.org/43890>.
316 drv1
=`guix build inkscape -d --no-grafts`
317 drv2
=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking`
318 test "$drv1" = "$drv2"
320 # Rewriting implicit inputs.
321 drv1
=`guix build hello -d`
322 drv2
=`guix build hello -d --with-input=gcc=gcc-toolchain`
323 test "$drv1" != "$drv2"
324 guix gc
-R "$drv2" |
grep `guix build -d gcc-toolchain`
326 ! guix build guile
--with-input=libunistring
=something-really-silly
328 # Deprecated/superseded packages.
329 test "`guix build superseded -d`" = "`guix build bar -d`"
331 # Parsing package names and versions.
332 guix build
-n time # PASS
333 guix build
-n time@
1.9 # PASS, version found
334 ! guix build
-n time@
3.2 # FAIL, version not found
335 ! guix build
-n something-that-will-never-exist
# FAIL
337 # Invoking a monadic procedure.
338 guix build
-e "(begin
339 (use-modules (guix gexp))
341 (gexp->derivation \"test\"
342 (gexp (mkdir (ungexp output))))))" \
346 guix build
-e '#~(mkdir #$output)' -d
347 guix build
-e '#~(mkdir #$output)' -d |
grep 'gexp\.drv'
349 # Same with a file-like object.
350 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d
351 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d |
grep 'foo\.drv'
353 # Building from a package file.
354 cat > "$module_dir/package.scm"<<EOF
356 (use-package-modules bootstrap)
360 guix build
--file="$module_dir/package.scm"
362 # Building from a monadic procedure file.
363 cat > "$module_dir/proc.scm"<<EOF
364 (use-modules (guix gexp))
366 (gexp->derivation "test"
367 (gexp (mkdir (ungexp output)))))
369 guix build
--file="$module_dir/proc.scm" --dry-run
371 # Building from a gexp file.
372 cat > "$module_dir/gexp.scm"<<EOF
373 (use-modules (guix gexp))
375 (gexp (mkdir (ungexp output)))
377 guix build
--file="$module_dir/gexp.scm" -d
378 guix build
--file="$module_dir/gexp.scm" -d |
grep 'gexp\.drv'
380 # Building from a manifest file.
381 cat > "$module_dir/manifest.scm"<<EOF
382 (specifications->manifest '("hello" "guix"))
384 test `guix build -d --manifest="$module_dir/manifest.scm" \
385 | grep -e '-hello-' -e '-guix-' \
388 # Building from a manifest that contains a non-package object.
389 cat > "$module_dir/manifest.scm"<<EOF
391 (list (manifest-entry (name "foo") (version "0")
392 (item (computed-file "computed-thingie"
393 #~(mkdir (ungexp output)))))))
395 guix build
-d -m "$module_dir/manifest.scm" \
396 |
grep 'computed-thingie\.drv$'
398 rm "$module_dir"/*.scm
400 # Using 'GUIX_BUILD_OPTIONS'.
401 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
402 export GUIX_BUILD_OPTIONS
406 GUIX_BUILD_OPTIONS
="--something-completely-crazy"