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