projects/guix·blob python-team · refs

263 lines · 9.3 KiB

1# GNU Guix --- Functional package management for GNU
2# Copyright © 2015, 2016, 2017, 2018, 2019, 2021 Ludovic Courtès <[email protected]>
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-$$"
28gcroot="t-guix-environment-gc-root-$$"
29trap 'rm -r "$tmpdir"; rm -f "$gcroot"' EXIT
30
31mkdir "$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.)
35export SHELL
36
37# Check the environment variables for the bootstrap Guile.
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"
42
43# $PATH must appear in the search paths, and nothing else.
44grep -E '^export PATH=.*profile/bin' "$tmpdir/a"
45test "`wc -l < "$tmpdir/a"`" = 1
46
47# Guile must be on $PATH.
48test -x `sed -r 's/^export PATH="(.*)"/\1/' "$tmpdir/a"`/guile
49
50cmp "$tmpdir/a" "$tmpdir/b"
51
52# Check '--preserve', as well as its -E VAR=VALUE special case.
53GUIX_TEST_ABC=1
54GUIX_TEST_DEF=2
55GUIX_TEST_XYZ=3
56GUIX_TEST_ZZZ=4
57export GUIX_TEST_ABC GUIX_TEST_DEF GUIX_TEST_XYZ
58guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
59 --preserve='^GUIX_TEST_A' --preserve='^GUIX_TEST_D' \
60 --preserve='^GUIX_TEST_Z' -E 'GUIX_TEST_ZZZ=overridden' \
61 -- "$SHELL" -c set > "$tmpdir/a"
62grep '^PATH=' "$tmpdir/a"
63grep '^GUIX_TEST_ABC=1' "$tmpdir/a"
64grep '^GUIX_TEST_DEF=2' "$tmpdir/a"
65grep '^GUIX_TEST_XYZ=3' "$tmpdir/a" && false
66grep '^GUIX_TEST_ZZZ=overridden' "$tmpdir/a"
67
68# Make sure the exit value is preserved.
69if guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
70 -- guile -c '(exit 42)'
71then
72 false
73else
74 test $? = 42
75fi
76
77# Make sure 'GUIX_ENVIRONMENT' points to the profile.
78guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
79 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
80
81# Make sure 'GUIX_ENVIRONMENT' points to the profile when building from a
82# manifest.
83echo "(use-modules (guix profiles) (gnu packages bootstrap))
84
85(packages->manifest (list %bootstrap-guile))
86" > $tmpdir/manifest.scm
87guix environment --bootstrap --manifest=$tmpdir/manifest.scm --pure \
88 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
89
90# Make sure '--manifest' can be specified multiple times.
91cat > "$tmpdir/manifest2.scm" <<EOF
92(use-modules (guix) (guix profiles)
93 (guix build-system trivial)
94 (gnu packages bootstrap))
95
96(packages->manifest
97 (list (package
98 (inherit %bootstrap-guile)
99 (name "eliug")
100 (build-system trivial-build-system)
101 (arguments
102 (quasiquote
103 (#:guile ,%bootstrap-guile
104 #:builder
105 (begin
106 (mkdir %output)
107 (mkdir (string-append %output "/eliug")))))))))
108EOF
109guix environment --bootstrap -m "$tmpdir/manifest.scm" \
110 -m "$tmpdir/manifest2.scm" --pure \
111 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile" && test -d "$GUIX_ENVIRONMENT/eliug"'
112
113# Make sure '-r' works as expected.
114rm -f "$gcroot"
115expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
116 -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT'`"
117guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
118 -- guile -c 1
119test `readlink "$gcroot"` = "$expected"
120
121# Make sure '-r' is idempotent.
122guix environment --bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
123 -- guile -c 1
124test `readlink "$gcroot"` = "$expected"
125
126# Make sure '-p' works as expected.
127test $(guix environment -p "$gcroot" -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT') = "$expected"
128paths1="$(guix environment -p "$gcroot" --search-paths)"
129paths2="$(guix environment --bootstrap --ad-hoc guile-bootstrap --search-paths)"
130test "$paths1" = "$paths2"
131
132rm "$gcroot"
133
134# Try '-r' with a relative file name.
135(cd "$tmpdir"; mkdir "gc-root";
136 guix environment --bootstrap -r "gc-root/r" --ad-hoc guile-bootstrap \
137 -- guile -c 1;
138 rm "gc-root/r"; rmdir "gc-root")
139
140# Same with an absolute file name.
141guix environment --bootstrap -r "$PWD/$gcroot" --ad-hoc guile-bootstrap \
142 -- guile -c 1
143test `readlink "$gcroot"` = "$expected"
144
145case "`uname -m`" in
146 x86_64)
147 # On x86_64, we should be able to create a 32-bit environment.
148 guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
149 -- guile -c '(exit (string-prefix? "x86_64" %host-type))'
150 guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
151 -s i686-linux \
152 -- guile -c '(exit (string-prefix? "i686" %host-type))'
153 ;;
154 *)
155 echo "nothing to do" >&2
156 ;;
157esac
158
159# Make sure we can build the environment of 'guix'. There may be collisions
160# in its profile (e.g., for 'gzip'), but we have to accept them.
161guix environment guix --bootstrap -n
162
163# Try program transformation options.
164mkdir "$tmpdir/emacs-36.8"
165drv="`guix environment --ad-hoc emacs -n 2>&1 | grep 'emacs.*\.drv'`"
166transformed_drv="`guix environment --ad-hoc emacs --with-source="$tmpdir/emacs-36.8" -n 2>&1 | grep 'emacs.*\.drv'`"
167test -n "$drv"
168test "$drv" != "$transformed_drv"
169case "$transformed_drv" in
170 *-emacs-36.8.drv) true;;
171 *) false;;
172esac
173rmdir "$tmpdir/emacs-36.8"
174
175# Transformation options without '--ad-hoc'.
176drv="`guix environment -n emacs-geiser 2>&1 | grep '\.drv$'`"
177transformed_drv="`guix environment -n emacs-geiser \
178 --with-input=emacs-minimal=vim 2>&1 | grep '\.drv$'`"
179test "$drv" != "$transformed_drv"
180case "$drv" in
181 *-emacs-minimal*.drv*) true;;
182 *) false;;
183esac
184case "$transformed_drv" in
185 *-emacs-minimal*.drv*) false;;
186 *) true;;
187esac
188case "$transformed_drv" in
189 *-vim*.drv*) true;;
190 *) false;;
191esac
192
193
194if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
195then
196 # Compute the build environment for the initial GNU Make.
197 guix environment --bootstrap --no-substitutes --search-paths --pure \
198 -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
199
200 # Make sure bootstrap binaries are in the profile.
201 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
202
203 # Make sure the bootstrap binaries are all listed where they belong.
204 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
205 grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
206 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
207 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
208 do
209 guix gc --references "$profile" | grep "$dep"
210 done
211
212 # 'make-boot0' itself must not be listed.
213 guix gc --references "$profile" | grep make-boot0 && false
214
215 # Make sure that the shell spawned with '--exec' sees the same environment
216 # as returned by '--search-paths'.
217 guix environment --bootstrap --no-substitutes --pure \
218 -e '(@ (guix tests) gnu-make-for-tests)' \
219 -- /bin/sh -c 'echo $PATH $C_INCLUDE_PATH $LIBRARY_PATH' > "$tmpdir/b"
220 ( . "$tmpdir/a" ; echo $PATH $C_INCLUDE_PATH $LIBRARY_PATH ) > "$tmpdir/c"
221 cmp "$tmpdir/b" "$tmpdir/c"
222
223 rm "$tmpdir"/*
224
225 # The following test assumes 'make-boot0' has a "debug" output.
226 make_boot0_debug="`guix build -e '(@ (guix tests) gnu-make-for-tests)' | grep -e -debug`"
227 test "x$make_boot0_debug" != "x"
228
229 # Make sure the "debug" output is not listed.
230 guix gc --references "$profile" | grep "$make_boot0_debug" && false
231
232 # Compute the build environment for the initial GNU Make, but add in the
233 # bootstrap Guile as an ad-hoc addition.
234 guix environment --bootstrap --no-substitutes --search-paths --pure \
235 -e '(@ (guix tests) gnu-make-for-tests)' \
236 --ad-hoc guile-bootstrap > "$tmpdir/a"
237 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
238
239 # Make sure the bootstrap binaries are all listed where they belong.
240 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
241 grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
242 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
243 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
244 guile-bootstrap
245 do
246 guix gc --references "$profile" | grep "$dep"
247 done
248
249 # Make sure a package list with plain package objects and package+output
250 # tuples can be used with -e.
251 expr_list_test_code="
252(list (@ (guix tests) gnu-make-for-tests)
253 (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
254
255 guix environment --bootstrap --ad-hoc --no-substitutes --search-paths \
256 --pure -e "$expr_list_test_code" > "$tmpdir/a"
257 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
258
259 for dep in make-test-boot0 guile-bootstrap
260 do
261 guix gc --references "$profile" | grep "$dep"
262 done
263fi