wok view tazbb/stuff/tazbb @ rev 6065

tazbb: breaks a cook loop
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 22 11:18:37 2010 +0200 (2010-08-22)
parents db0522a9fd7a
children 32233f725ab5
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 if [ ! -f $BUILD_WOK/$i/taz/*/receipt ]; then
428 case " $MISSING " in
429 *\ $i\ *);;
430 *) echo -n " $i";;
431 esac
432 MISSING="$MISSING $i"
433 fi
434 done
435 echo ""
436 done | awk '
437 function show(name)
438 {
439 print name;
440 got[name]++;
441 if (revdepcnt[name] > 0)
442 for (i = split(revdep[name], pkg, " "); i > 0; i--)
443 if (--depcnt[pkg[i]] == 0) show(pkg[i]);
444 }
446 {
447 if ($2 == "") show($1);
448 else {
449 depcnt[$1] = NF - 1;
450 unres = unres " " $1;
451 for (i = 2; i <= NF; i++) {
452 if (got[$i] > 0) continue;
453 revdepcnt[$i]++;
454 revdep[$i] = revdep[$i] " " $1;
455 }
456 }
457 }
458 END {
459 for (i = split(unres, pkg, " "); i > 0; i--)
460 if (depcnt[pkg[i]] > 0) print pkg[i];
461 }
462 '
463 }
465 # Here we cook all packages found in the cooklist.
466 cook_install()
467 {
468 echo "" > $DB_DIR/unbuilt
469 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
470 do
471 if ! cook_package $pkg; then
472 # Link to build log.
473 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
474 $DB_DIR/unbuilt
475 fi
476 missing_depends="$(check_depends_pkg $pkg)"
477 if [ -n "$missing_depends" ]; then
478 cat >> $LOG_DIR/$pkg.log <<EOT
480 Update $pkg receipt for DEPENDS :
481 The package $pkg depends on packages $missing_depends
483 EOT
484 # Unbuild package
485 rm -rf $BUILD_WOK/$pkg/taz
486 # Link to build log.
487 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
488 $DB_DIR/unbuilt
489 fi
490 # Remove package from the cooklist and empty lines for HTML <pre>.
491 sed -i /"^$pkg$"/d $DB_DIR/cooklist
492 sed -i '/^$/d' $DB_DIR/cooklist
493 packages_summary_update
494 done
495 }
497 # Build depends_to_skip list with packages to remove from depends_to_add list
498 # These packages are already present in depends_to_add trees
499 scan_depends_to_skip()
500 {
501 local i
502 case " $depends_to_skip " in
503 *\ $1\ *) return;;
504 esac
505 [ -d $BUILD_WOK/$1 ] || return
506 DEPENDS=""
507 . $BUILD_WOK/$1/receipt
508 for i in $DEPENDS ; do
509 case " $depends_to_add " in
510 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
511 esac
512 done
513 for i in $DEPENDS ; do
514 scan_depends_to_skip $i
515 done
516 }
518 # Reduce depends list by scanning nested depends
519 show_missing_depends()
520 {
521 local i
522 depends_to_add=""
523 depends_to_skip="$2"
524 for i in $1 ; do
525 case " $depends_to_add " in
526 *\ $i\ *) continue;;
527 esac
528 depends_to_add="$depends_to_add$i "
529 done
530 for i in $depends_to_add ; do
531 scan_depends_to_skip $i
532 done
533 for i in $depends_to_add ; do
534 case " $depends_to_skip " in
535 *\ $i\ *) continue;;
536 esac
537 echo -n "$i "
538 done
539 }
541 # Build all_depends variable
542 scan_dep()
543 {
544 local i
545 all_depends="$all_depends$PACKAGE "
546 for i in $DEPENDS $SUGGESTED ; do
547 case " $all_depends " in
548 *\ $i\ *) continue;;
549 esac
550 [ -d $BUILD_WOK/$i ] || {
551 all_depends="$all_depends$i "
552 continue
553 }
554 DEPENDS=""
555 SUGGESTED=""
556 . $BUILD_WOK/$i/receipt
557 scan_dep
558 done
559 }
561 # Check for ELF file
562 is_elf()
563 {
564 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
565 }
567 # Print shared library dependencies
568 ldd()
569 {
570 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
571 }
573 # scan a file for shared libraries and display according package names
574 check_depends_file()
575 {
576 file=$1
577 is_elf $file || continue
578 case "$file" in
579 *.o|*.ko|*.ko.gz) continue;;
580 esac
581 [ -s /tmp/files.list.tazbb$$ ] ||
582 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
583 ldd $file | while read lib rem; do
584 case "$lib" in
585 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
586 continue;;
587 esac
588 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
589 case " $all_depends " in
590 *\ $dep\ *) continue 2;;
591 esac
592 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
593 case " $all_depends " in
594 *\ $vdep\ *) continue 3;;
595 esac
596 done
597 done
598 [ -n "$dep" ] || dep="UNKNOWN"
599 all_depends="$all_depends $dep"
600 if [ -n "$VERBOSE" ]; then
601 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
602 fi
603 echo -n "$dep "
604 done
605 }
607 DEFAULT_DEPENDS="glibc-base"
609 # scan a package for shared libraries and display missing package in DEPENDS
610 check_depends_pkg()
611 {
612 pkg=$1
613 echo "(checking depends for $pkg)" > $DB_DIR/running
614 tmp=/tmp/tazbb$$
615 mkdir $tmp
616 package=$(basename $pkg)
617 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
618 cd $tmp
619 tazpkg extract $pkg > /dev/null 2>&1
620 fi
621 . */receipt
622 all_depends="$DEFAULT_DEPENDS "
623 scan_dep
624 toadd=$(find */fs -type f | while read file ; do
625 check_depends_file $file
626 done)
627 . */receipt
628 rm -rf */
629 cd - > /dev/null
630 rm -rf $tmp
631 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
632 }
634 check_depends_this_file()
635 {
636 file=$1
637 all_depends="$DEFAULT_DEPENDS "
638 scan_dep
639 check_depends_file $file
640 }
642 # Remove old packages in the build wok and clean pkgs repository. The
643 # Hg wok is copied into the build wok so packages removed by hg must be
644 # removed. To remove old packages in the repository we look into the
645 # build wok and dont remove unbuilt packages. Clean-up will also remove
646 # all corrupted packages.
647 clean_up()
648 {
649 touch $DB_DIR/removed
650 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
651 echo "(cleaning)" > $DB_DIR/running
652 for pkg in `ls $BUILD_WOK`
653 do
654 if [ ! -d $HG_WOK/$pkg ]; then
655 case $2 in
656 --dry-run)
657 echo "Removing directory : $pkg" ;;
658 --verbose)
659 echo "Removing directory : $pkg"
660 rm -rf $BUILD_WOK/$pkg ;;
661 *)
662 rm -rf $BUILD_WOK/$pkg ;;
663 esac
664 fi
665 done
666 # Build a packages list with EXTRAVERSION so we can grep into it.
667 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
668 for receipt in $BUILD_WOK/*/taz/*/receipt
669 do
670 EXTRAVERSION=""
671 . $receipt
672 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
673 done
674 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
675 do
676 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
677 case $2 in
678 --dry-run)
679 echo "Removing package : $pkg" ;;
680 --verbose)
681 echo "Removing package : $pkg"
682 echo "$pkg" >> $DB_DIR/removed
683 rm -f $PACKAGES_REPOSITORY/$pkg ;;
684 *)
685 echo "$pkg" >> $DB_DIR/removed
686 rm -f $PACKAGES_REPOSITORY/$pkg ;;
687 esac
688 fi
689 done
690 # Remove all corrupted packages
691 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
692 do
693 case $2 in
694 --dry-run)
695 echo "Removing corrupted: $pkg" ;;
696 --verbose)
697 echo "Removing corrupted: $pkg"
698 echo "$pkg" >> $DB_DIR/removed
699 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
700 *)
701 echo "$pkg" >> $DB_DIR/removed
702 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
703 esac
704 done
705 echo ""
706 # Keep the 20 last removed packages list.
707 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
708 mv -f /tmp/removed.tail $DB_DIR/removed
709 # Clean packages stuff/ directory
710 echo -e "\nCleaning the build wok stuff/ directories...\n"
711 for pkg in `ls $BUILD_WOK`
712 do
713 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
714 cd $BUILD_WOK/$pkg
715 for file in `find stuff -type f`
716 do
717 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
718 echo "Removing: $pkg/$file"
719 rm $file
720 fi
721 done
722 fi
723 done
724 }
726 blocked_urls()
727 {
728 rm -f $DB_DIR/blocked.urls
729 for pkg in `cat $DB_DIR/blocked`
730 do
731 if [ -f $LOG_DIR/$pkg.log ]; then
732 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
733 $DB_DIR/blocked.urls
734 else
735 echo "$pkg" >> $DB_DIR/blocked.urls
736 fi
737 done
738 }
740 # 4k, not a meta or a get-* package and no files = buggy package
741 test_packages()
742 {
743 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
744 echo "================================================================================"
745 echo "(testing packages)" > $DB_DIR/running
746 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
747 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
748 do
749 tmp=/tmp/bb-test.$$
750 CATEGORY=""
751 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
752 mkdir -p $tmp && cd $tmp
753 cpio -i receipt >/dev/null 2>&1 < $pkg
754 . ./receipt
755 if [ "$CATEGORY" != "meta" ]; then
756 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
757 cpio -i fs.cpio.gz >/dev/null 2>&1 < $pkg
758 cpio -i fs.cpio.lzma >/dev/null 2>&1 < $pkg
759 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
760 echo "Missing filesystem `basename $pkg`"
761 if [ -f $LOG_DIR/$PACKAGE.log ];then
762 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
763 >> $DB_DIR/corrupted
764 else
765 echo "Missing filesystem `basename $pkg`" \
766 >> $DB_DIR/corrupted
767 fi
768 else
769 ( zcat fs.cpio.gz 2> /dev/null || \
770 unlzma -c fs.cpio.lzma ) | \
771 cpio -id >/dev/null 2>&1
772 files=`find fs -type f -o -type l`
773 if [ -z "$files" ]; then
774 echo "Empty filesystem `basename $pkg`"
775 if [ -f $LOG_DIR/$PACKAGE.log ]; then
776 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
777 >> $DB_DIR/corrupted
778 else
779 echo "Empty filesystem `basename $pkg`" \
780 >> $DB_DIR/corrupted
781 fi
782 fi
783 fi
784 fi
785 cd .. && rm -rf $tmp
786 fi
787 done
788 packages_summary_update
789 echo ""
790 }
792 # Generate flavor list
793 gen_flavor_list()
794 {
795 cd $PACKAGES_REPOSITORY
796 noheader=""
797 for i in *.flavor; do
798 tazlito show-flavor $i --brief $noheader
799 noheader="--noheader"
800 done > flavors.list
801 cd - > /dev/null
802 }
804 case "$1" in
805 list-pkgs)
806 # List last cooked packages.
807 list_packages ;;
808 report)
809 # Run in report mode. If an update is done we must cook-all to
810 # rebuild all updated packages.
811 [ "$2" == "--update" ] && update_wok $@ || echo ""
812 check_wok $@
813 check_flavors $@
814 test_packages $@
815 show_report ;;
816 cook)
817 # Cook, install and log a single package build.
818 if [ -z $2 ]; then
819 echo "Please specify a package on the command line."
820 rm -f $LOCK_FILE && exit 0
821 fi
822 pkg=$2
823 echo "Starting to cook and install: $pkg"
824 if ! cook_package $pkg; then
825 echo "Unable to install: $pkg"
826 fi ;;
827 cook-all)
828 # Update wok, gen report (with cooklist), cook all packages, test,
829 # clean, gen new report and lists.
830 update_wok $@
831 check_wok $@
832 cook_install
833 test_packages $@
834 check_flavors $@
835 pack_flavors
836 clean_up $@
837 check_wok $@
838 echo "(generating lists)" > $DB_DIR/running
839 tazwok gen-list --text
840 check_flavors $@
841 gen_flavor_list
842 echo "" ;;
843 cook-commit)
844 # Cook all packages affected by the last commits in the wok.
845 # Clean up is done only by cook-all to avoid rebuild of corrupted
846 # packages on each commit.
847 update_wok $@
848 check_commit
849 cook_install
850 test_packages $@
851 check_flavors $@
852 pack_flavors
853 check_wok $@
854 check_flavors $@
855 echo "(generating lists)" > $DB_DIR/running
856 tazwok gen-list --text
857 gen_flavor_list
858 echo "" ;;
859 block)
860 # Add a pkg name to the list of blocked packages.
861 echo ""
862 if grep -qs "^$2$" $DB_DIR/blocked; then
863 echo -e "$2 is already in the blocked packages list."
864 else
865 echo -n "Adding $2 to : $DB_DIR/blocked... "
866 echo "$2" >> $DB_DIR/blocked && echo "Done"
867 if grep -q "^$2$" $DB_DIR/cooklist; then
868 echo -n "Removing $2 from : $DB_DIR/cooklist... "
869 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
870 packages_summary_update
871 fi
872 fi
873 blocked_urls
874 echo "" ;;
875 unblock)
876 # Remove a pkg name from the list of blocked packages.
877 echo ""
878 if grep -qs "^$2$" $DB_DIR/blocked; then
879 echo -n "Removing $2 from : $DB_DIR/blocked... "
880 sed -i /"^$2$"/d $DB_DIR/blocked
881 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
882 echo -n "Adding $2 to : $DB_DIR/cooklist... "
883 echo "$2" >> $DB_DIR/cooklist && echo "Done"
884 packages_summary_update
885 else
886 echo -e "$2 is not in the blocked packages list."
887 fi
888 blocked_urls
889 echo "" ;;
890 test-pkgs)
891 # Start a test suite on all builded packages.
892 test_packages $@ ;;
893 test-suite)
894 # Start a test suite on all builded package and the wok using
895 # the great 'tazwok check'.
896 #
897 # test_packages > $LOG_DIR/test-suite.log
898 # tazwok check >> $LOG_DIR/test-suite.log
899 #
900 test_packages $@
901 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
902 mail)
903 # Tazbbmail Pythom script wrapper.
904 PACKAGE=$2
905 tazbbmail $PACKAGE ;;
906 clean-up)
907 # Remove old packages and generate new packages lists.
908 update_wok $@
909 clean_up $@
910 packages_summary_update
911 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
912 clean-log)
913 logs=`ls $LOG_DIR | wc -l`
914 echo -n "Cleaning: $LOG_DIR... "
915 rm -rf $LOG_DIR/*
916 echo "$logs log removed" ;;
917 check-depends)
918 case "$2" in
919 wok)
920 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
921 missing_depends="$(check_depends_pkg $pkg)"
922 [ -n "$missing_depends" ] &&
923 echo "The package $pkg depends on $missing_depends."
924 done ;;
925 package)
926 pkg=$3
927 VERBOSE=$4
928 missing_depends="$(check_depends_pkg $pkg)"
929 [ -n "$missing_depends" ] &&
930 echo "The package $pkg depends on $missing_depends."
931 ;;
932 file)
933 file=3
934 VERBOSE=$4
935 missing_depends="$(check_depends_this_file $file)"
936 [ -n "$missing_depends" ] &&
937 echo "The file $file depends on $missing_depends."
938 ;;
939 *) cat <<EOT
940 check-depends wok check every package in wok.
941 check-depends package <pkg> check one package.
942 check-depends file <filename> check one file only.
943 EOT
944 ;;
945 esac ;;
946 *)
947 usage ;;
948 esac
950 echo "" > $DB_DIR/running
951 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
953 exit 0