1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019 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.
28 then false
; else true
; fi
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"
66 test `guix build sed $all_systems -d | sort -u | wc -l` = 4
68 # Check --sources option with its arguments
69 module_dir
="t-guix-build-$$"
71 trap "rm -rf $module_dir" EXIT
73 cat > "$module_dir/foo.scm"<<EOF
75 #:use-module (guix tests)
76 #:use-module (guix packages)
77 #:use-module (guix download)
78 #:use-module (guix build-system trivial))
86 (uri "http://www.example.com/foo.tar.gz")
89 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
90 (build-system trivial-build-system)
92 (quasiquote (("bar" ,bar))))
93 (home-page "www.example.com")
94 (synopsis "Dummy package")
95 (description "foo is a dummy package for testing.")
104 (uri "http://www.example.com/bar.tar.gz")
107 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
108 (build-system trivial-build-system)
113 (uri "http://www.example.com/bar.dat")
116 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
117 (home-page "www.example.com")
118 (synopsis "Dummy package")
119 (description "bar is a dummy package for testing.")
123 (dummy-package "baz" (replacement foo)))
125 (define-public superseded
126 (deprecated-package "superseded" bar))
130 GUIX_PACKAGE_PATH
="$module_dir"
131 export GUIX_PACKAGE_PATH
135 guix build
-d -S foo |
grep -e 'foo\.tar\.gz'
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`")
141 guix build
-d --sources=package foo
142 guix build
-d --sources=package foo |
grep -e 'foo\.tar\.gz'
144 # bar.tar.gz and bar.dat
145 guix build
-d --sources bar
146 test `guix build -d --sources bar \
147 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
150 # bar.tar.gz and bar.dat
151 guix build
-d --sources=all bar
152 test `guix build -d --sources bar \
153 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
156 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
157 guix build
-d --sources=transitive foo
158 test `guix build -d --sources=transitive foo \
159 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
163 # Unbound variable in thunked field.
164 cat > "$module_dir/foo.scm" <<EOF
166 #:use-module (guix tests)
167 #:use-module (guix build-system trivial))
170 (dummy-package "package-with-something-wrong"
171 (build-system trivial-build-system)
172 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
175 if guix build package-with-something-wrong
-n; then false
; else true
; fi
176 guix build package-with-something-wrong
-n 2> "$module_dir/err" || true
177 grep "unbound" "$module_dir/err" # actual error
178 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
180 # Unbound variable at the top level.
181 cat > "$module_dir/foo.scm" <<EOF
183 #:use-module (guix tests))
186 (dummy-package "package-with-something-wrong"
187 (build-system gnu-build-system))) ;unbound variable
190 guix build
sed -n 2> "$module_dir/err"
191 grep "unbound" "$module_dir/err" # actual error
192 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
194 rm -f "$module_dir"/*
196 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
197 cat > "$module_dir/foo.scm" <<EOF
198 (define-module (something foo)
202 guix build guile-bootstrap
-n 2> "$module_dir/err"
203 grep "does not match file name" "$module_dir/err"
207 # Should all return valid log files.
208 drv
="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
209 out
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
210 log
="`guix build --log-file $drv`"
211 echo "$log" |
grep log
/.
*guile.
*drv
213 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
215 test "`guix build --log-file guile-bootstrap`" = "$log"
216 test "`guix build --log-file $out`" = "$log"
218 # Should fail because the name/version combination could not be found.
219 if guix build hello-0.0
.1 -n; then false
; else true
; fi
221 # Keep a symlink to the result, registered as a root.
223 guix build
-r "$result" \
224 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
225 test -x "$result/bin/guile"
227 # Should fail, because $result already exists.
228 if guix build
-r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
229 then false
; else true
; fi
233 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
235 guix build
-r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
236 test -x "$result/x/bin/guile"
241 guix build coreutils
--target=mips64el-linux-gnu
--dry-run --no-substitutes
243 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
244 guix build
--target=arm-linux-gnueabihf
--dry-run \
245 -e '(@ (gnu packages base) coreutils)'
248 drv1
=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
249 drv2
=`guix build guix -d`
250 test "$drv1" != "$drv2"
252 drv1
=`guix build guile -d`
253 drv2
=`guix build guile --with-input=gimp=ruby -d`
254 test "$drv1" = "$drv2"
256 if guix build guile
--with-input=libunistring
=something-really-silly
257 then false
; else true
; fi
259 # Deprecated/superseded packages.
260 test "`guix build superseded -d`" = "`guix build bar -d`"
262 # Parsing package names and versions.
263 guix build
-n time # PASS
264 guix build
-n time@
1.9 # PASS, version found
265 if guix build
-n time@
3.2; # FAIL, version not found
266 then false
; else true
; fi
267 if guix build
-n something-that-will-never-exist
; # FAIL
268 then false
; else true
; fi
270 # Invoking a monadic procedure.
271 guix build
-e "(begin
272 (use-modules (guix gexp))
274 (gexp->derivation \"test\"
275 (gexp (mkdir (ungexp output))))))" \
279 guix build
-e '#~(mkdir #$output)' -d
280 guix build
-e '#~(mkdir #$output)' -d |
grep 'gexp\.drv'
282 # Same with a file-like object.
283 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d
284 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d |
grep 'foo\.drv'
286 # Building from a package file.
287 cat > "$module_dir/package.scm"<<EOF
289 (use-package-modules bootstrap)
293 guix build
--file="$module_dir/package.scm"
295 # Building from a monadic procedure file.
296 cat > "$module_dir/proc.scm"<<EOF
297 (use-modules (guix gexp))
299 (gexp->derivation "test"
300 (gexp (mkdir (ungexp output)))))
302 guix build
--file="$module_dir/proc.scm" --dry-run
304 # Building from a gexp file.
305 cat > "$module_dir/gexp.scm"<<EOF
306 (use-modules (guix gexp))
308 (gexp (mkdir (ungexp output)))
310 guix build
--file="$module_dir/gexp.scm" -d
311 guix build
--file="$module_dir/gexp.scm" -d |
grep 'gexp\.drv'
313 # Building from a manifest file.
314 cat > "$module_dir/manifest.scm"<<EOF
315 (specifications->manifest '("hello" "guix"))
317 test `guix build -d --manifest="$module_dir/manifest.scm" \
318 | grep -e '-hello-' -e '-guix-' \
320 rm "$module_dir"/*.scm
322 # Using 'GUIX_BUILD_OPTIONS'.
323 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
324 export GUIX_BUILD_OPTIONS
328 GUIX_BUILD_OPTIONS
="--something-completely-crazy"
330 then false
; else true
; fi