gnu: cool-retro-term: Upgrade to 1.1.1.
[jackhill/guix/guix.git] / tests / guix-environment.sh
CommitLineData
cad25264 1# GNU Guix --- Functional package management for GNU
a93c1606 2# Copyright © 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
cad25264
LC
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 'guix environment'.
21#
22
23set -e
24
25guix environment --version
26
27tmpdir="t-guix-environment-$$"
f943c317
LC
28gcroot="t-guix-environment-gc-root-$$"
29trap 'rm -r "$tmpdir"; rm -f "$gcroot"' EXIT
cad25264
LC
30
31mkdir "$tmpdir"
32
b485f756
LC
33# 'guix environment' launches /bin/sh if 'SHELL' is unset, so export 'SHELL'
34# since we know it's valid (build environments lack /bin/sh.)
35export SHELL
36
cad25264 37# Check the environment variables for the bootstrap Guile.
779aa003
DT
38guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
39 --search-paths > "$tmpdir/a"
40guix environment --bootstrap --ad-hoc guile-bootstrap:out --pure \
41 --search-paths > "$tmpdir/b"
cad25264
LC
42
43# $PATH must appear in the search paths, and nothing else.
779aa003 44grep -E '^export PATH=.*profile/bin' "$tmpdir/a"
cad25264
LC
45test "`wc -l < "$tmpdir/a"`" = 1
46
779aa003
DT
47# Guile must be on $PATH.
48test -x `sed -r 's/^export PATH="(.*)"/\1/' "$tmpdir/a"`/guile
49
417c39f1
LC
50cmp "$tmpdir/a" "$tmpdir/b"
51
4931dfcd 52# Make sure the exit value is preserved.
779aa003
DT
53if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
54 -- guile -c '(exit 42)'
1de2fe95
DT
55then
56 false
57else
58 test $? = 42
59fi
60
20185522
LC
61# Make sure 'GUIX_ENVIRONMENT' points to the profile.
62guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
63 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
64
267379f8
DT
65# Make sure 'GUIX_ENVIRONMENT' points to the profile when building from a
66# manifest.
67echo "(use-modules (guix profiles) (gnu packages bootstrap))
68
69(packages->manifest (list %bootstrap-guile))
70" > $tmpdir/manifest.scm
71guix environment --bootstrap --manifest=$tmpdir/manifest.scm --pure \
72 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
73
f943c317
LC
74# Make sure '-r' works as expected.
75rm -f "$gcroot"
76expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
77 -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT'`"
78guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
79 -- guile -c 1
80test `readlink "$gcroot"` = "$expected"
81
82# Make sure '-r' is idempotent.
83guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
84 -- guile -c 1
85test `readlink "$gcroot"` = "$expected"
840f38ba 86rm "$gcroot"
f943c317 87
840f38ba
LC
88# Same with an absolute file name.
89guix environment --bootstrap -r "$PWD/$gcroot" --ad-hoc guile-bootstrap \
90 -- guile -c 1
91test `readlink "$gcroot"` = "$expected"
f943c317 92
40d71e44
LC
93case "`uname -m`" in
94 x86_64)
95 # On x86_64, we should be able to create a 32-bit environment.
96 guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
97 -- guile -c '(exit (string-prefix? "x86_64" %host-type))'
98 guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
99 -s i686-linux \
100 -- guile -c '(exit (string-prefix? "i686" %host-type))'
101 ;;
102 *)
103 echo "nothing to do" >&2
104 ;;
105esac
106
107
1de2fe95 108# Same as above, but with deprecated -E flag.
779aa003
DT
109if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
110 -E "guile -c '(exit 42)'"
4931dfcd
LC
111then
112 false
113else
114 test $? = 42
115fi
116
afd06f60
LC
117# Make sure we can build the environment of 'guix'. There may be collisions
118# in its profile (e.g., for 'gzip'), but we have to accept them.
119guix environment guix --bootstrap -n
120
a93c1606
LC
121# Try program transformation options.
122mkdir "$tmpdir/emacs-36.8"
123drv="`guix environment --ad-hoc emacs -n 2>&1 | grep 'emacs.*\.drv'`"
124transformed_drv="`guix environment --ad-hoc emacs --with-source="$tmpdir/emacs-36.8" -n 2>&1 | grep 'emacs.*\.drv'`"
125test -n "$drv"
126test "$drv" != "$transformed_drv"
127case "$transformed_drv" in
128 *-emacs-36.8.drv) true;;
129 *) false;;
130esac
131rmdir "$tmpdir/emacs-36.8"
132
cad25264
LC
133if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
134then
135 # Compute the build environment for the initial GNU Make.
779aa003
DT
136 guix environment --bootstrap --no-substitutes --search-paths --pure \
137 -e '(@@ (gnu packages commencement) gnu-make-boot0)' > "$tmpdir/a"
138
139 # Make sure bootstrap binaries are in the profile.
140 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
cad25264
LC
141
142 # Make sure the bootstrap binaries are all listed where they belong.
779aa003
DT
143 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
144 grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
145 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
146 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
147 do
148 guix gc --references "$profile" | grep "$dep"
149 done
cad25264
LC
150
151 # 'make-boot0' itself must not be listed.
779aa003
DT
152 if guix gc --references "$profile" | grep make-boot0
153 then false; else true; fi
cad25264
LC
154
155 # Make sure that the shell spawned with '--exec' sees the same environment
156 # as returned by '--search-paths'.
779aa003
DT
157 guix environment --bootstrap --no-substitutes --pure \
158 -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
1de2fe95 159 -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
cad25264
LC
160 ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
161 cmp "$tmpdir/b" "$tmpdir/c"
6b6298ae
LC
162
163 rm "$tmpdir"/*
164
165 # Compute the build environment for the initial GNU Findutils.
779aa003
DT
166 guix environment --bootstrap --no-substitutes --search-paths --pure \
167 -e '(@@ (gnu packages commencement) findutils-boot0)' > "$tmpdir/a"
168 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
6b6298ae
LC
169
170 # Make sure the bootstrap binaries are all listed where they belong.
779aa003
DT
171 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
172 grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
173 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
174 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
175 make-boot0
176 do
177 guix gc --references "$profile" | grep "$dep"
178 done
6b6298ae
LC
179
180 # The following test assumes 'make-boot0' has a "debug" output.
181 make_boot0_debug="`guix build -e '(@@ (gnu packages commencement) gnu-make-boot0)' | grep -e -debug`"
182 test "x$make_boot0_debug" != "x"
183
184 # Make sure the "debug" output is not listed.
779aa003
DT
185 if guix gc --references "$profile" | grep "$make_boot0_debug"
186 then false; else true; fi
cc90fbbf
DT
187
188 # Compute the build environment for the initial GNU Make, but add in the
189 # bootstrap Guile as an ad-hoc addition.
779aa003
DT
190 guix environment --bootstrap --no-substitutes --search-paths --pure \
191 -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
192 --ad-hoc guile-bootstrap > "$tmpdir/a"
193 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
cc90fbbf
DT
194
195 # Make sure the bootstrap binaries are all listed where they belong.
779aa003
DT
196 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
197 grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
198 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
199 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
200 guile-bootstrap
201 do
202 guix gc --references "$profile" | grep "$dep"
203 done
204
205 # Make sure a package list with plain package objects and package+output
206 # tuples can be used with -e.
c9c282ce
DT
207 expr_list_test_code="
208(list (@@ (gnu packages commencement) gnu-make-boot0)
779aa003 209 (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
c9c282ce 210
779aa003
DT
211 guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
212 --pure -e "$expr_list_test_code" > "$tmpdir/a"
213 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
c9c282ce 214
779aa003
DT
215 for dep in make-boot0 guile-bootstrap
216 do
217 guix gc --references "$profile" | grep "$dep"
218 done
cad25264 219fi