gnu: Add deprecation notice for 'boost-with-python3'.
[jackhill/guix/guix.git] / tests / guix-build.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 #
4 # This file is part of GNU Guix.
5 #
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.
10 #
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.
15 #
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/>.
18
19 #
20 # Test the `guix build' command-line utility.
21 #
22
23 guix build --version
24
25 # Should fail.
26 if guix build -e +;
27 then false; else true; fi
28
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`" = ""
32
33 # Should pass.
34 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
35 grep -e '-guile-'
36 guix build hello -d | \
37 grep -e '-hello-[0-9\.]\+\.drv$'
38
39 # Passing a .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)'`"
43 test "$out" = "$out2"
44
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
48 # .drv.
49 guix build "$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
50 | grep "missing derivation"
51
52 # Passing a URI.
53 GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
54 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
55
56 ( if GUIX_DAEMON_SOCKET="weird://uri" \
57 guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
58 then exit 1; fi )
59
60 # Passing one '-s' flag.
61 test `guix build sed -s x86_64-linux -d | wc -l` = 1
62
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
66
67 # Check --sources option with its arguments
68 module_dir="t-guix-build-$$"
69 mkdir "$module_dir"
70 trap "rm -rf $module_dir" EXIT
71
72 cat > "$module_dir/foo.scm"<<EOF
73 (define-module (foo)
74 #:use-module (guix tests)
75 #:use-module (guix packages)
76 #:use-module (guix download)
77 #:use-module (guix build-system trivial))
78
79 (define-public foo
80 (package
81 (name "foo")
82 (version "42")
83 (source (origin
84 (method url-fetch)
85 (uri "http://www.example.com/foo.tar.gz")
86 (sha256
87 (base32
88 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
89 (build-system trivial-build-system)
90 (inputs
91 (quasiquote (("bar" ,bar))))
92 (home-page "www.example.com")
93 (synopsis "Dummy package")
94 (description "foo is a dummy package for testing.")
95 (license #f)))
96
97 (define-public bar
98 (package
99 (name "bar")
100 (version "9001")
101 (source (origin
102 (method url-fetch)
103 (uri "http://www.example.com/bar.tar.gz")
104 (sha256
105 (base32
106 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
107 (build-system trivial-build-system)
108 (inputs
109 (quasiquote
110 (("data" ,(origin
111 (method url-fetch)
112 (uri "http://www.example.com/bar.dat")
113 (sha256
114 (base32
115 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
116 (home-page "www.example.com")
117 (synopsis "Dummy package")
118 (description "bar is a dummy package for testing.")
119 (license #f)))
120
121 (define-public baz
122 (dummy-package "baz" (replacement foo)))
123
124 (define-public superseded
125 (deprecated-package "superseded" bar))
126
127 EOF
128
129 GUIX_PACKAGE_PATH="$module_dir"
130 export GUIX_PACKAGE_PATH
131
132 # foo.tar.gz
133 guix build -d -S foo
134 guix build -d -S foo | grep -e 'foo\.tar\.gz'
135
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`")
139
140 guix build -d --sources=package foo
141 guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
142
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' \
147 | wc -l` -eq 2
148
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' \
153 | wc -l` -eq 2
154
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' \
159 | wc -l` -eq 3
160
161
162 # Unbound variable in thunked field.
163 cat > "$module_dir/foo.scm" <<EOF
164 (define-module (foo)
165 #:use-module (guix tests)
166 #:use-module (guix build-system trivial))
167
168 (define-public foo
169 (dummy-package "package-with-something-wrong"
170 (build-system trivial-build-system)
171 (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
172 EOF
173
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
178
179 # Unbound variable at the top level.
180 cat > "$module_dir/foo.scm" <<EOF
181 (define-module (foo)
182 #:use-module (guix tests))
183
184 (define-public foo
185 (dummy-package "package-with-something-wrong"
186 (build-system gnu-build-system))) ;unbound variable
187 EOF
188
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
192
193 rm -f "$module_dir"/*
194
195 # Wrong 'define-module' clause reported by 'warn-about-load-error'.
196 cat > "$module_dir/foo.scm" <<EOF
197 (define-module (something foo)
198 #:use-module (guix)
199 #:use-module (gnu))
200 EOF
201 guix build guile-bootstrap -n 2> "$module_dir/err"
202 grep "does not match file name" "$module_dir/err"
203
204 rm "$module_dir"/*
205
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
211 test -f "$log"
212 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
213 = "$log"
214 test "`guix build --log-file guile-bootstrap`" = "$log"
215 test "`guix build --log-file $out`" = "$log"
216
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
219
220 # Keep a symlink to the result, registered as a root.
221 result="t-result-$$"
222 guix build -r "$result" \
223 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
224 test -x "$result/bin/guile"
225
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
229
230 rm -f "$result"
231
232 # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
233 mkdir "$result"
234 guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
235 test -x "$result/x/bin/guile"
236 rm "$result/x"
237 rmdir "$result"
238
239 # Cross building.
240 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
241
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)'
245
246 # Replacements.
247 drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
248 drv2=`guix build guix -d`
249 test "$drv1" != "$drv2"
250
251 drv1=`guix build guile -d`
252 drv2=`guix build guile --with-input=gimp=ruby -d`
253 test "$drv1" = "$drv2"
254
255 if guix build guile --with-input=libunistring=something-really-silly
256 then false; else true; fi
257
258 # Deprecated/superseded packages.
259 test "`guix build superseded -d`" = "`guix build bar -d`"
260
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
268
269 # Invoking a monadic procedure.
270 guix build -e "(begin
271 (use-modules (guix gexp))
272 (lambda ()
273 (gexp->derivation \"test\"
274 (gexp (mkdir (ungexp output))))))" \
275 --dry-run
276
277 # Running a gexp.
278 guix build -e '#~(mkdir #$output)' -d
279 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
280
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'
284
285 # Building from a package file.
286 cat > "$module_dir/package.scm"<<EOF
287 (use-modules (gnu))
288 (use-package-modules bootstrap)
289
290 %bootstrap-guile
291 EOF
292 guix build --file="$module_dir/package.scm"
293
294 # Building from a monadic procedure file.
295 cat > "$module_dir/proc.scm"<<EOF
296 (use-modules (guix gexp))
297 (lambda ()
298 (gexp->derivation "test"
299 (gexp (mkdir (ungexp output)))))
300 EOF
301 guix build --file="$module_dir/proc.scm" --dry-run
302
303 # Building from a gexp file.
304 cat > "$module_dir/gexp.scm"<<EOF
305 (use-modules (guix gexp))
306
307 (gexp (mkdir (ungexp output)))
308 EOF
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
312
313 # Using 'GUIX_BUILD_OPTIONS'.
314 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
315 export GUIX_BUILD_OPTIONS
316
317 guix build emacs
318
319 GUIX_BUILD_OPTIONS="--something-completely-crazy"
320 if guix build emacs;
321 then false; else true; fi