cookutils view modules/deps @ rev 940

cook: improve patchit() and all_names(); modules/deps: change the cases upside down, show update stats (it not hangs); lighttpd/index.cgi: use split.db to make search datalist, and to search packages (no need to `ls` ~ 5000 dirs, just one file); lighttpd/cooker.css: style the matches in search page.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jun 22 20:18:08 2017 +0300 (2017-06-22)
parents 9c470f60d0d0
children 6e892f321f46
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
21 # recreate "combined list of all files" in the cases:
22 # * if absent
23 # * mirror files list has been updated
24 # * local files list has been updated
26 case $(hostname) in
27 # Do we need to use mirror files list?
28 # It's useful on casual development on local host, but useless on cooker server
29 # (and slows down list creation a lot).
30 tank)
31 [ ! -s $fl -o $fl_local -nt $fl ] && cp $fl_local $fl
32 ;;
33 *)
34 if [ ! -s $fl -o $fl_mirrorz -nt $fl -o $fl_local -nt $fl ]; then
35 action 'Updating %s...' "$(basename $fl)"
36 # unpack mirror files list
37 fl_mirror="$(mktemp)"
38 lzcat $fl_mirrorz > $fl_mirror
40 # remove packages that exist in local list
41 cut -d: -f1 $fl_local | uniq | \
42 while read package; do
43 sed -i "/^$package: /d" $fl_mirror
44 done
46 # combine lists
47 cat $fl_mirror $fl_local > $fl
49 # clean
50 rm $fl_mirror
51 status
52 fi
53 ;;
54 esac
56 # recreate "database with *.so files" in the cases:
57 # * if absent
58 # * combined list of all files has been updated
60 if [ ! -s $db_so -o $fl -nt $db_so ]; then
61 action 'Updating %s...' "$(basename $db_so)"
62 fgrep '/lib/' $fl | fgrep '.so' | \
63 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
64 awk -F$'\t' '{if ($2 !~ "uclibc") print}' | \
65 sort > $db_so
66 status
67 fi
69 # recreate "database with *.a files" in the cases:
70 # * if absent
71 # * combined list of all files has been updated
73 if [ ! -s $db_a -o $fl -nt $db_a ]; then
74 action 'Updating %s...' "$(basename $db_a)"
75 fgrep '/usr/lib/lib' $fl | fgrep '.a' | \
76 sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
77 sort > $db_a
78 status
79 fi
81 # recreate "database with *.la files" in the cases:
82 # * if absent
83 # * combined list of all files has been updated
85 if [ ! -s $db_la -o $fl -nt $db_la ]; then
86 action 'Updating %s...' "$(basename $db_la)"
87 fgrep '/usr/lib/' $fl | fgrep '.la' | \
88 sed 's|^\([^:]*\): \(.*\)$|\2\t\1|' | \
89 sort > $db_la
90 status
91 fi
93 # recreate "database with *.pc files" in the cases:
94 # * if absent
95 # * combined list of all files has been updated
97 if [ ! -s $db_pc -o $fl -nt $db_pc ]; then
98 action 'Updating %s...' "$(basename $db_pc)"
99 grep '\.pc$' $fl | \
100 sed -e 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' -e '/\tbuildroot$/d' | \
101 sort > $db_pc
102 status
103 fi
108 # Auxiliary function that deals with "not found" packages as well as with "repeatedly found" packages
110 outpkg() {
111 pkgs="$1"
112 case $pkgs in
113 *ld-linux.so*);;
114 *linux-gate.so*);;
115 *)
116 echo "$pkgs" | awk '
117 # if both packages exist in list, return the first one only
118 function s(pkg1, pkg2) {
119 if (index(" "$0" ", " "pkg1" ") && index(" "$0" ", " " pkg2 " "))
120 $0 = pkg1;
121 }
122 {
123 s("wine", "wine-rt");
124 s("samba", "samba-pam");
125 s("mesa", "mesa-wayland");
126 s("mysql", "mariadb");
127 s("perl", "perl-thread");
128 s("xorg-server", "xorg-server-light");
129 s("cairo", "cairo-gl");
130 s("freetype", "freetype-infinality");
131 s("freetype", "freetype-without-harfbuzz");
132 s("harfbuzz", "harfbuzz-icu");
133 s("openbox", "openbox-imlib2");
134 s("gcc-lib-base", "gcc49-lib-base"); # also gcc54-lib-base and gcc61-lib-base
135 s("polkit", "polkit-pam");
136 s("libgudev", "eudev"); # also systemd
137 s("xz-dev", "liblzma-dev");
139 if (! index($0, "glibc-base") &&
140 ! index($0, "gcc-lib-base") &&
141 ! index($0, "glibc-dev") &&
142 $0 != "gcc")
143 print gensub(" ", "|", "g");
144 }';;
145 esac >>$tmptmp
146 }
149 # Search for item $1 in db $2
151 indb() {
152 local res="$(awk -vi="$1" '
153 {
154 if ($1 == i)
155 { print $2; found = 1; }
156 }
157 END {
158 if (found != 1) {
159 if (index(i, "statically linked"))
160 print gensub(" ", "_", "g", i);
161 else
162 printf("[%s]\n", i);
163 }
164 }
165 ' $2 | tr '\n' ' ')"
166 outpkg "${res% }"
167 }
170 # Like `ldd` function but returns packages names where dependency exists.
171 # Also can process some development files
173 tp_ldd() {
174 unset IFS
175 tmptmp=$(mktemp)
177 case $1 in
178 *.la)
179 # found dependencies in the *.la files
180 libs=$(. $1; echo $dependency_libs)
181 for i in $libs; do
182 case $i in
183 -l*) indb "lib${i#-l}.so" $db_so;; # FIXME: I'm not sure it's about a *.so, but *.a often absent
184 *.la) indb "$i" $db_la;;
185 esac
186 done
187 ;;
188 *.pc)
189 # found dependencies in the *.pc files
190 # Syntax examples:
191 # Requires: glib-2.0 gobject-2.0
192 # Requires.private: gmodule-no-export-2.0
193 # Requires: gobject-2.0,gio-2.0
194 # Requires.private: nspr >= 4.9.2
195 pcs=$(grep '^Requires' $1 | cut -d: -f2 | tr ',' ' ' | tr '\n' ' ')
196 for i in $pcs; do
197 isitlib=$(echo $i | tr -d '<=>0-9.')
198 # if it contains only comparisons, numbers, dot - it is not lib, skip
199 [ -n "$isitlib" ] || continue
200 indb "$i.pc" $db_pc
201 done
202 # Syntax examples:
203 # Libs: -L${libdir} -lgio-2.0
204 # Libs.private: -lz -lresolv
205 libs=$(grep '^Libs' $1 | cut -d: -f2 | tr '\n' ' ')
206 for i in $libs; do
207 case $i in
208 -l*) indb "lib${i#-l}.so" $db_so;;
209 esac
210 done
211 ;;
212 */lib/modules/*)
213 echo 'linux'
214 ;;
215 *.pl|*.pm)
216 echo 'perl'
217 ;;
218 *.py)
219 echo 'python'
220 ;;
221 *)
222 LD_PRELOAD= LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux* "$1" 2>/dev/null | \
223 sed 's| =>.*||; s| (.*||; s|\t||' | \
224 while read i; do
225 indb "$i" $db_so
226 done
227 ;;
228 esac
230 sort -u $tmptmp
231 rm $tmptmp
232 }
235 # Return all the names of packages bundled in this receipt
237 all_names() {
238 local split=" $SPLIT "
239 if [ "${split/ $PACKAGE /}" != "$split" ]; then
240 # $PACKAGE included somewhere in $SPLIT (probably in the end).
241 # We should build packages in the order defined in the $SPLIT.
242 echo $SPLIT
243 else
244 # We'll build the $PACKAGE, then all defined in the $SPLIT.
245 echo $PACKAGE $SPLIT
246 fi
247 }
252 unset IFS
253 . $WOK/$1/receipt
255 for pkg in $(all_names); do
256 title 'Dependencies for "%s"' "$pkg"
257 IFS=$'\n'
258 while read file; do
259 tp_ldd "$WOK/$1/taz/$pkg-$VERSION/fs$file"
260 done < $WOK/$1/taz/$pkg-$VERSION/files.list | sort -u | grep -v "^$pkg$"
261 done
263 newline