Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / tests / guix-environment.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2015 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 trap 'rm -r "$tmpdir"' EXIT
29
30 mkdir "$tmpdir"
31
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.)
34 export SHELL
35
36 # Check the environment variables for the bootstrap Guile.
37 guix environment --ad-hoc guile-bootstrap --pure --search-paths > "$tmpdir/a"
38 guix environment --ad-hoc guile-bootstrap:out --pure --search-paths > "$tmpdir/b"
39
40 # $PATH must appear in the search paths, and nothing else.
41 grep -E '^export PATH=.*guile-bootstrap-[0-9.]+/bin' "$tmpdir/a"
42 test "`wc -l < "$tmpdir/a"`" = 1
43
44 cmp "$tmpdir/a" "$tmpdir/b"
45
46 # Make sure the exit value is preserved.
47 if guix environment --ad-hoc guile-bootstrap --pure -- guile -c '(exit 42)'
48 then
49 false
50 else
51 test $? = 42
52 fi
53
54 # Same as above, but with deprecated -E flag.
55 if guix environment --ad-hoc guile-bootstrap --pure -E "guile -c '(exit 42)'"
56 then
57 false
58 else
59 test $? = 42
60 fi
61
62 if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
63 then
64 # Compute the build environment for the initial GNU Make.
65 guix environment -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
66 --no-substitutes --search-paths --pure > "$tmpdir/a"
67
68 # Make sure the bootstrap binaries are all listed where they belong.
69 grep -E '^export PATH=.*-bootstrap-binaries-0/bin' "$tmpdir/a"
70 grep -E '^export CPATH=.*-gcc-bootstrap-0/include' "$tmpdir/a"
71 grep -E '^export CPATH=.*-glibc-bootstrap-0/include' "$tmpdir/a"
72 grep -E '^export LIBRARY_PATH=.*-glibc-bootstrap-0/lib' "$tmpdir/a"
73
74 # 'make-boot0' itself must not be listed.
75 if grep "make-boot0" "$tmpdir/a"; then false; else true; fi
76
77 # Make sure that the shell spawned with '--exec' sees the same environment
78 # as returned by '--search-paths'.
79 guix environment -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
80 --no-substitutes --pure \
81 -- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
82 ( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
83 cmp "$tmpdir/b" "$tmpdir/c"
84
85 rm "$tmpdir"/*
86
87 # Compute the build environment for the initial GNU Findutils.
88 guix environment -e '(@@ (gnu packages commencement) findutils-boot0)' \
89 --no-substitutes --search-paths --pure > "$tmpdir/a"
90
91 # Make sure the bootstrap binaries are all listed where they belong.
92 grep -E '^export PATH=.*-bootstrap-binaries-0/bin' "$tmpdir/a"
93 grep -E '^export PATH=.*-make-boot0-[0-9.]+/bin' "$tmpdir/a"
94 grep -E '^export CPATH=.*-gcc-bootstrap-0/include' "$tmpdir/a"
95 grep -E '^export CPATH=.*-glibc-bootstrap-0/include' "$tmpdir/a"
96 grep -E '^export LIBRARY_PATH=.*-glibc-bootstrap-0/lib' "$tmpdir/a"
97
98 # The following test assumes 'make-boot0' has a "debug" output.
99 make_boot0_debug="`guix build -e '(@@ (gnu packages commencement) gnu-make-boot0)' | grep -e -debug`"
100 test "x$make_boot0_debug" != "x"
101
102 # Make sure the "debug" output is not listed.
103 if grep -E "$make_boot0_debug" "$tmpdir/a"; then false; else true; fi
104
105 # Compute the build environment for the initial GNU Make, but add in the
106 # bootstrap Guile as an ad-hoc addition.
107 guix environment -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
108 --ad-hoc guile-bootstrap --no-substitutes --search-paths \
109 --pure > "$tmpdir/a"
110
111 # Make sure the bootstrap binaries are all listed where they belong.
112 cat $tmpdir/a
113 grep -E '^export PATH=.*-bootstrap-binaries-0/bin' "$tmpdir/a"
114 grep -E '^export PATH=.*-guile-bootstrap-2.0/bin' "$tmpdir/a"
115 grep -E '^export CPATH=.*-gcc-bootstrap-0/include' "$tmpdir/a"
116 grep -E '^export CPATH=.*-glibc-bootstrap-0/include' "$tmpdir/a"
117 grep -E '^export LIBRARY_PATH=.*-glibc-bootstrap-0/lib' "$tmpdir/a"
118
119 # Make sure a package list can be used with -e.
120 expr_list_test_code="
121 (list (@@ (gnu packages commencement) gnu-make-boot0)
122 (@ (gnu packages bootstrap) %bootstrap-guile))"
123
124 guix environment --ad-hoc --no-substitutes --search-paths --pure \
125 -e "$expr_list_test_code" > "$tmpdir/a"
126
127 grep -E '^export PATH=.*-make-boot0-4.1/bin' "$tmpdir/a"
128 grep -E '^export PATH=.*-guile-bootstrap-2.0/bin' "$tmpdir/a"
129 fi