1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
5 # This file is part of GNU Guix.
7 # GNU Guix is free software; you can redistribute it and/or modify it
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.
12 # GNU Guix is distributed in the hope that it will be useful, but
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.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 # Test the `guix build' command-line utility.
29 # Source-less packages are accepted; they just return nothing.
30 guix build
-e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
31 test "`guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S`" = ""
34 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
36 guix build hello
-d | \
37 grep -e '-hello-[0-9\.]\+\.drv$'
40 drv
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
41 out
="`guix build "$drv"`"
42 out2
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
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
49 guix build
"$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
50 |
grep "missing derivation"
53 GUIX_DAEMON_SOCKET
="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
54 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
56 ( if GUIX_DAEMON_SOCKET
="weird://uri" \
57 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
60 # Passing one '-s' flag.
61 test `guix build sed -s x86_64-linux -d | wc -l` = 1
63 # Passing multiple '-s' flags.
64 all_systems
="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux"
65 test `guix build sed $all_systems -d | sort -u | wc -l` = 4
67 # Check there's no weird memoization effect leading to erroneous results.
68 # See <https://bugs.gnu.org/40482>.
69 drv1
="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
70 drv2
="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
71 test "$drv1" = "$drv2"
73 # Check --sources option with its arguments
74 module_dir
="t-guix-build-$$"
76 trap "rm -rf $module_dir" EXIT
78 cat > "$module_dir/foo.scm"<<EOF
80 #:use-module (guix tests)
81 #:use-module (guix packages)
82 #:use-module (guix download)
83 #:use-module (guix build-system trivial))
91 (uri "http://www.example.com/foo.tar.gz")
94 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
95 (build-system trivial-build-system)
97 (quasiquote (("bar" ,bar))))
98 (home-page "www.example.com")
99 (synopsis "Dummy package")
100 (description "foo is a dummy package for testing.")
109 (uri "http://www.example.com/bar.tar.gz")
112 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
113 (build-system trivial-build-system)
118 (uri "http://www.example.com/bar.dat")
121 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
122 (home-page "www.example.com")
123 (synopsis "Dummy package")
124 (description "bar is a dummy package for testing.")
128 (dummy-package "baz" (replacement foo)))
130 (define-public superseded
131 (deprecated-package "superseded" bar))
135 GUIX_PACKAGE_PATH
="$module_dir"
136 export GUIX_PACKAGE_PATH
140 guix build
-d -S foo |
grep -e 'foo\.tar\.gz'
142 # 'baz' has a replacement so we should be getting the replacement's source.
143 (unset GUIX_BUILD_OPTIONS
;
144 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
146 guix build
-d --sources=package foo
147 guix build
-d --sources=package foo |
grep -e 'foo\.tar\.gz'
149 # bar.tar.gz and bar.dat
150 guix build
-d --sources bar
151 test `guix build -d --sources bar \
152 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
155 # bar.tar.gz and bar.dat
156 guix build
-d --sources=all bar
157 test `guix build -d --sources bar \
158 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
161 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
162 guix build
-d --sources=transitive foo
163 test `guix build -d --sources=transitive foo \
164 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
168 # Unbound variable in thunked field.
169 cat > "$module_dir/foo.scm" <<EOF
171 #:use-module (guix tests)
172 #:use-module (guix build-system trivial))
175 (dummy-package "package-with-something-wrong"
176 (build-system trivial-build-system)
177 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
180 ! guix build package-with-something-wrong
-n
181 guix build package-with-something-wrong
-n 2> "$module_dir/err" || true
182 grep "unbound" "$module_dir/err" # actual error
183 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
185 # Unbound variable at the top level.
186 cat > "$module_dir/foo.scm" <<EOF
188 #:use-module (guix tests))
191 (dummy-package "package-with-something-wrong"
192 (build-system gnu-build-system))) ;unbound variable
195 guix build
sed -n 2> "$module_dir/err"
196 grep "unbound" "$module_dir/err" # actual error
197 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
199 rm -f "$module_dir"/*
201 # Unbound variable: don't suggest modules that do not export the variable.
202 cat > "$module_dir/aa-private.scm" <<EOF
203 (define-module (aa-private))
204 (define make-thing #f)
205 (set! make-thing make-thing) ;don't inline
208 cat > "$module_dir/bb-public.scm" <<EOF
209 (define-module (bb-public) #:export (make-thing))
210 (define make-thing identity)
213 cat > "$module_dir/cc-user.scm" <<EOF
214 ;; Make those module available in the global name space.
215 (load-from-path "aa-private.scm")
216 (load-from-path "bb-public.scm")
218 (define-module (cc-user))
221 ! guix build
-f "$module_dir/cc-user.scm" -n 2> "$module_dir/err"
222 cat "$module_dir/err"
223 grep "make-thing.*unbound" "$module_dir/err" # actual error
224 grep "forget.*(bb-public)" "$module_dir/err" # hint
226 rm -f "$module_dir"/*
228 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
229 cat > "$module_dir/foo.scm" <<EOF
230 (define-module (something foo)
234 guix build guile-bootstrap
-n 2> "$module_dir/err"
235 grep "does not match file name" "$module_dir/err"
239 # Should all return valid log files.
240 drv
="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
241 out
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
242 log
="`guix build --log-file $drv`"
243 echo "$log" |
grep log
/.
*guile.
*drv
245 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
247 test "`guix build --log-file guile-bootstrap`" = "$log"
248 test "`guix build --log-file $out`" = "$log"
250 # Should fail because the name/version combination could not be found.
251 ! guix build hello-0.0
.1 -n
253 # Keep a symlink to the result, registered as a root.
255 guix build
-r "$result" \
256 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
257 test -x "$result/bin/guile"
259 # Should fail, because $result already exists.
260 ! guix build
-r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
264 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
266 guix build
-r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
267 test -x "$result/x/bin/guile"
272 guix build coreutils
--target=mips64el-linux-gnu
--dry-run --no-substitutes
274 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
275 guix build
--target=arm-linux-gnueabihf
--dry-run \
276 -e '(@ (gnu packages base) coreutils)'
279 drv1
=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
280 drv2
=`guix build guix -d`
281 test "$drv1" != "$drv2"
283 drv1
=`guix build guile -d`
284 drv2
=`guix build guile --with-input=gimp=ruby -d`
285 test "$drv1" = "$drv2"
287 # See <https://bugs.gnu.org/42156>.
288 drv1
=`guix build glib -d`
289 drv2
=`guix build glib -d --with-input=libreoffice=inkscape`
290 test "$drv1" = "$drv2"
292 # '--with-graft' should have no effect when using '--no-grafts'.
293 # See <https://bugs.gnu.org/43890>.
294 drv1
=`guix build inkscape -d --no-grafts`
295 drv2
=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking`
296 test "$drv1" = "$drv2"
298 # Rewriting implicit inputs.
299 drv1
=`guix build hello -d`
300 drv2
=`guix build hello -d --with-input=gcc=gcc-toolchain`
301 test "$drv1" != "$drv2"
302 guix gc
-R "$drv2" |
grep `guix build -d gcc-toolchain`
304 ! guix build guile
--with-input=libunistring
=something-really-silly
306 # Deprecated/superseded packages.
307 test "`guix build superseded -d`" = "`guix build bar -d`"
309 # Parsing package names and versions.
310 guix build
-n time # PASS
311 guix build
-n time@
1.9 # PASS, version found
312 ! guix build
-n time@
3.2 # FAIL, version not found
313 ! guix build
-n something-that-will-never-exist
# FAIL
315 # Invoking a monadic procedure.
316 guix build
-e "(begin
317 (use-modules (guix gexp))
319 (gexp->derivation \"test\"
320 (gexp (mkdir (ungexp output))))))" \
324 guix build
-e '#~(mkdir #$output)' -d
325 guix build
-e '#~(mkdir #$output)' -d |
grep 'gexp\.drv'
327 # Same with a file-like object.
328 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d
329 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d |
grep 'foo\.drv'
331 # Building from a package file.
332 cat > "$module_dir/package.scm"<<EOF
334 (use-package-modules bootstrap)
338 guix build
--file="$module_dir/package.scm"
340 # Building from a monadic procedure file.
341 cat > "$module_dir/proc.scm"<<EOF
342 (use-modules (guix gexp))
344 (gexp->derivation "test"
345 (gexp (mkdir (ungexp output)))))
347 guix build
--file="$module_dir/proc.scm" --dry-run
349 # Building from a gexp file.
350 cat > "$module_dir/gexp.scm"<<EOF
351 (use-modules (guix gexp))
353 (gexp (mkdir (ungexp output)))
355 guix build
--file="$module_dir/gexp.scm" -d
356 guix build
--file="$module_dir/gexp.scm" -d |
grep 'gexp\.drv'
358 # Building from a manifest file.
359 cat > "$module_dir/manifest.scm"<<EOF
360 (specifications->manifest '("hello" "guix"))
362 test `guix build -d --manifest="$module_dir/manifest.scm" \
363 | grep -e '-hello-' -e '-guix-' \
366 # Building from a manifest that contains a non-package object.
367 cat > "$module_dir/manifest.scm"<<EOF
369 (list (manifest-entry (name "foo") (version "0")
370 (item (computed-file "computed-thingie"
371 #~(mkdir (ungexp output)))))))
373 guix build
-d -m "$module_dir/manifest.scm" \
374 |
grep 'computed-thingie\.drv$'
376 rm "$module_dir"/*.scm
378 # Using 'GUIX_BUILD_OPTIONS'.
379 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
380 export GUIX_BUILD_OPTIONS
384 GUIX_BUILD_OPTIONS
="--something-completely-crazy"