gtk and wayland update
[jackhill/guix/guix.git] / tests / guix-package-net.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012-2015, 2017, 2019, 2022 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
4 # Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
5 #
6 # This file is part of GNU Guix.
7 #
8 # GNU Guix is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GNU Guix is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 #
22 # Test the `guix package' command-line utility. This test requires network
23 # access and is skipped when that is lacking.
24 #
25
26 guix package --version
27
28 readlink_base ()
29 {
30 basename `readlink "$1"`
31 }
32
33 # Return true if a typical shebang in the store would exceed Linux's default
34 # static limit.
35 shebang_too_long ()
36 {
37 test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \
38 -ge 128
39 }
40
41 if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \
42 || shebang_too_long
43 then
44 # Skipping.
45 exit 77
46 fi
47
48
49 profile="t-profile-$$"
50 profile_alt="t-profile-alt-$$"
51 rm -f "$profile"
52
53 module_dir="t-guix-package-net-$$"
54 mkdir "$module_dir"
55
56 trap 'rm -f "$profile" "$profile_alt" "$profile.lock" "$profile_alt.lock" "$profile-"[0-9]* "$profile_alt-"[0-9]* ; rm -r "$module_dir" t-home-'"$$" EXIT
57
58
59 guix package --bootstrap -p "$profile" -i guile-bootstrap
60 test -L "$profile" && test -L "$profile-1-link"
61 ! test -f "$profile-2-link"
62 test -f "$profile/bin/guile"
63
64 boot_make="(@ (guix tests) gnu-make-for-tests)"
65 boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
66 guix package --bootstrap -p "$profile" -i "$boot_make_drv"
67 test -L "$profile-2-link"
68 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
69
70 # Check whether `--list-installed' works.
71 # XXX: Change the tests when `--install' properly extracts the package
72 # name and version string.
73 installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
74 case "x$installed" in
75 "guile-bootstrap make-boot0")
76 true;;
77 "make-boot0 guile-bootstrap")
78 true;;
79 "*")
80 false;;
81 esac
82
83 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
84
85 guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
86 installed="`guix package -p "$profile" -p "$profile_alt" -I | cut -f1 | xargs echo | sort`"
87 case "x$installed" in
88 "gcc-bootstrap guile-bootstrap make-boot0")
89 true;;
90 "*")
91 false;;
92 esac
93 test "`guix package -p "$profile_alt" -p "$profile" -I | wc -l`" = "3"
94 rm "$profile_alt"
95
96 # List generations.
97 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
98 = " guile-bootstrap"
99
100 # Exit with 1 when a generation does not exist.
101 ! guix package -p "$profile" --list-generations=42
102 ! guix package -p "$profile" --switch-generation=99
103
104 # Remove a package.
105 guix package --bootstrap -p "$profile" -r "guile-bootstrap"
106 test -L "$profile-3-link"
107 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
108
109 # Roll back.
110 guix package --roll-back -p "$profile"
111 test "`readlink_base "$profile"`" = "$profile-2-link"
112 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
113 guix package --roll-back -p "$profile"
114 test "`readlink_base "$profile"`" = "$profile-1-link"
115 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
116
117 # Switch to the rolled generation and switch back.
118 guix package -p "$profile" --switch-generation=2
119 test "`readlink_base "$profile"`" = "$profile-2-link"
120 guix package -p "$profile" --switch-generation=-1
121 test "`readlink_base "$profile"`" = "$profile-1-link"
122
123 # Move to the empty profile.
124 for i in `seq 1 3`
125 do
126 guix package --bootstrap --roll-back -p "$profile"
127 ! test -f "$profile/bin"
128 ! test -f "$profile/lib"
129 test "`readlink_base "$profile"`" = "$profile-0-link"
130 done
131
132 # Test that '--list-generations' does not output the zeroth generation.
133 test -z "`guix package -p "$profile" -l 0`"
134
135 # Reinstall after roll-back to the empty profile.
136 guix package --bootstrap -p "$profile" -e "$boot_make"
137 test "`readlink_base "$profile"`" = "$profile-1-link"
138 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
139
140 # Check that the first generation is the current one.
141 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
142
143 # Roll-back to generation 0, and install---all at once.
144 guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
145 test "`readlink_base "$profile"`" = "$profile-1-link"
146 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
147
148 # Install Make.
149 guix package --bootstrap -p "$profile" -e "$boot_make"
150 test "`readlink_base "$profile"`" = "$profile-2-link"
151 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
152 grep "`guix build -e "$boot_make"`" "$profile/manifest"
153
154 # Make a "hole" in the list of generations, and make sure we can
155 # roll back and switch "over" it.
156 rm "$profile-1-link"
157 guix package --bootstrap -p "$profile" --roll-back
158 test "`readlink_base "$profile"`" = "$profile-0-link"
159 guix package -p "$profile" --switch-generation=+1
160 test "`readlink_base "$profile"`" = "$profile-2-link"
161
162 # Make sure LIBRARY_PATH gets listed by `--search-paths'.
163 guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
164 guix package -p "$profile" --search-paths | grep LIBRARY_PATH
165
166 # Roll back so we can delete #3 below.
167 guix package -p "$profile" --switch-generation=2
168
169 # Delete the third generation and check that it was actually deleted.
170 guix package -p "$profile" --delete-generations=3
171 test -z "`guix package -p "$profile" -l 3`"
172
173 # Search path of combined profiles. 'LIBRARY_PATH' should show up only in the
174 # combination, not in the individual profiles.
175 rm "$profile"
176 guix package --bootstrap -p "$profile" -i guile-bootstrap
177 guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
178 ! guix package -p "$profile" --search-paths | grep LIBRARY_PATH
179 guix package -p "$profile" -p "$profile_alt" --search-paths \
180 | grep "LIBRARY_PATH.*$profile/lib.$profile_alt/lib"
181
182 # Simulate an upgrade and make sure the package order is preserved.
183 cat > "$module_dir/new.scm" <<EOF
184 (define-module (new)
185 #:use-module (guix)
186 #:use-module (gnu packages bootstrap))
187
188 (define-public new-guile
189 (package (inherit %bootstrap-guile)
190 (version (string-append "42." (getenv "V_MINOR")))))
191 (define-public new-gcc
192 (package (inherit %bootstrap-gcc)
193 (version (string-append "77." (getenv "V_MINOR")))))
194 EOF
195
196 guix package --bootstrap -p "$profile" -i gcc-bootstrap
197 installed="`guix package -p "$profile" -I | cut -f1`"
198
199 # Dry-run upgrade. Make sure no new generation is created when things are
200 # already in store and '-n' is used: <https://issues.guix.gnu.org/53267>.
201 V_MINOR=0
202 export V_MINOR
203 profile_before="$(readlink "$profile")"
204 guix package -p "$profile" --bootstrap -L "$module_dir" -u # build the profile
205 guix package -p "$profile" --roll-back
206 guix package -p "$profile" --bootstrap -L "$module_dir" -u . -n # check '-n'
207 test "$(readlink "$profile")" = "$profile_before"
208
209 for i in 1 2
210 do
211 V_MINOR="$i"
212 export V_MINOR
213
214 guix package -p "$profile" --bootstrap -L "$module_dir" -u .
215 post_upgrade="`guix package -p "$profile" -I | cut -f1`"
216 test "$post_upgrade" = "$installed"
217 done
218
219 #
220 # Try with the default profile.
221 #
222
223 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
224 export XDG_CACHE_HOME
225 HOME="$PWD/t-home-$$"
226 export HOME
227
228 mkdir -p "$HOME"
229
230 # Get the canonical directory name so that 'guix package' recognizes it.
231 HOME="`cd $HOME; pwd -P`"
232
233 guix package --bootstrap -e "$boot_make"
234 test -f "$HOME/.guix-profile/bin/make"
235
236 guix package --bootstrap --roll-back
237 ! test -f "$HOME/.guix-profile/bin/make"