packages: Support the deprecated "NAME-VERSION" syntax.
[jackhill/guix/guix.git] / tests / guix-build.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2016 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 # Should fail because this is a source-less package.
30 if guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
31 then false; else true; fi
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 # Check --sources option with its arguments
40 module_dir="t-guix-build-$$"
41 mkdir "$module_dir"
42 trap "rm -rf $module_dir" EXIT
43
44 cat > "$module_dir/foo.scm"<<EOF
45 (define-module (foo)
46 #:use-module (guix tests)
47 #:use-module (guix packages)
48 #:use-module (guix download)
49 #:use-module (guix build-system trivial))
50
51 (define-public foo
52 (package
53 (name "foo")
54 (version "42")
55 (source (origin
56 (method url-fetch)
57 (uri "http://www.example.com/foo.tar.gz")
58 (sha256
59 (base32
60 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
61 (build-system trivial-build-system)
62 (inputs
63 (quasiquote (("bar" ,bar))))
64 (home-page "www.example.com")
65 (synopsis "Dummy package")
66 (description "foo is a dummy package for testing.")
67 (license #f)))
68
69 (define-public bar
70 (package
71 (name "bar")
72 (version "9001")
73 (source (origin
74 (method url-fetch)
75 (uri "http://www.example.com/bar.tar.gz")
76 (sha256
77 (base32
78 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
79 (build-system trivial-build-system)
80 (inputs
81 (quasiquote
82 (("data" ,(origin
83 (method url-fetch)
84 (uri "http://www.example.com/bar.dat")
85 (sha256
86 (base32
87 "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
88 (home-page "www.example.com")
89 (synopsis "Dummy package")
90 (description "bar is a dummy package for testing.")
91 (license #f)))
92
93 (define-public baz
94 (dummy-package "baz" (replacement foo)))
95
96 EOF
97
98 GUIX_PACKAGE_PATH="$module_dir"
99 export GUIX_PACKAGE_PATH
100
101 # foo.tar.gz
102 guix build -d -S foo
103 guix build -d -S foo | grep -e 'foo\.tar\.gz'
104
105 # 'baz' has a replacement so we should be getting the replacement's source.
106 (unset GUIX_BUILD_OPTIONS;
107 test "`guix build -d -S baz`" = "`guix build -d -S foo`")
108
109 guix build -d --sources=package foo
110 guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
111
112 # bar.tar.gz and bar.dat
113 guix build -d --sources bar
114 test `guix build -d --sources bar \
115 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
116 | wc -l` -eq 2
117
118 # bar.tar.gz and bar.dat
119 guix build -d --sources=all bar
120 test `guix build -d --sources bar \
121 | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
122 | wc -l` -eq 2
123
124 # Should include foo.tar.gz, bar.tar.gz, and bar.dat
125 guix build -d --sources=transitive foo
126 test `guix build -d --sources=transitive foo \
127 | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
128 | wc -l` -eq 3
129
130 # Should all return valid log files.
131 drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
132 out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
133 log="`guix build --log-file $drv`"
134 echo "$log" | grep log/.*guile.*drv
135 test -f "$log"
136 test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
137 = "$log"
138 test "`guix build --log-file guile-bootstrap`" = "$log"
139 test "`guix build --log-file $out`" = "$log"
140
141 # Should fail because the name/version combination could not be found.
142 if guix build hello-0.0.1 -n; then false; else true; fi
143
144 # Keep a symlink to the result, registered as a root.
145 result="t-result-$$"
146 guix build -r "$result" \
147 -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
148 test -x "$result/bin/guile"
149
150 # Should fail, because $result already exists.
151 if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
152 then false; else true; fi
153
154 rm -f "$result"
155
156 # Cross building.
157 guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
158
159 # Replacements.
160 drv1=`guix build guix --with-input=guile=guile-next -d`
161 drv2=`guix build guix -d`
162 test "$drv1" != "$drv2"
163
164 drv1=`guix build guile -d`
165 drv2=`guix build guile --with-input=gimp=ruby -d`
166 test "$drv1" = "$drv2"
167
168 if guix build guile --with-input=libunistring=something-really-silly
169 then false; else true; fi
170
171 # Parsing package names and versions.
172 guix build -n time # PASS
173 guix build -n time@1.7 # PASS, version found
174 guix build -n time-1.7 # PASS, deprecated version syntax
175 if guix build -n time@3.2; # FAIL, version not found
176 then false; else true; fi
177 if guix build -n something-that-will-never-exist; # FAIL
178 then false; else true; fi
179
180 # Invoking a monadic procedure.
181 guix build -e "(begin
182 (use-modules (guix gexp))
183 (lambda ()
184 (gexp->derivation \"test\"
185 (gexp (mkdir (ungexp output))))))" \
186 --dry-run
187
188 # Running a gexp.
189 guix build -e '#~(mkdir #$output)' -d
190 guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
191
192 # Building from a package file.
193 cat > "$module_dir/package.scm"<<EOF
194 (use-modules (gnu))
195 (use-package-modules bootstrap)
196
197 %bootstrap-guile
198 EOF
199 guix build --file="$module_dir/package.scm"
200
201 # Building from a monadic procedure file.
202 cat > "$module_dir/proc.scm"<<EOF
203 (use-modules (guix gexp))
204 (lambda ()
205 (gexp->derivation "test"
206 (gexp (mkdir (ungexp output)))))
207 EOF
208 guix build --file="$module_dir/proc.scm" --dry-run
209
210 # Building from a gexp file.
211 cat > "$module_dir/gexp.scm"<<EOF
212 (use-modules (guix gexp))
213
214 (gexp (mkdir (ungexp output)))
215 EOF
216 guix build --file="$module_dir/gexp.scm" -d
217 guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
218
219 # Using 'GUIX_BUILD_OPTIONS'.
220 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
221 export GUIX_BUILD_OPTIONS
222
223 guix build emacs
224
225 GUIX_BUILD_OPTIONS="--something-completely-crazy"
226 if guix build emacs;
227 then false; else true; fi