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> |
97298ffa | 3 | # |
233e7676 | 4 | # This file is part of GNU Guix. |
97298ffa | 5 | # |
233e7676 | 6 | # GNU Guix is free software; you can redistribute it and/or modify it |
97298ffa LC |
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 | # | |
233e7676 | 11 | # GNU Guix is distributed in the hope that it will be useful, but |
97298ffa LC |
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 | |
233e7676 | 17 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
97298ffa LC |
18 | |
19 | # | |
e49951eb | 20 | # Test the `guix build' command-line utility. |
97298ffa LC |
21 | # |
22 | ||
e49951eb | 23 | guix build --version |
97298ffa LC |
24 | |
25 | # Should fail. | |
e49951eb | 26 | if guix build -e +; |
912209ee LC |
27 | then false; else true; fi |
28 | ||
d223ac4a LC |
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`" = "" | |
97298ffa LC |
32 | |
33 | # Should pass. | |
af9142dc | 34 | guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \ |
97298ffa | 35 | grep -e '-guile-' |
e49951eb | 36 | guix build hello -d | \ |
97298ffa LC |
37 | grep -e '-hello-[0-9\.]\+\.drv$' |
38 | ||
1397b422 | 39 | # Passing a URI. |
a87d66f3 | 40 | GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \ |
1397b422 LC |
41 | guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
42 | ||
43 | ( if GUIX_DAEMON_SOCKET="weird://uri" \ | |
44 | guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \ | |
45 | then exit 1; fi ) | |
46 | ||
2cdfe13d EB |
47 | # Check --sources option with its arguments |
48 | module_dir="t-guix-build-$$" | |
49 | mkdir "$module_dir" | |
50 | trap "rm -rf $module_dir" EXIT | |
51 | ||
52 | cat > "$module_dir/foo.scm"<<EOF | |
53 | (define-module (foo) | |
94d609ab | 54 | #:use-module (guix tests) |
2cdfe13d EB |
55 | #:use-module (guix packages) |
56 | #:use-module (guix download) | |
57 | #:use-module (guix build-system trivial)) | |
58 | ||
59 | (define-public foo | |
60 | (package | |
61 | (name "foo") | |
62 | (version "42") | |
63 | (source (origin | |
64 | (method url-fetch) | |
65 | (uri "http://www.example.com/foo.tar.gz") | |
66 | (sha256 | |
67 | (base32 | |
68 | "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")))) | |
69 | (build-system trivial-build-system) | |
70 | (inputs | |
71 | (quasiquote (("bar" ,bar)))) | |
72 | (home-page "www.example.com") | |
73 | (synopsis "Dummy package") | |
74 | (description "foo is a dummy package for testing.") | |
75 | (license #f))) | |
76 | ||
77 | (define-public bar | |
78 | (package | |
79 | (name "bar") | |
80 | (version "9001") | |
81 | (source (origin | |
82 | (method url-fetch) | |
83 | (uri "http://www.example.com/bar.tar.gz") | |
84 | (sha256 | |
85 | (base32 | |
86 | "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy")))) | |
87 | (build-system trivial-build-system) | |
88 | (inputs | |
89 | (quasiquote | |
90 | (("data" ,(origin | |
91 | (method url-fetch) | |
92 | (uri "http://www.example.com/bar.dat") | |
93 | (sha256 | |
94 | (base32 | |
95 | "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"))))))) | |
96 | (home-page "www.example.com") | |
97 | (synopsis "Dummy package") | |
98 | (description "bar is a dummy package for testing.") | |
99 | (license #f))) | |
94d609ab LC |
100 | |
101 | (define-public baz | |
102 | (dummy-package "baz" (replacement foo))) | |
103 | ||
01afdab8 LC |
104 | (define-public superseded |
105 | (deprecated-package "superseded" bar)) | |
106 | ||
2cdfe13d EB |
107 | EOF |
108 | ||
109 | GUIX_PACKAGE_PATH="$module_dir" | |
110 | export GUIX_PACKAGE_PATH | |
111 | ||
112 | # foo.tar.gz | |
113 | guix build -d -S foo | |
114 | guix build -d -S foo | grep -e 'foo\.tar\.gz' | |
115 | ||
94d609ab LC |
116 | # 'baz' has a replacement so we should be getting the replacement's source. |
117 | (unset GUIX_BUILD_OPTIONS; | |
118 | test "`guix build -d -S baz`" = "`guix build -d -S foo`") | |
119 | ||
2cdfe13d EB |
120 | guix build -d --sources=package foo |
121 | guix build -d --sources=package foo | grep -e 'foo\.tar\.gz' | |
122 | ||
123 | # bar.tar.gz and bar.dat | |
124 | guix build -d --sources bar | |
125 | test `guix build -d --sources bar \ | |
126 | | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \ | |
127 | | wc -l` -eq 2 | |
128 | ||
129 | # bar.tar.gz and bar.dat | |
130 | guix build -d --sources=all bar | |
131 | test `guix build -d --sources bar \ | |
132 | | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \ | |
133 | | wc -l` -eq 2 | |
134 | ||
135 | # Should include foo.tar.gz, bar.tar.gz, and bar.dat | |
136 | guix build -d --sources=transitive foo | |
137 | test `guix build -d --sources=transitive foo \ | |
138 | | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \ | |
139 | | wc -l` -eq 3 | |
140 | ||
2d2f98ef LC |
141 | |
142 | # Unbound variables. | |
143 | cat > "$module_dir/foo.scm"<<EOF | |
144 | (define-module (foo) | |
145 | #:use-module (guix tests) | |
146 | #:use-module (guix build-system trivial)) | |
147 | ||
148 | (define-public foo | |
149 | (dummy-package "package-with-something-wrong" | |
150 | (build-system trivial-build-system) | |
151 | (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable | |
152 | EOF | |
153 | ||
154 | if guix build package-with-something-wrong -n; then false; else true; fi | |
155 | guix build package-with-something-wrong -n 2> "$module_dir/err" || true | |
156 | grep "unbound" "$module_dir/err" # actual error | |
157 | grep "forget.*(gnu packages base)" "$module_dir/err" # hint | |
158 | rm -f "$module_dir"/* | |
159 | ||
bf421152 | 160 | # Should all return valid log files. |
af9142dc LC |
161 | drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" |
162 | out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" | |
bf421152 LC |
163 | log="`guix build --log-file $drv`" |
164 | echo "$log" | grep log/.*guile.*drv | |
165 | test -f "$log" | |
af9142dc | 166 | test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \ |
bf421152 LC |
167 | = "$log" |
168 | test "`guix build --log-file guile-bootstrap`" = "$log" | |
169 | test "`guix build --log-file $out`" = "$log" | |
170 | ||
97298ffa | 171 | # Should fail because the name/version combination could not be found. |
e49951eb | 172 | if guix build hello-0.0.1 -n; then false; else true; fi |
97298ffa LC |
173 | |
174 | # Keep a symlink to the result, registered as a root. | |
175 | result="t-result-$$" | |
e49951eb | 176 | guix build -r "$result" \ |
af9142dc | 177 | -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
97298ffa LC |
178 | test -x "$result/bin/guile" |
179 | ||
180 | # Should fail, because $result already exists. | |
af9142dc | 181 | if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' |
97298ffa LC |
182 | then false; else true; fi |
183 | ||
184 | rm -f "$result" | |
5401dd75 | 185 | |
4aea820f LC |
186 | # Check relative file name canonicalization: <https://bugs.gnu.org/35271>. |
187 | mkdir "$result" | |
188 | guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | |
189 | test -x "$result/x/bin/guile" | |
190 | rm "$result/x" | |
191 | rmdir "$result" | |
192 | ||
e55ec43d LC |
193 | # Cross building. |
194 | guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes | |
195 | ||
47c0f92c | 196 | # Replacements. |
f6396d86 | 197 | drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d` |
47c0f92c LC |
198 | drv2=`guix build guix -d` |
199 | test "$drv1" != "$drv2" | |
200 | ||
201 | drv1=`guix build guile -d` | |
202 | drv2=`guix build guile --with-input=gimp=ruby -d` | |
203 | test "$drv1" = "$drv2" | |
204 | ||
205 | if guix build guile --with-input=libunistring=something-really-silly | |
206 | then false; else true; fi | |
207 | ||
01afdab8 LC |
208 | # Deprecated/superseded packages. |
209 | test "`guix build superseded -d`" = "`guix build bar -d`" | |
210 | ||
5401dd75 | 211 | # Parsing package names and versions. |
e49951eb | 212 | guix build -n time # PASS |
64f925cb | 213 | guix build -n time@1.9 # PASS, version found |
1b846da8 | 214 | if guix build -n time@3.2; # FAIL, version not found |
5401dd75 | 215 | then false; else true; fi |
e49951eb | 216 | if guix build -n something-that-will-never-exist; # FAIL |
5401dd75 | 217 | then false; else true; fi |
ac5de156 LC |
218 | |
219 | # Invoking a monadic procedure. | |
220 | guix build -e "(begin | |
ada3df03 | 221 | (use-modules (guix gexp)) |
ac5de156 | 222 | (lambda () |
ada3df03 LC |
223 | (gexp->derivation \"test\" |
224 | (gexp (mkdir (ungexp output))))))" \ | |
ac5de156 | 225 | --dry-run |
56b82106 LC |
226 | |
227 | # Running a gexp. | |
228 | guix build -e '#~(mkdir #$output)' -d | |
229 | guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv' | |
16eb115e | 230 | |
b33e191c LC |
231 | # Same with a file-like object. |
232 | guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | |
233 | guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv' | |
234 | ||
34a1783f DT |
235 | # Building from a package file. |
236 | cat > "$module_dir/package.scm"<<EOF | |
237 | (use-modules (gnu)) | |
238 | (use-package-modules bootstrap) | |
239 | ||
240 | %bootstrap-guile | |
241 | EOF | |
242 | guix build --file="$module_dir/package.scm" | |
243 | ||
244 | # Building from a monadic procedure file. | |
245 | cat > "$module_dir/proc.scm"<<EOF | |
246 | (use-modules (guix gexp)) | |
247 | (lambda () | |
248 | (gexp->derivation "test" | |
249 | (gexp (mkdir (ungexp output))))) | |
250 | EOF | |
251 | guix build --file="$module_dir/proc.scm" --dry-run | |
252 | ||
253 | # Building from a gexp file. | |
254 | cat > "$module_dir/gexp.scm"<<EOF | |
255 | (use-modules (guix gexp)) | |
256 | ||
257 | (gexp (mkdir (ungexp output))) | |
258 | EOF | |
259 | guix build --file="$module_dir/gexp.scm" -d | |
260 | guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv' | |
261 | ||
16eb115e | 262 | # Using 'GUIX_BUILD_OPTIONS'. |
442a6ff5 | 263 | GUIX_BUILD_OPTIONS="--dry-run --no-grafts" |
16eb115e DP |
264 | export GUIX_BUILD_OPTIONS |
265 | ||
266 | guix build emacs | |
267 | ||
268 | GUIX_BUILD_OPTIONS="--something-completely-crazy" | |
269 | if guix build emacs; | |
270 | then false; else true; fi |