gnu: time: Update to 1.9.
[jackhill/guix/guix.git] / tests / guix-build.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016, 2017 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 URI.
40 GUIX_DAEMON_SOCKET="file://$NIX_STATE_DIR/daemon-socket/socket" \
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
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)
54 #:use-module (guix tests)
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)))
100
101 (define-public baz
102 (dummy-package "baz" (replacement foo)))
103
104 (define-public superseded
105 (deprecated-package "superseded" bar))
106
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
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
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
141 # Should all return valid log files.
142 drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
143 out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
144 log="`guix build --log-file $drv`"
145 echo "$log" | grep log/.*guile.*drv
146 test -f "$log"
147 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
148 = "$log"
149 test "`guix build --log-file guile-bootstrap`" = "$log"
150 test "`guix build --log-file $out`" = "$log"
151
152 # Should fail because the name/version combination could not be found.
153 if guix build hello-0.0.1 -n; then false; else true; fi
154
155 # Keep a symlink to the result, registered as a root.
156 result="t-result-$$"
157 guix build -r "$result" \
158 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
159 test -x "$result/bin/guile"
160
161 # Should fail, because $result already exists.
162 if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
163 then false; else true; fi
164
165 rm -f "$result"
166
167 # Cross building.
168 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
169
170 # Replacements.
171 drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
172 drv2=`guix build guix -d`
173 test "$drv1" != "$drv2"
174
175 drv1=`guix build guile -d`
176 drv2=`guix build guile --with-input=gimp=ruby -d`
177 test "$drv1" = "$drv2"
178
179 if guix build guile --with-input=libunistring=something-really-silly
180 then false; else true; fi
181
182 # Deprecated/superseded packages.
183 test "`guix build superseded -d`" = "`guix build bar -d`"
184
185 # Parsing package names and versions.
186 guix build -n time # PASS
187 guix build -n time@1.9 # PASS, version found
188 if guix build -n time@3.2; # FAIL, version not found
189 then false; else true; fi
190 if guix build -n something-that-will-never-exist; # FAIL
191 then false; else true; fi
192
193 # Invoking a monadic procedure.
194 guix build -e "(begin
195 (use-modules (guix gexp))
196 (lambda ()
197 (gexp->derivation \"test\"
198 (gexp (mkdir (ungexp output))))))" \
199 --dry-run
200
201 # Running a gexp.
202 guix build -e '#~(mkdir #$output)' -d
203 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
204
205 # Building from a package file.
206 cat > "$module_dir/package.scm"<<EOF
207 (use-modules (gnu))
208 (use-package-modules bootstrap)
209
210 %bootstrap-guile
211 EOF
212 guix build --file="$module_dir/package.scm"
213
214 # Building from a monadic procedure file.
215 cat > "$module_dir/proc.scm"<<EOF
216 (use-modules (guix gexp))
217 (lambda ()
218 (gexp->derivation "test"
219 (gexp (mkdir (ungexp output)))))
220 EOF
221 guix build --file="$module_dir/proc.scm" --dry-run
222
223 # Building from a gexp file.
224 cat > "$module_dir/gexp.scm"<<EOF
225 (use-modules (guix gexp))
226
227 (gexp (mkdir (ungexp output)))
228 EOF
229 guix build --file="$module_dir/gexp.scm" -d
230 guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
231
232 # Using 'GUIX_BUILD_OPTIONS'.
233 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
234 export GUIX_BUILD_OPTIONS
235
236 guix build emacs
237
238 GUIX_BUILD_OPTIONS="--something-completely-crazy"
239 if guix build emacs;
240 then false; else true; fi