wok view tazbb/stuff/tazbb @ rev 6094

tazbb/sort_cook_list: wanted fix
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Aug 30 16:34:18 2010 +0200 (2010-08-30)
parents 3e963697ee61
children 8a9364f4f9fb
line source
1 #!/bin/sh
2 # Tazbb - SliTaz Build Bot.
3 # System wide config file: /etc/slitaz/tazbb.conf
4 #
5 # Tazbb is a tool to automate package building, it can be run manually
6 # or via a cron job. On SliTaz build host, tazbb is run in a chroot env.
7 #
8 # (c) 2009 SliTaz GNU/Linux project - GNU gpl v3
9 #
11 # Include config file or exit if no file found.
12 if [ -f "./tazbb.conf" ]; then
13 . ./tazbb.conf
14 elif [ -f "/etc/slitaz/tazbb.conf" ]; then
15 . /etc/slitaz/tazbb.conf
16 else
17 echo -e "\nNo config file found: tazbb.conf...\n" && exit 0
18 fi
19 LOG_SUFFIX=""
20 case "$HG_WOK" in
21 *stable) LOG_SUFFIX="&stable=1";;
22 esac
24 # Tazbb is only for root.
25 if test $(id -u) != 0 ; then
26 echo -e "\nYou must be root to run: `basename $0`.\n" && exit 0
27 fi
29 # Let tazbb finish is work and make sure needed files exist.
30 if [ -f $LOCK_FILE ]; then
31 case $1 in
32 usage|list-*|*block)
33 continue ;;
34 *)
35 echo -e "\nTazbb is already running and locked...\n"
36 exit 0 ;;
37 esac
38 else
39 mkdir -p $DB_DIR $LOG_DIR
40 touch $LOCK_FILE $DB_DIR/blocked
41 fi
43 # Set KERNEL variable
44 if [ -s $BUILD_WOK/linux/receipt ]; then
45 . $BUILD_WOK/linux/receipt
46 KERNEL=$VERSION
47 fi
49 # Get revision
50 cd $HG_WOK
51 NEW_REV=`hg head --template '{rev}\n'`
52 cd - > /dev/null
54 usage()
55 {
56 echo -e "\nSliTaz developers and build host tool\n
57 \033[1mUsage: \033[0m `basename $0` [command] [--option]
58 \033[1mCommands: \033[0m\n
59 usage Print this short usage and command list.
60 list-pkgs List last cooked packages with date.
61 report Run in report mode and dont cook anything [--verbose].
62 cook Cook, install and log a single package build.
63 cook-all Cook all missing, modified or unbuilt packages.
64 cook-commit Cook all packages affected by a commit in the last update.
65 test-pkgs Execute a test suite on all packages [--verbose].
66 [un]block Block or unblock a package to skip or enable building.
67 mail Send mail to package maintainer with tazbbmail.
68 check-depends Verify DEPENDS value with library needs [--verbose].
69 clean-up Remove old packages [--verbose|--dry-run].
70 clean-log Remove all generated build log files.\n"
71 }
73 status()
74 {
75 local CHECK=$?
76 echo -en "\033[70G"
77 if [ $CHECK = 0 ]; then
78 echo "Done"
79 else
80 echo "Failed"
81 fi
82 return $CHECK
83 }
85 top_summary()
86 {
87 cat > $DB_DIR/summary << _EOT_
88 Update : `date`
89 Revision : $NEW_REV (<a href="$HG_URL/log/$NEW_REV">changelog</a>)
90 _EOT_
91 }
93 packages_summary()
94 {
95 if ! grep -q "^Packages" $DB_DIR/summary; then
96 cat >> $DB_DIR/summary << _EOT_
97 Packages : `ls $BUILD_WOK | wc -l` in the wok, `cat $DB_DIR/cooklist | wc -l` to cook, \
98 `cat $DB_DIR/blocked | wc -l` blocked, `cat $DB_DIR/corrupted | wc -l` corrupted
99 _EOT_
100 fi
101 }
103 VERBOSE=""
105 packages_summary_update()
106 {
107 sed -i s/"[0-9]* in the wok"/"`ls $BUILD_WOK | wc -l` in the wok"/ \
108 $DB_DIR/summary
109 sed -i s/"[0-9]* to cook"/"`cat $DB_DIR/cooklist | wc -l` to cook"/ \
110 $DB_DIR/summary
111 sed -i s/"[0-9]* blocked"/"`cat $DB_DIR/blocked | wc -l` blocked"/ \
112 $DB_DIR/summary
113 sed -i s/"[0-9]* corrupted"/"`cat $DB_DIR/corrupted | wc -l` corrupted"/ \
114 $DB_DIR/summary
115 }
117 list_packages()
118 {
119 cd $PACKAGES_REPOSITORY
120 ls -1t *.tazpkg | head -20 | \
121 while read file
122 do
123 echo -n $(stat -c '%y' $PACKAGES_REPOSITORY/$file | cut -d. -f1)
124 echo " $file"
125 done
126 }
128 show_report()
129 {
130 echo "Cooklist"
131 echo "================================================================================"
132 cat $DB_DIR/cooklist && echo ""
133 echo "Packlist"
134 echo "================================================================================"
135 cat $DB_DIR/packlist && echo ""
136 echo "Blocked"
137 echo "================================================================================"
138 cat $DB_DIR/blocked && echo ""
139 echo ""
140 }
142 # URL encoding
143 escape()
144 {
145 echo $1 | sed -e 's/+/%2B/g' -e 's|/|%2F|g' -e 's/:/%3A/g'
146 }
148 update_wok()
149 {
150 local forced
151 forced=""
152 echo ""
153 echo "(updating flavors)" > $DB_DIR/running
154 cd $HG_FLAVORS
155 LAST_REV=`hg head --template '{rev}\n'`
156 hg pull && hg update
157 NEW_REV=`hg head --template '{rev}\n'`
158 if [ "$NEW_REV" != "$LAST_REV" ]; then
159 size=`du -sh $HG_FLAVORS | awk '{ print $1 }'`
160 echo -n "Copying Hg flavors to the build flavors ($size)... "
161 cp -a $HG_FLAVORS/* $BUILD_FLAVORS
162 cp -a $HG_FLAVORS/.hg $BUILD_FLAVORS
163 echo -e "Done\n"
164 forced="yes"
165 fi
166 echo "(updating wok)" > $DB_DIR/running
167 cd $HG_WOK
168 LAST_REV=`hg head --template '{rev}\n'`
169 hg pull && hg update
170 NEW_REV=`hg head --template '{rev}\n'`
171 # Gen a new summary and link last revision for the web interface.
172 echo -e "\nHg wok : $HG_WOK ($NEW_REV)"
173 echo -e "Build wok : $BUILD_WOK ($LAST_REV)\n"
174 top_summary
175 # Copy Hg wok if new revision or exit to stop process since nothing
176 # have change (--forced can be used).
177 if [ "$NEW_REV" != "$LAST_REV" ]; then
178 size=`du -sh $HG_WOK | awk '{ print $1 }'`
179 echo -n "Copying Hg wok to the build wok ($size)... "
180 #rsync -r -n -t $HG_WOK/ $BUILD_WOK/
181 cp -a $HG_WOK/* $BUILD_WOK
182 cp -a $HG_WOK/.hg $BUILD_WOK
183 echo -e "Done\n"
184 else
185 if [ "$1" = "cook-all" ] || [ "$1" = "cook-commit" ]; then
186 if [ "$2" != "--forced" -a -z "$forced" ]; then
187 echo -e "Nothing to cook...\n"
188 packages_summary
189 rm -f $LOCK_FILE && exit 0
190 fi
191 fi
192 fi
193 }
195 # Running 'tazbb report' should not pack anything and --verbose option
196 # can be used to display more messages.
197 check_flavors()
198 {
199 # Clean up last results.
200 rm -f $DB_DIR/packlist && touch $DB_DIR/packlist
201 echo ""
202 echo "Checking all files in: $HG_FLAVORS"
203 echo "================================================================================"
204 echo "(checking flavors)" > $DB_DIR/running
205 for flavor in $(cd $HG_FLAVORS ; ls)
206 do
207 [ "$2" = "--verbose" ] && echo "Flavor : $flavor"
208 if [ ! -s $PACKAGES_REPOSITORY/$flavor.flavor ]; then
209 echo $flavor >> $DB_DIR/packlist
210 [ "$1" = "report" ] && echo "Missing : $flavor"
211 echo "Missing flavor : $flavor" >> $DB_DIR/report
212 continue
213 fi
214 for i in $(find $HG_FLAVORS/$flavor -type f); do
215 [ $PACKAGES_REPOSITORY/$flavor.flavor -nt \
216 $i ] && continue
217 echo $flavor >> $DB_DIR/packlist
218 [ "$1" = "report" ] && echo "Refresh : $flavor for $i"
219 echo "Refresh flavor : $flavor" >> $DB_DIR/report
220 continue 2
221 done
222 [ -s $HG_FLAVORS/$flavor/packages.list ] &&
223 for i in $(cat $HG_FLAVORS/$flavor/packages.list); do
224 if [ ! -d $BUILD_WOK/$i ]; then
225 [ "$1" = "report" ] &&
226 echo "Fix flavor for $i: $flavor"
227 echo "Fix flavor for $i: $flavor" >> $DB_DIR/report
228 continue
229 fi
230 [ $PACKAGES_REPOSITORY/$flavor.flavor -nt \
231 $BUILD_WOK/$i/taz ] && continue
232 echo $flavor >> $DB_DIR/packlist
233 [ "$1" = "report" ] && echo "Repack : $flavor for $i"
234 echo "Repack flavor : $flavor" >> $DB_DIR/report
235 continue 2
236 done
237 done
239 # Check for meta flavors
240 for flavor in $(cd $HG_FLAVORS ; ls)
241 do
242 grep -q ^ROOTFS_SELECTION $HG_FLAVORS/$flavor/receipt || continue
243 . $HG_FLAVORS/$flavor/receipt
244 set -- $ROOTFS_SELECTION
245 if [ $PACKAGES_REPOSITORY/$2.flavor -nt \
246 $PACKAGES_REPOSITORY/$flavor.flavor ]; then
247 echo $flavor >> $DB_DIR/packlist
248 [ "$1" = "report" ] && echo "Refresh : $flavor for $2"
249 echo "Refresh meta flavor : $flavor" >> $DB_DIR/report
250 continue
251 fi
252 if grep -q ^$2$ $DB_DIR/packlist ; then
253 echo $flavor >> $DB_DIR/packlist
254 [ "$1" = "report" ] && echo "Repack : $flavor for $2"
255 echo "Repack meta flavor : $flavor" >> $DB_DIR/report
256 continue
257 fi
258 done
259 }
261 # Here we pack all flavors found in the packlist.
262 pack_flavors()
263 {
264 [ -s $DB_DIR/packlist ] || return
265 [ $PACKAGES_REPOSITORY/packages.list -nt /var/lib/tazpkg/packages.list ] &&
266 cp -a $PACKAGES_REPOSITORY/packages.list /var/lib/tazpkg/packages.list
267 cd $PACKAGES_REPOSITORY
268 for flavor in $(cat $DB_DIR/packlist)
269 do
270 tazlito pack-flavor $flavor
271 # Remove flavor from the packlist and empty lines for HTML <pre>.
272 sed -i /"^$flavor$"/d $DB_DIR/packlist
273 sed -i '/^$/d' $DB_DIR/packlist
274 done
275 cd - > /dev/null
276 }
278 # Running 'tazbb report' should not cook anything and --verbose option
279 # can be used to display more messages.
280 check_wok()
281 {
282 # Clean up last results.
283 rm -f $DB_DIR/cooklist && touch $DB_DIR/cooklist
284 rm -f $DB_DIR/report && touch $DB_DIR/report
285 rm -f $DB_DIR/unbuilt && touch $DB_DIR/unbuilt
286 echo "Checking all files in: $HG_WOK"
287 echo "================================================================================"
288 echo "(checking wok)" > $DB_DIR/running
289 TOOLCHAIN="$(. $HG_WOK/slitaz-toolchain/receipt ; echo $DEPENDS)"
290 TOOLCHAIN="$TOOLCHAIN glibc linux" # break cook loop
291 for pkg in $HG_WOK/*
292 do
293 EXTRAVERSION=""
294 WANTED=""
295 BUILD_DEPENDS=""
296 [ -s $pkg/receipt ] || continue
297 . $pkg/receipt
298 [ "$2" = "--verbose" ] && echo "Package : $PACKAGE"
299 # Skip blocked packages.
300 if grep -qs "^$PACKAGE$" $DB_DIR/blocked; then
301 echo "Blocked : $PACKAGE ($VERSION)" && continue
302 fi
304 # Some packages may compute VERSION at cook time (bristuff)
305 if grep -q ^get_version $pkg/receipt; then
306 . $BUILD_WOK/$PACKAGE/taz/*/receipt
307 fi
309 # First check if package exit. Package naming _must_ be in the form of:
310 # $PACKAGE-$VERSION or $PACKAGE-${VERSION}$EXTRAVERSION (Kernel string).
311 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg ]; then
312 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
313 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg ]; then
314 [ "$1" = "report" ] && echo "Missing : $PACKAGE ($VERSION)"
315 echo "Missing : $PACKAGE ($VERSION)" >> $DB_DIR/report
316 echo "$PACKAGE" >> $DB_DIR/cooklist
317 fi
318 else
319 # Check if package is up-to-date.
320 PKG_YEAR=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%Y'`
321 PKG_DATE=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%m%d%H%M'`
322 for file in `find $pkg -type f`
323 do
324 FILE_YEAR=`date -u -r $file '+%Y'`
325 FILE_DATE=`date -u -r $file '+%m%d%H%M'`
326 [ "$2" = "--verbose" ] && echo " -> Checking: $file"
327 if [ "$FILE_YEAR" -ge "$PKG_YEAR" -a "$FILE_DATE" -gt "$PKG_DATE" ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
328 [ "$1" = "report" ] && echo "Refresh : $PACKAGE ($VERSION)"
329 echo "Refresh : $PACKAGE ($VERSION)" >> $DB_DIR/report
330 echo "$PACKAGE" >> $DB_DIR/cooklist
331 fi
332 done
333 fi
334 # Now check if package is built and not already in the list.
335 if [ ! -d $BUILD_WOK/$PACKAGE/taz ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
336 [ "$1" = "report" ] && echo "Unbuilt : $PACKAGE ($VERSION)"
337 echo "Unbuilt : $PACKAGE ($VERSION)" >> $DB_DIR/report
338 echo "$PACKAGE" >> $DB_DIR/cooklist
339 fi
340 if ! grep -q $PACKAGE $DB_DIR/cooklist; then
341 case " $TOOLCHAIN " in
342 *\ $PACKAGE\ *) continue;;
343 esac
344 case "$PACKAGE" in
345 tazbb|tazwok|tazpkg) continue;;
346 esac
347 for dep in $BUILD_DEPENDS $TOOLCHAIN ; do
348 [ $BUILD_WOK/$PACKAGE/taz -nt $BUILD_WOK/$dep/taz ] && continue
349 [ "$1" = "report" ] && echo "Refresh : $PACKAGE (older than $dep)"
350 echo "Refresh : $PACKAGE (older than $dep)" >> $DB_DIR/report
351 echo "$PACKAGE" >> $DB_DIR/cooklist
352 break
353 done
354 fi
355 # Rebuild unbuilt packages list with link to log file. This list
356 # is also generated by cook_inslall to have real time stats.
357 if [ ! -d $BUILD_WOK/$PACKAGE/taz ]; then
358 echo "<a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">$PACKAGE</a>" \
359 >> $DB_DIR/unbuilt
360 fi
361 done
362 packages_summary
363 }
365 # Create a new cooklist and summary (dont modify report) so 'tazbb cook-commit'
366 # can cook last changes.
367 check_commit()
368 {
369 echo "(checking commit)" > $DB_DIR/running
370 cd $HG_WOK
371 # Clean up last results.
372 rm -f $DB_DIR/cooklist && touch $DB_DIR/cooklist
373 # Get the name of modified packages by the revision range. +1 last
374 # commit was build by the previous build.
375 LAST_REV=$(($LAST_REV+1))
376 echo -e "Will cook from revision $LAST_REV to $NEW_REV\n"
377 for file in `hg log --rev=$LAST_REV:$NEW_REV --template '{files}\n'`
378 do
379 pkg=`echo $file | cut -d "/" -f 1`
380 if ! grep -q ^$pkg$ $DB_DIR/cooklist; then
381 . $pkg/receipt
382 echo "Commit : $PACKAGE ($VERSION)" >> $DB_DIR/report
383 echo "$PACKAGE" >> $DB_DIR/cooklist
384 fi
385 done
386 packages_summary
387 }
389 # Cook one package
390 cook_package()
391 {
392 EXTRAVERSION=""
393 DEPENDS=""
394 BUILD_DEPENDS=""
395 SOURCE=""
396 WANTED=""
397 echo "(cooking <a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>)" > $DB_DIR/running
398 tazwok clean $pkg
399 script -c "echo 'install' | tazwok cook $pkg" $LOG_DIR/$pkg.log
400 # Install new package (important for new shared libs). Note
401 # that tests are done separatly with 'test_packages' and should
402 # be done by tazwok.
403 if [ -f $BUILD_WOK/$pkg/taz/*/receipt ]; then
404 TAZBB_NO_INSTALL=""
405 . $BUILD_WOK/$pkg/taz/*/receipt
406 [ -n "$TAZBB_NO_INSTALL" ] && return 0
407 echo "(installing $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg)" \
408 > $DB_DIR/running
409 yes | tazpkg install \
410 $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg \
411 --forced
412 return 0
413 fi
414 return 1
415 }
417 # Sort list according WANTED and BUILD_DEPENDS
418 sort_cook_list()
419 {
420 sort | while read pkg; do
421 echo -n "$pkg"
422 WANTED=""
423 BUILD_DEPENDS=""
424 . $BUILD_WOK/$pkg/receipt
425 MISSING=""
426 for i in $WANTED $BUILD_DEPENDS ; do
427 # Verify that the dependancy exists and is older
428 [ -f $BUILD_WOK/$i/taz/*/receipt ] &&
429 [ $BUILD_WOK/$pkg/taz/*/receipt \
430 -nt $BUILD_WOK/$i/taz/*/receipt ] && continue
431 WANTED=""
432 [ -f $BUILD_WOK/$i/receipt ] &&
433 . $BUILD_WOK/$i/receipt
434 # This dependancy may be cooked
435 # by another package
436 [ -n "$WANTED" ] && i=$WANTED
437 case " $MISSING " in
438 *\ $i\ *);;
439 *) echo -n " $i";;
440 esac
441 MISSING="$MISSING $i"
442 done
443 echo ""
444 done | awk '
445 function show(name)
446 {
447 print name;
448 got[name]++;
449 if (revdepcnt[name] > 0)
450 for (i = split(revdep[name], pkg, " "); i > 0; i--)
451 if (--depcnt[pkg[i]] == 0) show(pkg[i]);
452 }
454 {
455 if ($2 == "") show($1);
456 else {
457 depcnt[$1] = NF - 1;
458 unres = unres " " $1;
459 for (i = 2; i <= NF; i++) {
460 if (got[$i] > 0) continue;
461 revdepcnt[$i]++;
462 revdep[$i] = revdep[$i] " " $1;
463 }
464 }
465 }
466 END {
467 for (i = split(unres, pkg, " "); i > 0; i--)
468 if (depcnt[pkg[i]] > 0) print pkg[i];
469 }
470 '
471 }
473 # Here we cook all packages found in the cooklist.
474 cook_install()
475 {
476 echo "" > $DB_DIR/unbuilt
477 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
478 do
479 if ! cook_package $pkg; then
480 # Link to build log.
481 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
482 $DB_DIR/unbuilt
483 fi
484 missing_depends="$(check_depends_pkg $pkg)"
485 if [ -n "$missing_depends" ]; then
486 cat >> $LOG_DIR/$pkg.log <<EOT
488 Update $pkg receipt for DEPENDS :
489 The package $pkg depends on packages $missing_depends
491 EOT
492 # Unbuild package
493 rm -rf $BUILD_WOK/$pkg/taz
494 # Link to build log.
495 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
496 $DB_DIR/unbuilt
497 fi
498 # Remove package from the cooklist and empty lines for HTML <pre>.
499 sed -i /"^$pkg$"/d $DB_DIR/cooklist
500 sed -i '/^$/d' $DB_DIR/cooklist
501 packages_summary_update
502 done
503 }
505 # Build depends_to_skip list with packages to remove from depends_to_add list
506 # These packages are already present in depends_to_add trees
507 scan_depends_to_skip()
508 {
509 local i
510 case " $depends_to_skip " in
511 *\ $1\ *) return;;
512 esac
513 [ -d $BUILD_WOK/$1 ] || return
514 DEPENDS=""
515 . $BUILD_WOK/$1/receipt
516 for i in $DEPENDS ; do
517 case " $depends_to_add " in
518 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
519 esac
520 done
521 for i in $DEPENDS ; do
522 scan_depends_to_skip $i
523 done
524 }
526 # Reduce depends list by scanning nested depends
527 show_missing_depends()
528 {
529 local i
530 depends_to_add=""
531 depends_to_skip="$2"
532 for i in $1 ; do
533 case " $depends_to_add " in
534 *\ $i\ *) continue;;
535 esac
536 depends_to_add="$depends_to_add$i "
537 done
538 for i in $depends_to_add ; do
539 scan_depends_to_skip $i
540 done
541 for i in $depends_to_add ; do
542 case " $depends_to_skip " in
543 *\ $i\ *) continue;;
544 esac
545 echo -n "$i "
546 done
547 }
549 # Build all_depends variable
550 scan_dep()
551 {
552 local i
553 all_depends="$all_depends$PACKAGE "
554 for i in $DEPENDS $SUGGESTED ; do
555 case " $all_depends " in
556 *\ $i\ *) continue;;
557 esac
558 [ -d $BUILD_WOK/$i ] || {
559 all_depends="$all_depends$i "
560 continue
561 }
562 DEPENDS=""
563 SUGGESTED=""
564 . $BUILD_WOK/$i/receipt
565 scan_dep
566 done
567 }
569 # Check for ELF file
570 is_elf()
571 {
572 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
573 }
575 # Print shared library dependencies
576 ldd()
577 {
578 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
579 }
581 # scan a file for shared libraries and display according package names
582 check_depends_file()
583 {
584 file=$1
585 is_elf $file || continue
586 case "$file" in
587 *.o|*.ko|*.ko.gz) continue;;
588 esac
589 [ -s /tmp/files.list.tazbb$$ ] ||
590 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
591 ldd $file | while read lib rem; do
592 case "$lib" in
593 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
594 continue;;
595 esac
596 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
597 case " $all_depends " in
598 *\ $dep\ *) continue 2;;
599 esac
600 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
601 case " $all_depends " in
602 *\ $vdep\ *) continue 3;;
603 esac
604 done
605 done
606 [ -n "$dep" ] || dep="UNKNOWN"
607 all_depends="$all_depends $dep"
608 if [ -n "$VERBOSE" ]; then
609 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
610 fi
611 echo -n "$dep "
612 done
613 }
615 DEFAULT_DEPENDS="glibc-base"
617 # scan a package for shared libraries and display missing package in DEPENDS
618 check_depends_pkg()
619 {
620 pkg=$1
621 echo "(checking depends for $pkg)" > $DB_DIR/running
622 tmp=/tmp/tazbb$$
623 mkdir $tmp
624 package=$(basename $pkg)
625 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
626 cd $tmp
627 tazpkg extract $pkg > /dev/null 2>&1
628 fi
629 . */receipt
630 all_depends="$DEFAULT_DEPENDS "
631 scan_dep
632 toadd=$(find */fs -type f | while read file ; do
633 check_depends_file $file
634 done)
635 . */receipt
636 rm -rf */
637 cd - > /dev/null
638 rm -rf $tmp
639 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
640 }
642 check_depends_this_file()
643 {
644 file=$1
645 all_depends="$DEFAULT_DEPENDS "
646 scan_dep
647 check_depends_file $file
648 }
650 # Remove old packages in the build wok and clean pkgs repository. The
651 # Hg wok is copied into the build wok so packages removed by hg must be
652 # removed. To remove old packages in the repository we look into the
653 # build wok and dont remove unbuilt packages. Clean-up will also remove
654 # all corrupted packages.
655 clean_up()
656 {
657 touch $DB_DIR/removed
658 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
659 echo "(cleaning)" > $DB_DIR/running
660 for pkg in `ls $BUILD_WOK`
661 do
662 if [ ! -d $HG_WOK/$pkg ]; then
663 case $2 in
664 --dry-run)
665 echo "Removing directory : $pkg" ;;
666 --verbose)
667 echo "Removing directory : $pkg"
668 rm -rf $BUILD_WOK/$pkg ;;
669 *)
670 rm -rf $BUILD_WOK/$pkg ;;
671 esac
672 fi
673 done
674 # Build a packages list with EXTRAVERSION so we can grep into it.
675 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
676 for receipt in $BUILD_WOK/*/taz/*/receipt
677 do
678 EXTRAVERSION=""
679 . $receipt
680 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
681 done
682 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
683 do
684 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
685 case $2 in
686 --dry-run)
687 echo "Removing package : $pkg" ;;
688 --verbose)
689 echo "Removing package : $pkg"
690 echo "$pkg" >> $DB_DIR/removed
691 rm -f $PACKAGES_REPOSITORY/$pkg ;;
692 *)
693 echo "$pkg" >> $DB_DIR/removed
694 rm -f $PACKAGES_REPOSITORY/$pkg ;;
695 esac
696 fi
697 done
698 # Remove all corrupted packages
699 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
700 do
701 case $2 in
702 --dry-run)
703 echo "Removing corrupted: $pkg" ;;
704 --verbose)
705 echo "Removing corrupted: $pkg"
706 echo "$pkg" >> $DB_DIR/removed
707 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
708 *)
709 echo "$pkg" >> $DB_DIR/removed
710 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
711 esac
712 done
713 echo ""
714 # Keep the 20 last removed packages list.
715 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
716 mv -f /tmp/removed.tail $DB_DIR/removed
717 # Clean packages stuff/ directory
718 echo -e "\nCleaning the build wok stuff/ directories...\n"
719 for pkg in `ls $BUILD_WOK`
720 do
721 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
722 cd $BUILD_WOK/$pkg
723 for file in `find stuff -type f`
724 do
725 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
726 echo "Removing: $pkg/$file"
727 rm $file
728 fi
729 done
730 fi
731 done
732 }
734 blocked_urls()
735 {
736 rm -f $DB_DIR/blocked.urls
737 for pkg in `cat $DB_DIR/blocked`
738 do
739 if [ -f $LOG_DIR/$pkg.log ]; then
740 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
741 $DB_DIR/blocked.urls
742 else
743 echo "$pkg" >> $DB_DIR/blocked.urls
744 fi
745 done
746 }
748 # 4k, not a meta or a get-* package and no files = buggy package
749 test_packages()
750 {
751 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
752 echo "================================================================================"
753 echo "(testing packages)" > $DB_DIR/running
754 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
755 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
756 do
757 tmp=/tmp/bb-test.$$
758 CATEGORY=""
759 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
760 mkdir -p $tmp && cd $tmp
761 cpio -i receipt >/dev/null 2>&1 < $pkg
762 . ./receipt
763 if [ "$CATEGORY" != "meta" ]; then
764 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
765 cpio -i fs.cpio.gz >/dev/null 2>&1 < $pkg
766 cpio -i fs.cpio.lzma >/dev/null 2>&1 < $pkg
767 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
768 echo "Missing filesystem `basename $pkg`"
769 if [ -f $LOG_DIR/$PACKAGE.log ];then
770 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
771 >> $DB_DIR/corrupted
772 else
773 echo "Missing filesystem `basename $pkg`" \
774 >> $DB_DIR/corrupted
775 fi
776 else
777 ( zcat fs.cpio.gz 2> /dev/null || \
778 unlzma -c fs.cpio.lzma ) | \
779 cpio -id >/dev/null 2>&1
780 files=`find fs -type f -o -type l`
781 if [ -z "$files" ]; then
782 echo "Empty filesystem `basename $pkg`"
783 if [ -f $LOG_DIR/$PACKAGE.log ]; then
784 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
785 >> $DB_DIR/corrupted
786 else
787 echo "Empty filesystem `basename $pkg`" \
788 >> $DB_DIR/corrupted
789 fi
790 fi
791 fi
792 fi
793 cd .. && rm -rf $tmp
794 fi
795 done
796 packages_summary_update
797 echo ""
798 }
800 # Generate flavor list
801 gen_flavor_list()
802 {
803 cd $PACKAGES_REPOSITORY
804 noheader=""
805 for i in *.flavor; do
806 tazlito show-flavor $i --brief $noheader
807 noheader="--noheader"
808 done > flavors.list
809 cd - > /dev/null
810 }
812 case "$1" in
813 list-pkgs)
814 # List last cooked packages.
815 list_packages ;;
816 report)
817 # Run in report mode. If an update is done we must cook-all to
818 # rebuild all updated packages.
819 [ "$2" == "--update" ] && update_wok $@ || echo ""
820 check_wok $@
821 check_flavors $@
822 test_packages $@
823 show_report ;;
824 cook)
825 # Cook, install and log a single package build.
826 if [ -z $2 ]; then
827 echo "Please specify a package on the command line."
828 rm -f $LOCK_FILE && exit 0
829 fi
830 pkg=$2
831 echo "Starting to cook and install: $pkg"
832 if ! cook_package $pkg; then
833 echo "Unable to install: $pkg"
834 fi ;;
835 cook-all)
836 # Update wok, gen report (with cooklist), cook all packages, test,
837 # clean, gen new report and lists.
838 update_wok $@
839 check_wok $@
840 cook_install
841 test_packages $@
842 check_flavors $@
843 pack_flavors
844 clean_up $@
845 check_wok $@
846 echo "(generating lists)" > $DB_DIR/running
847 tazwok gen-list --text
848 check_flavors $@
849 gen_flavor_list
850 echo "" ;;
851 cook-commit)
852 # Cook all packages affected by the last commits in the wok.
853 # Clean up is done only by cook-all to avoid rebuild of corrupted
854 # packages on each commit.
855 update_wok $@
856 check_commit
857 cook_install
858 test_packages $@
859 check_flavors $@
860 pack_flavors
861 check_wok $@
862 check_flavors $@
863 echo "(generating lists)" > $DB_DIR/running
864 tazwok gen-list --text
865 gen_flavor_list
866 echo "" ;;
867 block)
868 # Add a pkg name to the list of blocked packages.
869 echo ""
870 if grep -qs "^$2$" $DB_DIR/blocked; then
871 echo -e "$2 is already in the blocked packages list."
872 else
873 echo -n "Adding $2 to : $DB_DIR/blocked... "
874 echo "$2" >> $DB_DIR/blocked && echo "Done"
875 if grep -q "^$2$" $DB_DIR/cooklist; then
876 echo -n "Removing $2 from : $DB_DIR/cooklist... "
877 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
878 packages_summary_update
879 fi
880 fi
881 blocked_urls
882 echo "" ;;
883 unblock)
884 # Remove a pkg name from the list of blocked packages.
885 echo ""
886 if grep -qs "^$2$" $DB_DIR/blocked; then
887 echo -n "Removing $2 from : $DB_DIR/blocked... "
888 sed -i /"^$2$"/d $DB_DIR/blocked
889 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
890 echo -n "Adding $2 to : $DB_DIR/cooklist... "
891 echo "$2" >> $DB_DIR/cooklist && echo "Done"
892 packages_summary_update
893 else
894 echo -e "$2 is not in the blocked packages list."
895 fi
896 blocked_urls
897 echo "" ;;
898 test-pkgs)
899 # Start a test suite on all builded packages.
900 test_packages $@ ;;
901 test-suite)
902 # Start a test suite on all builded package and the wok using
903 # the great 'tazwok check'.
904 #
905 # test_packages > $LOG_DIR/test-suite.log
906 # tazwok check >> $LOG_DIR/test-suite.log
907 #
908 test_packages $@
909 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
910 mail)
911 # Tazbbmail Pythom script wrapper.
912 PACKAGE=$2
913 tazbbmail $PACKAGE ;;
914 clean-up)
915 # Remove old packages and generate new packages lists.
916 update_wok $@
917 clean_up $@
918 packages_summary_update
919 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
920 clean-log)
921 logs=`ls $LOG_DIR | wc -l`
922 echo -n "Cleaning: $LOG_DIR... "
923 rm -rf $LOG_DIR/*
924 echo "$logs log removed" ;;
925 check-depends)
926 case "$2" in
927 wok)
928 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
929 missing_depends="$(check_depends_pkg $pkg)"
930 [ -n "$missing_depends" ] &&
931 echo "The package $pkg depends on $missing_depends."
932 done ;;
933 package)
934 pkg=$3
935 VERBOSE=$4
936 missing_depends="$(check_depends_pkg $pkg)"
937 [ -n "$missing_depends" ] &&
938 echo "The package $pkg depends on $missing_depends."
939 ;;
940 file)
941 file=3
942 VERBOSE=$4
943 missing_depends="$(check_depends_this_file $file)"
944 [ -n "$missing_depends" ] &&
945 echo "The file $file depends on $missing_depends."
946 ;;
947 *) cat <<EOT
948 check-depends wok check every package in wok.
949 check-depends package <pkg> check one package.
950 check-depends file <filename> check one file only.
951 EOT
952 ;;
953 esac ;;
954 *)
955 usage ;;
956 esac
958 echo "" > $DB_DIR/running
959 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
961 exit 0