gnu: Add alsa-plugins.
[jackhill/guix/guix.git] / tests / guix-environment.sh
CommitLineData
cad25264 1# GNU Guix --- Functional package management for GNU
779aa003 2# Copyright © 2015, 2016 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-$$"
28trap 'rm -r "$tmpdir"' EXIT
29
30mkdir "$tmpdir"
31
b485f756
LC
32# 'guix environment' launches /bin/sh if 'SHELL' is unset, so export 'SHELL'
33# since we know it's valid (build environments lack /bin/sh.)
34export SHELL
35
cad25264 36# Check the environment variables for the bootstrap Guile.
779aa003
DT
37guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
38 --search-paths > "$tmpdir/a"
39guix environment --bootstrap --ad-hoc guile-bootstrap:out --pure \
40 --search-paths > "$tmpdir/b"
cad25264
LC
41
42# $PATH must appear in the search paths, and nothing else.
779aa003 43grep -E '^export PATH=.*profile/bin' "$tmpdir/a"
cad25264
LC
44test "`wc -l < "$tmpdir/a"`" = 1
45
779aa003
DT
46# Guile must be on $PATH.
47test -x `sed -r 's/^export PATH="(.*)"/\1/' "$tmpdir/a"`/guile
48
417c39f1
LC
49cmp "$tmpdir/a" "$tmpdir/b"
50
4931dfcd 51# Make sure the exit value is preserved.
779aa003
DT
52if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
53 -- guile -c '(exit 42)'
1de2fe95
DT
54then
55 false
56else
57 test $? = 42
58fi
59
20185522
LC
60# Make sure 'GUIX_ENVIRONMENT' points to the profile.
61guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
62 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
63
40d71e44
LC
64case "`uname -m`" in
65 x86_64)
66 # On x86_64, we should be able to create a 32-bit environment.
67 guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
68 -- guile -c '(exit (string-prefix? "x86_64" %host-type))'
69 guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
70 -s i686-linux \
71 -- guile -c '(exit (string-prefix? "i686" %host-type))'
72 ;;
73 *)
74 echo "nothing to do" >&2
75 ;;
76esac
77
78
1de2fe95 79# Same as above, but with deprecated -E flag.
779aa003
DT
80if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
81 -E "guile -c '(exit 42)'"
4931dfcd
LC
82then
83 false
84else
85 test $? = 42
86fi
87
cad25264
LC
88if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
89then
90 # Compute the build environment for the initial GNU Make.
779aa003
DT
91 guix environment --bootstrap --no-substitutes --search-paths --pure \
92 -e '(@@ (gnu packages commencement) gnu-make-boot0)' > "$tmpdir/a"
93
94 # Make sure bootstrap binaries are in the profile.
95 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
cad25264
LC
96
97 # Make sure the bootstrap binaries are all listed where they belong.
779aa003
DT
98 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
99 grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
100 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
101 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
102 do
103 guix gc --references "$profile" | grep "$dep"
104 done
cad25264
LC
105
106 # 'make-boot0' itself must not be listed.
779aa003
DT
107 if guix gc --references "$profile" | grep make-boot0
108 then false; else true; fi
cad25264
LC
109
110 # Make sure that the shell spawned with '--exec' sees the same environment
111 # as returned by '--search-paths'.
779aa003
DT
112 guix environment --bootstrap --no-substitutes --pure \
113 -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
1de2fe95 114 -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
cad25264
LC
115 ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
116 cmp "$tmpdir/b" "$tmpdir/c"
6b6298ae
LC
117
118 rm "$tmpdir"/*
119
120 # Compute the build environment for the initial GNU Findutils.
779aa003
DT
121 guix environment --bootstrap --no-substitutes --search-paths --pure \
122 -e '(@@ (gnu packages commencement) findutils-boot0)' > "$tmpdir/a"
123 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
6b6298ae
LC
124
125 # Make sure the bootstrap binaries are all listed where they belong.
779aa003
DT
126 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
127 grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
128 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
129 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
130 make-boot0
131 do
132 guix gc --references "$profile" | grep "$dep"
133 done
6b6298ae
LC
134
135 # The following test assumes 'make-boot0' has a "debug" output.
136 make_boot0_debug="`guix build -e '(@@ (gnu packages commencement) gnu-make-boot0)' | grep -e -debug`"
137 test "x$make_boot0_debug" != "x"
138
139 # Make sure the "debug" output is not listed.
779aa003
DT
140 if guix gc --references "$profile" | grep "$make_boot0_debug"
141 then false; else true; fi
cc90fbbf
DT
142
143 # Compute the build environment for the initial GNU Make, but add in the
144 # bootstrap Guile as an ad-hoc addition.
779aa003
DT
145 guix environment --bootstrap --no-substitutes --search-paths --pure \
146 -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
147 --ad-hoc guile-bootstrap > "$tmpdir/a"
148 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
cc90fbbf
DT
149
150 # Make sure the bootstrap binaries are all listed where they belong.
779aa003
DT
151 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
152 grep -E "^export CPATH=\"$profile/include\"" "$tmpdir/a"
153 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
154 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
155 guile-bootstrap
156 do
157 guix gc --references "$profile" | grep "$dep"
158 done
159
160 # Make sure a package list with plain package objects and package+output
161 # tuples can be used with -e.
c9c282ce
DT
162 expr_list_test_code="
163(list (@@ (gnu packages commencement) gnu-make-boot0)
779aa003 164 (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
c9c282ce 165
779aa003
DT
166 guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
167 --pure -e "$expr_list_test_code" > "$tmpdir/a"
168 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
c9c282ce 169
779aa003
DT
170 for dep in make-boot0 guile-bootstrap
171 do
172 guix gc --references "$profile" | grep "$dep"
173 done
cad25264 174fi