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