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