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 GUIX_DAEMON_SOCKET
="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
41 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
43 ( if GUIX_DAEMON_SOCKET
="weird://uri" \
44 guix build
-e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
47 # Passing one '-s' flag.
48 test `guix build sed -s x86_64-linux -d | wc -l` = 1
50 # Passing multiple '-s' flags.
51 all_systems
="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux"
52 test `guix build sed $all_systems -d | sort -u | wc -l` = 4
54 # Check --sources option with its arguments
55 module_dir
="t-guix-build-$$"
57 trap "rm -rf $module_dir" EXIT
59 cat > "$module_dir/foo.scm"<<EOF
61 #:use-module (guix tests)
62 #:use-module (guix packages)
63 #:use-module (guix download)
64 #:use-module (guix build-system trivial))
72 (uri "http://www.example.com/foo.tar.gz")
75 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
76 (build-system trivial-build-system)
78 (quasiquote (("bar" ,bar))))
79 (home-page "www.example.com")
80 (synopsis "Dummy package")
81 (description "foo is a dummy package for testing.")
90 (uri "http://www.example.com/bar.tar.gz")
93 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
94 (build-system trivial-build-system)
99 (uri "http://www.example.com/bar.dat")
102 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
103 (home-page "www.example.com")
104 (synopsis "Dummy package")
105 (description "bar is a dummy package for testing.")
109 (dummy-package "baz" (replacement foo)))
111 (define-public superseded
112 (deprecated-package "superseded" bar))
116 GUIX_PACKAGE_PATH
="$module_dir"
117 export GUIX_PACKAGE_PATH
121 guix build
-d -S foo |
grep -e 'foo\.tar\.gz'
123 # 'baz' has a replacement so we should be getting the replacement's source.
124 (unset GUIX_BUILD_OPTIONS
;
125 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
127 guix build
-d --sources=package foo
128 guix build
-d --sources=package foo |
grep -e 'foo\.tar\.gz'
130 # bar.tar.gz and bar.dat
131 guix build
-d --sources bar
132 test `guix build -d --sources bar \
133 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
136 # bar.tar.gz and bar.dat
137 guix build
-d --sources=all bar
138 test `guix build -d --sources bar \
139 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
142 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
143 guix build
-d --sources=transitive foo
144 test `guix build -d --sources=transitive foo \
145 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
149 # Unbound variable in thunked field.
150 cat > "$module_dir/foo.scm" <<EOF
152 #:use-module (guix tests)
153 #:use-module (guix build-system trivial))
156 (dummy-package "package-with-something-wrong"
157 (build-system trivial-build-system)
158 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
161 if guix build package-with-something-wrong
-n; then false
; else true
; fi
162 guix build package-with-something-wrong
-n 2> "$module_dir/err" || true
163 grep "unbound" "$module_dir/err" # actual error
164 grep "forget.*(gnu packages base)" "$module_dir/err" # hint
166 # Unbound variable at the top level.
167 cat > "$module_dir/foo.scm" <<EOF
169 #:use-module (guix tests))
172 (dummy-package "package-with-something-wrong"
173 (build-system gnu-build-system))) ;unbound variable
176 guix build
sed -n 2> "$module_dir/err"
177 grep "unbound" "$module_dir/err" # actual error
178 grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
180 rm -f "$module_dir"/*
182 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
183 cat > "$module_dir/foo.scm" <<EOF
184 (define-module (something foo)
188 guix build guile-bootstrap
-n 2> "$module_dir/err"
189 grep "does not match file name" "$module_dir/err"
193 # Should all return valid log files.
194 drv
="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
195 out
="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
196 log
="`guix build --log-file $drv`"
197 echo "$log" |
grep log
/.
*guile.
*drv
199 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
201 test "`guix build --log-file guile-bootstrap`" = "$log"
202 test "`guix build --log-file $out`" = "$log"
204 # Should fail because the name/version combination could not be found.
205 if guix build hello-0.0
.1 -n; then false
; else true
; fi
207 # Keep a symlink to the result, registered as a root.
209 guix build
-r "$result" \
210 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
211 test -x "$result/bin/guile"
213 # Should fail, because $result already exists.
214 if guix build
-r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
215 then false
; else true
; fi
219 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
221 guix build
-r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
222 test -x "$result/x/bin/guile"
227 guix build coreutils
--target=mips64el-linux-gnu
--dry-run --no-substitutes
229 # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
230 guix build
--target=arm-linux-gnueabihf
--dry-run \
231 -e '(@ (gnu packages base) coreutils)'
234 drv1
=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
235 drv2
=`guix build guix -d`
236 test "$drv1" != "$drv2"
238 drv1
=`guix build guile -d`
239 drv2
=`guix build guile --with-input=gimp=ruby -d`
240 test "$drv1" = "$drv2"
242 if guix build guile
--with-input=libunistring
=something-really-silly
243 then false
; else true
; fi
245 # Deprecated/superseded packages.
246 test "`guix build superseded -d`" = "`guix build bar -d`"
248 # Parsing package names and versions.
249 guix build
-n time # PASS
250 guix build
-n time@
1.9 # PASS, version found
251 if guix build
-n time@
3.2; # FAIL, version not found
252 then false
; else true
; fi
253 if guix build
-n something-that-will-never-exist
; # FAIL
254 then false
; else true
; fi
256 # Invoking a monadic procedure.
257 guix build
-e "(begin
258 (use-modules (guix gexp))
260 (gexp->derivation \"test\"
261 (gexp (mkdir (ungexp output))))))" \
265 guix build
-e '#~(mkdir #$output)' -d
266 guix build
-e '#~(mkdir #$output)' -d |
grep 'gexp\.drv'
268 # Same with a file-like object.
269 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d
270 guix build
-e '(computed-file "foo" #~(mkdir #$output))' -d |
grep 'foo\.drv'
272 # Building from a package file.
273 cat > "$module_dir/package.scm"<<EOF
275 (use-package-modules bootstrap)
279 guix build
--file="$module_dir/package.scm"
281 # Building from a monadic procedure file.
282 cat > "$module_dir/proc.scm"<<EOF
283 (use-modules (guix gexp))
285 (gexp->derivation "test"
286 (gexp (mkdir (ungexp output)))))
288 guix build
--file="$module_dir/proc.scm" --dry-run
290 # Building from a gexp file.
291 cat > "$module_dir/gexp.scm"<<EOF
292 (use-modules (guix gexp))
294 (gexp (mkdir (ungexp output)))
296 guix build
--file="$module_dir/gexp.scm" -d
297 guix build
--file="$module_dir/gexp.scm" -d |
grep 'gexp\.drv'
298 rm "$module_dir"/*.scm
300 # Using 'GUIX_BUILD_OPTIONS'.
301 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
302 export GUIX_BUILD_OPTIONS
306 GUIX_BUILD_OPTIONS
="--something-completely-crazy"
308 then false
; else true
; fi