Commit | Line | Data |
---|---|---|
233e7676 | 1 | # GNU Guix --- Functional package management for GNU |
a87d66f3 | 2 | # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019 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 | ||
2cdfe13d EB |
68 | # Check --sources option with its arguments |
69 | module_dir="t-guix-build-$$" | |
70 | mkdir "$module_dir" | |
71 | trap "rm -rf $module_dir" EXIT | |
72 | ||
73 | cat > "$module_dir/foo.scm"<<EOF | |
74 | (define-module (foo) | |
94d609ab | 75 | #:use-module (guix tests) |
2cdfe13d EB |
76 | #:use-module (guix packages) |
77 | #:use-module (guix download) | |
78 | #:use-module (guix build-system trivial)) | |
79 | ||
80 | (define-public foo | |
81 | (package | |
82 | (name "foo") | |
83 | (version "42") | |
84 | (source (origin | |
85 | (method url-fetch) | |
86 | (uri "http://www.example.com/foo.tar.gz") | |
87 | (sha256 | |
88 | (base32 | |
89 | "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")))) | |
90 | (build-system trivial-build-system) | |
91 | (inputs | |
92 | (quasiquote (("bar" ,bar)))) | |
93 | (home-page "www.example.com") | |
94 | (synopsis "Dummy package") | |
95 | (description "foo is a dummy package for testing.") | |
96 | (license #f))) | |
97 | ||
98 | (define-public bar | |
99 | (package | |
100 | (name "bar") | |
101 | (version "9001") | |
102 | (source (origin | |
103 | (method url-fetch) | |
104 | (uri "http://www.example.com/bar.tar.gz") | |
105 | (sha256 | |
106 | (base32 | |
107 | "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy")))) | |
108 | (build-system trivial-build-system) | |
109 | (inputs | |
110 | (quasiquote | |
111 | (("data" ,(origin | |
112 | (method url-fetch) | |
113 | (uri "http://www.example.com/bar.dat") | |
114 | (sha256 | |
115 | (base32 | |
116 | "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"))))))) | |
117 | (home-page "www.example.com") | |
118 | (synopsis "Dummy package") | |
119 | (description "bar is a dummy package for testing.") | |
120 | (license #f))) | |
94d609ab LC |
121 | |
122 | (define-public baz | |
123 | (dummy-package "baz" (replacement foo))) | |
124 | ||
01afdab8 LC |
125 | (define-public superseded |
126 | (deprecated-package "superseded" bar)) | |
127 | ||
2cdfe13d EB |
128 | EOF |
129 | ||
130 | GUIX_PACKAGE_PATH="$module_dir" | |
131 | export GUIX_PACKAGE_PATH | |
132 | ||
133 | # foo.tar.gz | |
134 | guix build -d -S foo | |
135 | guix build -d -S foo | grep -e 'foo\.tar\.gz' | |
136 | ||
94d609ab LC |
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`") | |
140 | ||
2cdfe13d EB |
141 | guix build -d --sources=package foo |
142 | guix build -d --sources=package foo | grep -e 'foo\.tar\.gz' | |
143 | ||
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' \ | |
148 | | wc -l` -eq 2 | |
149 | ||
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' \ | |
154 | | wc -l` -eq 2 | |
155 | ||
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' \ | |
160 | | wc -l` -eq 3 | |
161 | ||
2d2f98ef | 162 | |
723bdb8e LC |
163 | # Unbound variable in thunked field. |
164 | cat > "$module_dir/foo.scm" <<EOF | |
2d2f98ef LC |
165 | (define-module (foo) |
166 | #:use-module (guix tests) | |
167 | #:use-module (guix build-system trivial)) | |
168 | ||
169 | (define-public foo | |
170 | (dummy-package "package-with-something-wrong" | |
171 | (build-system trivial-build-system) | |
172 | (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable | |
173 | EOF | |
174 | ||
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 | |
723bdb8e LC |
179 | |
180 | # Unbound variable at the top level. | |
181 | cat > "$module_dir/foo.scm" <<EOF | |
182 | (define-module (foo) | |
183 | #:use-module (guix tests)) | |
184 | ||
185 | (define-public foo | |
186 | (dummy-package "package-with-something-wrong" | |
187 | (build-system gnu-build-system))) ;unbound variable | |
188 | EOF | |
189 | ||
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 | |
193 | ||
2d2f98ef LC |
194 | rm -f "$module_dir"/* |
195 | ||
a2a94b6e LC |
196 | # Wrong 'define-module' clause reported by 'warn-about-load-error'. |
197 | cat > "$module_dir/foo.scm" <<EOF | |
198 | (define-module (something foo) | |
199 | #:use-module (guix) | |
200 | #:use-module (gnu)) | |
201 | EOF | |
202 | guix build guile-bootstrap -n 2> "$module_dir/err" | |
203 | grep "does not match file name" "$module_dir/err" | |
204 | ||
205 | rm "$module_dir"/* | |
206 | ||
bf421152 | 207 | # Should all return valid log files. |
af9142dc LC |
208 | drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" |
209 | out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" | |
bf421152 LC |
210 | log="`guix build --log-file $drv`" |
211 | echo "$log" | grep log/.*guile.*drv | |
212 | test -f "$log" | |
af9142dc | 213 | test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \ |
bf421152 LC |
214 | = "$log" |
215 | test "`guix build --log-file guile-bootstrap`" = "$log" | |
216 | test "`guix build --log-file $out`" = "$log" | |
217 | ||
97298ffa | 218 | # Should fail because the name/version combination could not be found. |
e49951eb | 219 | if guix build hello-0.0.1 -n; then false; else true; fi |
97298ffa LC |
220 | |
221 | # Keep a symlink to the result, registered as a root. | |
222 | result="t-result-$$" | |
e49951eb | 223 | guix build -r "$result" \ |
af9142dc | 224 | -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
97298ffa LC |
225 | test -x "$result/bin/guile" |
226 | ||
227 | # Should fail, because $result already exists. | |
af9142dc | 228 | if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
97298ffa LC |
229 | then false; else true; fi |
230 | ||
231 | rm -f "$result" | |
5401dd75 | 232 | |
4aea820f LC |
233 | # Check relative file name canonicalization: <https://bugs.gnu.org/35271>. |
234 | mkdir "$result" | |
235 | guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | |
236 | test -x "$result/x/bin/guile" | |
237 | rm "$result/x" | |
238 | rmdir "$result" | |
239 | ||
e55ec43d LC |
240 | # Cross building. |
241 | guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes | |
242 | ||
537b2dab LC |
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)' | |
246 | ||
47c0f92c | 247 | # Replacements. |
f6396d86 | 248 | drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d` |
47c0f92c LC |
249 | drv2=`guix build guix -d` |
250 | test "$drv1" != "$drv2" | |
251 | ||
252 | drv1=`guix build guile -d` | |
253 | drv2=`guix build guile --with-input=gimp=ruby -d` | |
254 | test "$drv1" = "$drv2" | |
255 | ||
256 | if guix build guile --with-input=libunistring=something-really-silly | |
257 | then false; else true; fi | |
258 | ||
01afdab8 LC |
259 | # Deprecated/superseded packages. |
260 | test "`guix build superseded -d`" = "`guix build bar -d`" | |
261 | ||
5401dd75 | 262 | # Parsing package names and versions. |
e49951eb | 263 | guix build -n time # PASS |
64f925cb | 264 | guix build -n time@1.9 # PASS, version found |
1b846da8 | 265 | if guix build -n time@3.2; # FAIL, version not found |
5401dd75 | 266 | then false; else true; fi |
e49951eb | 267 | if guix build -n something-that-will-never-exist; # FAIL |
5401dd75 | 268 | then false; else true; fi |
ac5de156 LC |
269 | |
270 | # Invoking a monadic procedure. | |
271 | guix build -e "(begin | |
ada3df03 | 272 | (use-modules (guix gexp)) |
ac5de156 | 273 | (lambda () |
ada3df03 LC |
274 | (gexp->derivation \"test\" |
275 | (gexp (mkdir (ungexp output))))))" \ | |
ac5de156 | 276 | --dry-run |
56b82106 LC |
277 | |
278 | # Running a gexp. | |
279 | guix build -e '#~(mkdir #$output)' -d | |
280 | guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv' | |
16eb115e | 281 | |
b33e191c LC |
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' | |
285 | ||
34a1783f DT |
286 | # Building from a package file. |
287 | cat > "$module_dir/package.scm"<<EOF | |
288 | (use-modules (gnu)) | |
289 | (use-package-modules bootstrap) | |
290 | ||
291 | %bootstrap-guile | |
292 | EOF | |
293 | guix build --file="$module_dir/package.scm" | |
294 | ||
295 | # Building from a monadic procedure file. | |
296 | cat > "$module_dir/proc.scm"<<EOF | |
297 | (use-modules (guix gexp)) | |
298 | (lambda () | |
299 | (gexp->derivation "test" | |
300 | (gexp (mkdir (ungexp output))))) | |
301 | EOF | |
302 | guix build --file="$module_dir/proc.scm" --dry-run | |
303 | ||
304 | # Building from a gexp file. | |
305 | cat > "$module_dir/gexp.scm"<<EOF | |
306 | (use-modules (guix gexp)) | |
307 | ||
308 | (gexp (mkdir (ungexp output))) | |
309 | EOF | |
310 | guix build --file="$module_dir/gexp.scm" -d | |
311 | guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv' | |
11415d35 MB |
312 | |
313 | # Building from a manifest file. | |
314 | cat > "$module_dir/manifest.scm"<<EOF | |
315 | (specifications->manifest '("hello" "guix")) | |
316 | EOF | |
317 | test `guix build -d --manifest="$module_dir/manifest.scm" \ | |
318 | | grep -e '-hello-' -e '-guix-' \ | |
319 | | wc -l` -eq 2 | |
a2a94b6e | 320 | rm "$module_dir"/*.scm |
34a1783f | 321 | |
16eb115e | 322 | # Using 'GUIX_BUILD_OPTIONS'. |
442a6ff5 | 323 | GUIX_BUILD_OPTIONS="--dry-run --no-grafts" |
16eb115e DP |
324 | export GUIX_BUILD_OPTIONS |
325 | ||
326 | guix build emacs | |
327 | ||
328 | GUIX_BUILD_OPTIONS="--something-completely-crazy" | |
329 | if guix build emacs; | |
330 | then false; else true; fi |