Commit | Line | Data |
---|---|---|
233e7676 | 1 | # GNU Guix --- Functional package management for GNU |
5a675b2c | 2 | # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
11415d35 | 3 | # Copyright © 2020 Marius Bakke <mbakke@fastmail.com> |
97298ffa | 4 | # |
233e7676 | 5 | # This file is part of GNU Guix. |
97298ffa | 6 | # |
233e7676 | 7 | # GNU Guix is free software; you can redistribute it and/or modify it |
97298ffa LC |
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. | |
11 | # | |
233e7676 | 12 | # GNU Guix is distributed in the hope that it will be useful, but |
97298ffa LC |
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. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
233e7676 | 18 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
97298ffa LC |
19 | |
20 | # | |
e49951eb | 21 | # Test the `guix build' command-line utility. |
97298ffa LC |
22 | # |
23 | ||
e49951eb | 24 | guix build --version |
97298ffa LC |
25 | |
26 | # Should fail. | |
e49951eb | 27 | if guix build -e +; |
912209ee LC |
28 | then false; else true; fi |
29 | ||
d223ac4a LC |
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`" = "" | |
97298ffa LC |
33 | |
34 | # Should pass. | |
af9142dc | 35 | guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \ |
97298ffa | 36 | grep -e '-guile-' |
e49951eb | 37 | guix build hello -d | \ |
97298ffa LC |
38 | grep -e '-hello-[0-9\.]\+\.drv$' |
39 | ||
16ac7403 LC |
40 | # Passing a .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)'`" | |
44 | test "$out" = "$out2" | |
45 | ||
9c9982dc LC |
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 | |
49 | # .drv. | |
50 | guix build "$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \ | |
51 | | grep "missing derivation" | |
52 | ||
1397b422 | 53 | # Passing a URI. |
a87d66f3 | 54 | GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \ |
1397b422 LC |
55 | guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
56 | ||
57 | ( if GUIX_DAEMON_SOCKET="weird://uri" \ | |
58 | guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \ | |
59 | then exit 1; fi ) | |
60 | ||
ea261dea LC |
61 | # Passing one '-s' flag. |
62 | test `guix build sed -s x86_64-linux -d | wc -l` = 1 | |
63 | ||
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 | |
67 | ||
e85d4cec LC |
68 | # Check there's no weird memoization effect leading to erroneous results. |
69 | # See <https://bugs.gnu.org/40482>. | |
70 | drv1="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`" | |
71 | drv2="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`" | |
72 | test "$drv1" = "$drv2" | |
73 | ||
2cdfe13d EB |
74 | # Check --sources option with its arguments |
75 | module_dir="t-guix-build-$$" | |
76 | mkdir "$module_dir" | |
77 | trap "rm -rf $module_dir" EXIT | |
78 | ||
79 | cat > "$module_dir/foo.scm"<<EOF | |
80 | (define-module (foo) | |
94d609ab | 81 | #:use-module (guix tests) |
2cdfe13d EB |
82 | #:use-module (guix packages) |
83 | #:use-module (guix download) | |
84 | #:use-module (guix build-system trivial)) | |
85 | ||
86 | (define-public foo | |
87 | (package | |
88 | (name "foo") | |
89 | (version "42") | |
90 | (source (origin | |
91 | (method url-fetch) | |
92 | (uri "http://www.example.com/foo.tar.gz") | |
93 | (sha256 | |
94 | (base32 | |
95 | "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")))) | |
96 | (build-system trivial-build-system) | |
97 | (inputs | |
98 | (quasiquote (("bar" ,bar)))) | |
99 | (home-page "www.example.com") | |
100 | (synopsis "Dummy package") | |
101 | (description "foo is a dummy package for testing.") | |
102 | (license #f))) | |
103 | ||
104 | (define-public bar | |
105 | (package | |
106 | (name "bar") | |
107 | (version "9001") | |
108 | (source (origin | |
109 | (method url-fetch) | |
110 | (uri "http://www.example.com/bar.tar.gz") | |
111 | (sha256 | |
112 | (base32 | |
113 | "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy")))) | |
114 | (build-system trivial-build-system) | |
115 | (inputs | |
116 | (quasiquote | |
117 | (("data" ,(origin | |
118 | (method url-fetch) | |
119 | (uri "http://www.example.com/bar.dat") | |
120 | (sha256 | |
121 | (base32 | |
122 | "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"))))))) | |
123 | (home-page "www.example.com") | |
124 | (synopsis "Dummy package") | |
125 | (description "bar is a dummy package for testing.") | |
126 | (license #f))) | |
94d609ab LC |
127 | |
128 | (define-public baz | |
129 | (dummy-package "baz" (replacement foo))) | |
130 | ||
01afdab8 LC |
131 | (define-public superseded |
132 | (deprecated-package "superseded" bar)) | |
133 | ||
2cdfe13d EB |
134 | EOF |
135 | ||
136 | GUIX_PACKAGE_PATH="$module_dir" | |
137 | export GUIX_PACKAGE_PATH | |
138 | ||
139 | # foo.tar.gz | |
140 | guix build -d -S foo | |
141 | guix build -d -S foo | grep -e 'foo\.tar\.gz' | |
142 | ||
94d609ab LC |
143 | # 'baz' has a replacement so we should be getting the replacement's source. |
144 | (unset GUIX_BUILD_OPTIONS; | |
145 | test "`guix build -d -S baz`" = "`guix build -d -S foo`") | |
146 | ||
2cdfe13d EB |
147 | guix build -d --sources=package foo |
148 | guix build -d --sources=package foo | grep -e 'foo\.tar\.gz' | |
149 | ||
150 | # bar.tar.gz and bar.dat | |
151 | guix build -d --sources bar | |
152 | test `guix build -d --sources bar \ | |
153 | | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \ | |
154 | | wc -l` -eq 2 | |
155 | ||
156 | # bar.tar.gz and bar.dat | |
157 | guix build -d --sources=all bar | |
158 | test `guix build -d --sources bar \ | |
159 | | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \ | |
160 | | wc -l` -eq 2 | |
161 | ||
162 | # Should include foo.tar.gz, bar.tar.gz, and bar.dat | |
163 | guix build -d --sources=transitive foo | |
164 | test `guix build -d --sources=transitive foo \ | |
165 | | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \ | |
166 | | wc -l` -eq 3 | |
167 | ||
2d2f98ef | 168 | |
723bdb8e LC |
169 | # Unbound variable in thunked field. |
170 | cat > "$module_dir/foo.scm" <<EOF | |
2d2f98ef LC |
171 | (define-module (foo) |
172 | #:use-module (guix tests) | |
173 | #:use-module (guix build-system trivial)) | |
174 | ||
175 | (define-public foo | |
176 | (dummy-package "package-with-something-wrong" | |
177 | (build-system trivial-build-system) | |
178 | (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable | |
179 | EOF | |
180 | ||
181 | if guix build package-with-something-wrong -n; then false; else true; fi | |
182 | guix build package-with-something-wrong -n 2> "$module_dir/err" || true | |
183 | grep "unbound" "$module_dir/err" # actual error | |
184 | grep "forget.*(gnu packages base)" "$module_dir/err" # hint | |
723bdb8e LC |
185 | |
186 | # Unbound variable at the top level. | |
187 | cat > "$module_dir/foo.scm" <<EOF | |
188 | (define-module (foo) | |
189 | #:use-module (guix tests)) | |
190 | ||
191 | (define-public foo | |
192 | (dummy-package "package-with-something-wrong" | |
193 | (build-system gnu-build-system))) ;unbound variable | |
194 | EOF | |
195 | ||
196 | guix build sed -n 2> "$module_dir/err" | |
197 | grep "unbound" "$module_dir/err" # actual error | |
198 | grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint | |
199 | ||
2d2f98ef LC |
200 | rm -f "$module_dir"/* |
201 | ||
a2a94b6e LC |
202 | # Wrong 'define-module' clause reported by 'warn-about-load-error'. |
203 | cat > "$module_dir/foo.scm" <<EOF | |
204 | (define-module (something foo) | |
205 | #:use-module (guix) | |
206 | #:use-module (gnu)) | |
207 | EOF | |
208 | guix build guile-bootstrap -n 2> "$module_dir/err" | |
209 | grep "does not match file name" "$module_dir/err" | |
210 | ||
211 | rm "$module_dir"/* | |
212 | ||
bf421152 | 213 | # Should all return valid log files. |
af9142dc LC |
214 | drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" |
215 | out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" | |
bf421152 LC |
216 | log="`guix build --log-file $drv`" |
217 | echo "$log" | grep log/.*guile.*drv | |
218 | test -f "$log" | |
af9142dc | 219 | test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \ |
bf421152 LC |
220 | = "$log" |
221 | test "`guix build --log-file guile-bootstrap`" = "$log" | |
222 | test "`guix build --log-file $out`" = "$log" | |
223 | ||
97298ffa | 224 | # Should fail because the name/version combination could not be found. |
e49951eb | 225 | if guix build hello-0.0.1 -n; then false; else true; fi |
97298ffa LC |
226 | |
227 | # Keep a symlink to the result, registered as a root. | |
228 | result="t-result-$$" | |
e49951eb | 229 | guix build -r "$result" \ |
af9142dc | 230 | -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
97298ffa LC |
231 | test -x "$result/bin/guile" |
232 | ||
233 | # Should fail, because $result already exists. | |
af9142dc | 234 | if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
97298ffa LC |
235 | then false; else true; fi |
236 | ||
237 | rm -f "$result" | |
5401dd75 | 238 | |
4aea820f LC |
239 | # Check relative file name canonicalization: <https://bugs.gnu.org/35271>. |
240 | mkdir "$result" | |
241 | guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | |
242 | test -x "$result/x/bin/guile" | |
243 | rm "$result/x" | |
244 | rmdir "$result" | |
245 | ||
e55ec43d LC |
246 | # Cross building. |
247 | guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes | |
248 | ||
537b2dab LC |
249 | # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>). |
250 | guix build --target=arm-linux-gnueabihf --dry-run \ | |
251 | -e '(@ (gnu packages base) coreutils)' | |
252 | ||
47c0f92c | 253 | # Replacements. |
f6396d86 | 254 | drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d` |
47c0f92c LC |
255 | drv2=`guix build guix -d` |
256 | test "$drv1" != "$drv2" | |
257 | ||
258 | drv1=`guix build guile -d` | |
259 | drv2=`guix build guile --with-input=gimp=ruby -d` | |
260 | test "$drv1" = "$drv2" | |
261 | ||
262 | if guix build guile --with-input=libunistring=something-really-silly | |
263 | then false; else true; fi | |
264 | ||
01afdab8 LC |
265 | # Deprecated/superseded packages. |
266 | test "`guix build superseded -d`" = "`guix build bar -d`" | |
267 | ||
5401dd75 | 268 | # Parsing package names and versions. |
e49951eb | 269 | guix build -n time # PASS |
64f925cb | 270 | guix build -n time@1.9 # PASS, version found |
1b846da8 | 271 | if guix build -n time@3.2; # FAIL, version not found |
5401dd75 | 272 | then false; else true; fi |
e49951eb | 273 | if guix build -n something-that-will-never-exist; # FAIL |
5401dd75 | 274 | then false; else true; fi |
ac5de156 LC |
275 | |
276 | # Invoking a monadic procedure. | |
277 | guix build -e "(begin | |
ada3df03 | 278 | (use-modules (guix gexp)) |
ac5de156 | 279 | (lambda () |
ada3df03 LC |
280 | (gexp->derivation \"test\" |
281 | (gexp (mkdir (ungexp output))))))" \ | |
ac5de156 | 282 | --dry-run |
56b82106 LC |
283 | |
284 | # Running a gexp. | |
285 | guix build -e '#~(mkdir #$output)' -d | |
286 | guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv' | |
16eb115e | 287 | |
b33e191c LC |
288 | # Same with a file-like object. |
289 | guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | |
290 | guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv' | |
291 | ||
34a1783f DT |
292 | # Building from a package file. |
293 | cat > "$module_dir/package.scm"<<EOF | |
294 | (use-modules (gnu)) | |
295 | (use-package-modules bootstrap) | |
296 | ||
297 | %bootstrap-guile | |
298 | EOF | |
299 | guix build --file="$module_dir/package.scm" | |
300 | ||
301 | # Building from a monadic procedure file. | |
302 | cat > "$module_dir/proc.scm"<<EOF | |
303 | (use-modules (guix gexp)) | |
304 | (lambda () | |
305 | (gexp->derivation "test" | |
306 | (gexp (mkdir (ungexp output))))) | |
307 | EOF | |
308 | guix build --file="$module_dir/proc.scm" --dry-run | |
309 | ||
310 | # Building from a gexp file. | |
311 | cat > "$module_dir/gexp.scm"<<EOF | |
312 | (use-modules (guix gexp)) | |
313 | ||
314 | (gexp (mkdir (ungexp output))) | |
315 | EOF | |
316 | guix build --file="$module_dir/gexp.scm" -d | |
317 | guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv' | |
11415d35 MB |
318 | |
319 | # Building from a manifest file. | |
320 | cat > "$module_dir/manifest.scm"<<EOF | |
321 | (specifications->manifest '("hello" "guix")) | |
322 | EOF | |
323 | test `guix build -d --manifest="$module_dir/manifest.scm" \ | |
324 | | grep -e '-hello-' -e '-guix-' \ | |
325 | | wc -l` -eq 2 | |
5a675b2c LC |
326 | |
327 | # Building from a manifest that contains a non-package object. | |
328 | cat > "$module_dir/manifest.scm"<<EOF | |
329 | (manifest | |
330 | (list (manifest-entry (name "foo") (version "0") | |
331 | (item (computed-file "computed-thingie" | |
332 | #~(mkdir (ungexp output))))))) | |
333 | EOF | |
334 | guix build -d -m "$module_dir/manifest.scm" \ | |
335 | | grep 'computed-thingie\.drv$' | |
336 | ||
a2a94b6e | 337 | rm "$module_dir"/*.scm |
34a1783f | 338 | |
16eb115e | 339 | # Using 'GUIX_BUILD_OPTIONS'. |
442a6ff5 | 340 | GUIX_BUILD_OPTIONS="--dry-run --no-grafts" |
16eb115e DP |
341 | export GUIX_BUILD_OPTIONS |
342 | ||
343 | guix build emacs | |
344 | ||
345 | GUIX_BUILD_OPTIONS="--something-completely-crazy" | |
346 | if guix build emacs; | |
347 | then false; else true; fi |