cookutils view modules/deps @ rev 1088

Better maintain Ruby packages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Aug 18 15:38:13 2018 +0300 (2018-08-18)
parents 20c2e51560fe
children 77291d41f21a
line source
1 #!/bin/sh
2 #
3 # deps - module of the SliTaz Cook
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
5 #
7 . /usr/lib/slitaz/libcook.sh
10 # Maintain databases
12 fl="$cache/tp.files.db" # combined list of all files
13 db_so="$cache/tp.so.db" # database with *.so files
14 db_a="$cache/tp.a.db" # database with *.a files
15 db_la="$cache/tp.la.db" # database with *.la files
16 db_pc="$cache/tp.pc.db" # database with *.pc files
18 fl_mirrorz='/var/lib/tazpkg/files.list.lzma' # mirror files list
19 fl_local='/home/slitaz/cache/files.list' # local files list
22 # check "local files list" doesn't contain files from missing/removed packages
24 action 'Updating %s...' "$(basename $fl_local)"
26 splitdb="$CACHE/split.db"
27 sed 's|:.*||' $fl_local \
28 | sort -u \
29 | while read pkg; do
30 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
31 if (index(" " $2 " ", pkg)) {print 1; exit}
32 }' $splitdb)
33 [ -n "$mainpkg" ] || sed -i "/^$pkg: /d" $fl_local
34 done
35 status
37 # recreate "combined list of all files" in the cases:
38 # * if absent
39 # * mirror files list has been updated
40 # * local files list has been updated
42 case $(hostname) in
43 # Do we need to use mirror files list?
44 # It's useful on casual development on local host, but useless on cooker server
45 # (and slows down list creation a lot).
46 tank)
47 [ ! -s $fl -o $fl_local -nt $fl ] && cp $fl_local $fl
48 ;;
49 *)
50 if [ ! -s $fl -o $fl_mirrorz -nt $fl -o $fl_local -nt $fl ]; then
51 action 'Updating %s...' "$(basename $fl)"
52 # unpack mirror files list
53 fl_mirror="$(mktemp)"
54 lzcat $fl_mirrorz | sed '/\.\(so.*\|a\|la\|pc\)$/!d' > $fl_mirror
56 # remove packages that exist in local list
57 cut -d: -f1 $fl_local | uniq | \
58 while read package; do
59 sed -i "/^$package: /d" $fl_mirror
60 done
62 # combine lists
63 cat $fl_mirror $fl_local > $fl
65 # clean
66 rm $fl_mirror
67 status
68 fi
69 ;;
70 esac
72 # recreate "database with *.so files" in the cases:
73 # * if absent
74 # * combined list of all files has been updated
76 if [ ! -s $db_so -o $fl -nt $db_so ]; then
77 action 'Updating %s...' "$(basename $db_so)"
78 fgrep '/lib/' $fl | fgrep '.so' | \
79 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
80 awk -F$'\t' '{if ($2 !~ "uclibc") print}' | \
81 sort > $db_so
82 status
83 fi
85 # recreate "database with *.a files" in the cases:
86 # * if absent
87 # * combined list of all files has been updated
89 if [ ! -s $db_a -o $fl -nt $db_a ]; then
90 action 'Updating %s...' "$(basename $db_a)"
91 fgrep '/usr/lib/lib' $fl | fgrep '.a' | \
92 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
93 sort > $db_a
94 status
95 fi
97 # recreate "database with *.la files" in the cases:
98 # * if absent
99 # * combined list of all files has been updated
101 if [ ! -s $db_la -o $fl -nt $db_la ]; then
102 action 'Updating %s...' "$(basename $db_la)"
103 fgrep '/usr/lib/' $fl | fgrep '.la' | \
104 sed 's|^\([^:]*\): \(.*\)$|\2\t\1|' | \
105 sort > $db_la
106 status
107 fi
109 # recreate "database with *.pc files" in the cases:
110 # * if absent
111 # * combined list of all files has been updated
113 if [ ! -s $db_pc -o $fl -nt $db_pc ]; then
114 action 'Updating %s...' "$(basename $db_pc)"
115 grep '\.pc$' $fl | \
116 sed -e 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' -e '/\tbuildroot$/d' | \
117 sort > $db_pc
118 status
119 fi
124 # Auxiliary function that deals with "not found" packages as well as with "repeatedly found" packages
126 outpkg() {
127 pkgs="$1"
128 case $pkgs in
129 *ld-linux.so*);;
130 *linux-gate.so*);;
131 *)
132 echo "$pkgs" | awk -vincl="$incl" '
133 # if both packages exist in list, return the first one only
134 function s(pkg1, pkg2) {
135 if (index(" "$0" ", " "pkg1" ") && index(" "$0" ", " " pkg2 " "))
136 $0 = pkg1;
137 }
138 {
139 s("wine", "wine-rt");
140 s("samba", "samba-pam");
141 s("mesa", "mesa-wayland");
142 s("mysql", "mariadb");
143 s("perl", "perl-thread");
144 s("xorg-server", "xorg-server-light");
145 s("cairo", "cairo-gl");
146 s("freetype", "freetype-infinality");
147 s("freetype", "freetype-without-harfbuzz");
148 s("harfbuzz", "harfbuzz-icu");
149 s("openbox", "openbox-imlib2");
150 s("gcc-lib-base", "gcc49-lib-base"); # also gcc54-lib-base and gcc61-lib-base
151 s("polkit", "polkit-pam");
152 s("libgudev", "eudev"); # also systemd
153 s("xz-dev", "liblzma-dev");
154 s("xorg-libxcb", "libxcb");
155 s("xorg-xcb-util-image", "xcb-util-image");
156 s("xorg-xcb-util-keysyms", "xcb-util-keysyms");
157 s("xorg-xcb-util-renderutil", "xcb-util-renderutil");
158 s("xorg-xcb-util-wm", "xcb-util-wm");
159 s("xorg-xcb-util", "xcb-util");
160 s("xorg-libxcb", "libxcb");
161 s("xorg-libxcb-dev", "libxcb-dev");
162 s("xorg-pixman", "pixman");
163 s("xorg-pixman-dev", "pixman-dev");
164 s("xorg-xcb-util-cursor", "xcb-util-cursor");
165 s("xorg-xcb-util-dev", "xcb-util-dev");
166 s("xorg-xcb-util-image-dev", "xcb-util-image-dev");
167 s("xorg-xcb-util-renderutil-dev", "xcb-util-renderutil-dev");
168 s("eudev-dev", "udev-dev");
169 s("util-linux-uuid", "ossp-uuid");
170 s("util-linux-uuid-dev", "ossp-uuid-dev");
171 s("polkit-pam-dev", "polkit-dev");
172 s("nspr", "palemoon"); # I doubt app may depend on Palemoon
173 s("nss", "palemoon"); #
174 s("xfconf", "libxfconf"); s("xfconf-dev", "libxfconf-dev");
175 s("exo", "libexo"); s("exo-dev", "libexo-dev");
176 s("gconf", "GConf"); s("gconf-dev", "GConf-dev");
177 s("pulseaudio", "apulse");
178 s("cairo-dev", "cairo-gl-dev");
179 s("freetype-dev", "freetype-infinality-dev");
180 s("nspr", "webian-shell");
181 s("nss", "webian-shell");
183 # if called with "--incl": show all deps including glibc-base,
184 # gcc-lib-base, glibc-dev and gcc; otherwise hide them
185 if (incl == "yes" ||
186 ! index($0, "glibc-base") &&
187 ! index($0, "gcc-lib-base") &&
188 ! index($0, "glibc-dev") &&
189 $0 != "gcc")
190 print gensub(" ", "|", "g");
191 }';;
192 esac
193 }
196 # Search for item $1 in db $2
198 indb() {
199 local res="$(awk -vi="$1" '
200 {
201 if ($1 == i)
202 { print $2; found = 1; }
203 }
204 END {
205 if (found != 1) {
206 if (index(i, "statically linked"))
207 print gensub(" ", "_", "g", i);
208 else
209 printf("[%s]\n", i);
210 }
211 }
212 ' $2 | tr '\n' ' ' | sed 's| $||')"
214 outpkg "$res"
215 }
218 # Like `ldd` function but returns packages names where dependency exists.
219 # Also can process some development files
221 tp_ldd() {
222 local tmptmp libs variables pcs pkg pkgs out
223 unset IFS
224 tmptmp=$(mktemp)
226 case $1 in
227 *.la)
228 if [ -n "$la" ]; then # use with --la
229 # found dependencies in the *.la files
230 libs=$(. $1; echo $dependency_libs)
231 for i in $libs; do
232 case $i in
233 -l*) indb "${i/-l/lib}.so" $db_so >>$tmptmp;; # FIXME: I'm not sure it's about a *.so, but *.a often absent
234 *.la) indb "$i" $db_la >>$tmptmp;;
235 esac
236 done
237 fi
238 ;;
239 *.pc)
240 # found dependencies in the *.pc files
241 variables=$(mktemp)
242 # variable value may contain spaces, so use pkg-config to safely get variable's value
243 for i in $(grep '^[a-zA-Z_][a-zA-Z_]*=' $1 | cut -d= -f1); do
244 echo "$i=\"$(pkg-config --variable=$i $1)\""
245 done > $variables
246 . $variables
247 rm $variables
248 # Syntax examples:
249 # Requires: glib-2.0 gobject-2.0
250 # Requires.private: gmodule-no-export-2.0
251 # Requires: gobject-2.0,gio-2.0
252 # Requires.private: nspr >= 4.9.2
253 pcs=$(grep '^Requires' $1 | cut -d: -f2 | tr ',' ' ' | tr '\n' ' ')
254 # expand $variables here, if any:
255 # (remove '>' because '>=' here will redirect `echo` output to file '=')
256 pcs=$(eval echo "${pcs//>/}")
257 for i in $pcs; do
258 isitlib=$(echo $i | tr -d '<=>0-9.')
259 # if it contains only comparisons, numbers, dot - it is not lib, skip
260 [ -n "$isitlib" ] || continue
261 indb "$i.pc" $db_pc >>$tmptmp
262 done
263 # Syntax examples:
264 # Libs: -L${libdir} -lgio-2.0
265 # Libs.private: -lz -lresolv
266 libs=$(grep '^Libs' $1 | cut -d: -f2 | tr '\n' ' ')
267 for i in $libs; do
268 case $i in
269 -L*) eval LIBDIR="${i#-L}";;
270 -l*)
271 eval i="$i" # substitute variables
272 #echo ">i='$i'" >&2
273 pkg=$(indb "lib${i#-l}.so" $db_so)
274 #echo ">>pkg='$pkg'" >&2
275 pkgs=$(awk -F$'\t' -vpkg="$pkg" '{if (index(" " $2 " ", " " pkg " ")) print $2;}' /home/slitaz/cache/split.db)
276 #echo ">>pkgs='$pkgs'" >&2
277 unset out
278 for j in $pkgs; do
279 # seadrch for <pkg>-dev
280 case $j in $pkg-dev) out=$j; break;;
281 esac
282 done
283 #echo ">>'$out'" >&2
284 [ -z "$out" ] &&
285 for j in $pkgs; do
286 # if not found previously, search for <any>-dev
287 case $j in *-dev) out=$j; break;;
288 esac
289 done
290 #echo ">>'$out'" >&2
291 echo ${out:-$pkg}
292 #echo >&2
293 ;;
294 esac
295 done
296 ;;
297 */lib/modules/*)
298 echo 'linux'
299 ;;
300 *.pl|*.pm)
301 echo 'perl'
302 ;;
303 *.py)
304 echo 'python'
305 ;;
306 *)
307 # LD_PRELOAD= LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux* "$1" 2>/dev/null | \
308 # sed 's| =>.*||; s| (.*||; s|\t||' | \
309 readelf -dW "$1" 2>/dev/null \
310 | sed -n '/NEEDED/ s|.*\[\(.*\)\]|\1|p' \
311 | while read i; do
312 indb "$i" $db_so >>$tmptmp
313 done
314 ;;
315 esac
317 sort -u $tmptmp
318 rm $tmptmp
319 }
322 # Return all the names of packages bundled in this receipt
324 all_names() {
325 # Get package names from $SPLIT variable
326 local split=$(echo $SPLIT \
327 | awk '
328 BEGIN { RS = " "; FS = ":"; }
329 { print $1; }' \
330 | tr '\n' ' ')
331 local split_space=" $split "
332 if [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
333 # $PACKAGE included somewhere in $SPLIT (probably in the end).
334 # We should build packages in the order defined in the $SPLIT.
335 echo $split
336 else
337 # We'll build the $PACKAGE, then all defined in the $SPLIT.
338 echo $PACKAGE $split
339 fi
340 }
345 unset IFS
346 . $WOK/$1/receipt
348 if [ -n "$quiet" ]; then
349 sub='\n'
350 else
351 sub=' '
352 fi
354 for pkg in $(all_names); do
355 title 'Dependencies for "%s"' "$pkg"
356 [ -n "$quiet" ] && echo -n "$pkg: "
357 IFS=$'\n'
358 while read file; do
359 # run in subprocess because VERSION may be redefined in .pc file
360 ( tp_ldd "$WOK/$1/taz/$pkg-$VERSION/fs$file" )
361 done < $WOK/$1/taz/$pkg-$VERSION/files.list \
362 | sort -u | grep -v "^$pkg$" | sed '/^$/d' \
363 | tr "$sub" ' '
364 [ -n "$quiet" ] && echo
365 done
367 newline