1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 # This file is part of GNU Guix.
6 # GNU Guix is free software; you can redistribute it and/or modify it
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.
11 # GNU Guix is distributed in the hope that it will be useful, but
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.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 # Test the `guix build' command-line utility.
27 then false
; else true
; fi
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 --sources option with its arguments
68 module_dir
="t-guix-build-$$"
70 trap "rm -rf $module_dir" EXIT
72 cat > "$module_dir/foo.scm"<<EOF
74 #:use-module (guix tests)
75 #:use-module (guix packages)
76 #:use-module (guix download)
77 #:use-module (guix build-system trivial))
85 (uri "http://www.example.com/foo.tar.gz")
88 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
89 (build-system trivial-build-system)
91 (quasiquote (("bar" ,bar))))
92 (home-page "www.example.com")
93 (synopsis "Dummy package")
94 (description "foo is a dummy package for testing.")
103 (uri "http://www.example.com/bar.tar.gz")
106 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
107 (build-system trivial-build-system)
112 (uri "http://www.example.com/bar.dat")
115 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
116 (home-page "www.example.com")
117 (synopsis "Dummy package")
118 (description "bar is a dummy package for testing.")
122 (dummy-package "baz" (replacement foo)))
124 (define-public superseded
125 (deprecated-package "superseded" bar))
129 GUIX_PACKAGE_PATH
="$module_dir"
130 export GUIX_PACKAGE_PATH
134 guix build
-d -S foo |
grep -e 'foo\.tar\.gz'
136 # 'baz' has a replacement so we should be getting the replacement's source.
137 (unset GUIX_BUILD_OPTIONS
;
138 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
140 guix build
-d --sources=package foo
141 guix build
-d --sources=package foo |
grep -e 'foo\.tar\.gz'
143 # bar.tar.gz and bar.dat
144 guix build
-d --sources bar
145 test `guix build -d --sources bar \
146 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
149 # bar.tar.gz and bar.dat
150 guix build
-d --sources=all bar
151 test `guix build -d --sources bar \
152 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
155 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
156 guix build
-d --sources=transitive foo
157 test `guix build -d --sources=transitive foo \
158 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
162 # Unbound variable in thunked field.
163 cat > "$module_dir/foo.scm" <<EOF
165 #:use-module (guix tests)
166 #:use-module (guix build-system trivial))
169 (dummy-package "package-with-something-wrong"
170 (build-system trivial-build-system)
171 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
174 if guix build package-with-something-wrong
-n; then false
; else true
; fi
175 guix build package-with-something-wrong
-n 2> "$module_dir/err" || true
176 grep "unbound" "$module_dir/err" # actual error
177 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
179 # Unbound variable at the top level.
180 cat > "$module_dir/foo.scm" <<EOF
182 #:use-module (guix tests))
185 (dummy-package "package-with-something-wrong"
186 (build-system gnu-build-system))) ;unbound variable
189 guix build
sed -n 2> "$module_dir/err"
190 grep "unbound" "$module_dir/err" # actual error
191 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
193 rm -f "$module_dir"/*
195 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
196 cat > "$module_dir/foo.scm" <<EOF
197 (define-module (something foo)
201 guix build guile-bootstrap
-n 2> "$module_dir/err"
202 grep "does not match file name" "$module_dir/err"
206 # Should all return valid log files.
207 drv
="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
208 out
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
209 log
="`guix build --log-file $drv`"
210 echo "$log" |
grep log
/.
*guile.
*drv
212 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
214 test "`guix build --log-file guile-bootstrap`" = "$log"
215 test "`guix build --log-file $out`" = "$log"
217 # Should fail because the name/version combination could not be found.
218 if guix build hello-0.0
.1 -n; then false
; else true
; fi
220 # Keep a symlink to the result, registered as a root.
222 guix build
-r "$result" \
223 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
224 test -x "$result/bin/guile"
226 # Should fail, because $result already exists.
227 if guix build
-r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
228 then false
; else true
; fi
232 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
234 guix build
-r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
235 test -x "$result/x/bin/guile"
240 guix build coreutils
--target=mips64el-linux-gnu
--dry-run --no-substitutes
242 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
243 guix build
--target=arm-linux-gnueabihf
--dry-run \
244 -e '(@ (gnu packages base) coreutils)'
247 drv1
=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
248 drv2
=`guix build guix -d`
249 test "$drv1" != "$drv2"
251 drv1
=`guix build guile -d`
252 drv2
=`guix build guile --with-input=gimp=ruby -d`
253 test "$drv1" = "$drv2"
255 if guix build guile
--with-input=libunistring
=something-really-silly
256 then false
; else true
; fi
258 # Deprecated/superseded packages.
259 test "`guix build superseded -d`" = "`guix build bar -d`"
261 # Parsing package names and versions.
262 guix build
-n time # PASS
263 guix build
-n time@
1.9 # PASS, version found
264 if guix build
-n time@
3.2; # FAIL, version not found
265 then false
; else true
; fi
266 if guix build
-n something-that-will-never-exist
; # FAIL
267 then false
; else true
; fi
269 # Invoking a monadic procedure.
270 guix build
-e "(begin
271 (use-modules (guix gexp))
273 (gexp->derivation \"test\"
274 (gexp (mkdir (ungexp output))))))" \
278 guix build
-e '#~(mkdir #$output)' -d
279 guix build
-e '#~(mkdir #$output)' -d |
grep 'gexp\.drv'
281 # Same with a file-like object.
282 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d
283 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d |
grep 'foo\.drv'
285 # Building from a package file.
286 cat > "$module_dir/package.scm"<<EOF
288 (use-package-modules bootstrap)
292 guix build
--file="$module_dir/package.scm"
294 # Building from a monadic procedure file.
295 cat > "$module_dir/proc.scm"<<EOF
296 (use-modules (guix gexp))
298 (gexp->derivation "test"
299 (gexp (mkdir (ungexp output)))))
301 guix build
--file="$module_dir/proc.scm" --dry-run
303 # Building from a gexp file.
304 cat > "$module_dir/gexp.scm"<<EOF
305 (use-modules (guix gexp))
307 (gexp (mkdir (ungexp output)))
309 guix build
--file="$module_dir/gexp.scm" -d
310 guix build
--file="$module_dir/gexp.scm" -d |
grep 'gexp\.drv'
311 rm "$module_dir"/*.scm
313 # Using 'GUIX_BUILD_OPTIONS'.
314 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
315 export GUIX_BUILD_OPTIONS
319 GUIX_BUILD_OPTIONS
="--something-completely-crazy"
321 then false
; else true
; fi