wok view tazbb/stuff/tazbb @ rev 6053

tazbb: break toolchain recompilations
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 17 15:27:28 2010 +0200 (2010-08-17)
parents 7040bf60917f
children e91159c0d814
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 for pkg in $HG_WOK/*
291 do
292 EXTRAVERSION=""
293 WANTED=""
294 BUILD_DEPENDS=""
295 [ -s $pkg/receipt ] || continue
296 . $pkg/receipt
297 [ "$2" = "--verbose" ] && echo "Package : $PACKAGE"
298 # Skip blocked packages.
299 if grep -qs "^$PACKAGE$" $DB_DIR/blocked; then
300 echo "Blocked : $PACKAGE ($VERSION)" && continue
301 fi
303 # Some packages may compute VERSION at cook time (bristuff)
304 if grep -q ^get_version $pkg/receipt; then
305 . $BUILD_WOK/$PACKAGE/taz/*/receipt
306 fi
308 # First check if package exit. Package naming _must_ be in the form of:
309 # $PACKAGE-$VERSION or $PACKAGE-${VERSION}$EXTRAVERSION (Kernel string).
310 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg ]; then
311 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
312 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg ]; then
313 [ "$1" = "report" ] && echo "Missing : $PACKAGE ($VERSION)"
314 echo "Missing : $PACKAGE ($VERSION)" >> $DB_DIR/report
315 echo "$PACKAGE" >> $DB_DIR/cooklist
316 fi
317 else
318 # Check if package is up-to-date.
319 PKG_YEAR=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%Y'`
320 PKG_DATE=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%m%d%H%M'`
321 for file in `find $pkg -type f`
322 do
323 FILE_YEAR=`date -u -r $file '+%Y'`
324 FILE_DATE=`date -u -r $file '+%m%d%H%M'`
325 [ "$2" = "--verbose" ] && echo " -> Checking: $file"
326 if [ "$FILE_YEAR" -ge "$PKG_YEAR" -a "$FILE_DATE" -gt "$PKG_DATE" ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
327 [ "$1" = "report" ] && echo "Refresh : $PACKAGE ($VERSION)"
328 echo "Refresh : $PACKAGE ($VERSION)" >> $DB_DIR/report
329 echo "$PACKAGE" >> $DB_DIR/cooklist
330 fi
331 done
332 fi
333 # Now check if package is built and not already in the list.
334 if [ ! -d $BUILD_WOK/$PACKAGE/taz ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
335 [ "$1" = "report" ] && echo "Unbuilt : $PACKAGE ($VERSION)"
336 echo "Unbuilt : $PACKAGE ($VERSION)" >> $DB_DIR/report
337 echo "$PACKAGE" >> $DB_DIR/cooklist
338 fi
339 if ! grep -q $PACKAGE $DB_DIR/cooklist; then
340 case " $TOOLCHAIN " in
341 *\ $PACKAGE\ *) continue;;
342 esac
343 for dep in $BUILD_DEPENDS $TOOLCHAIN ; do
344 [ $BUILD_WOK/$PACKAGE/taz -nt $BUILD_WOK/$dep/taz ] && continue
345 [ "$1" = "report" ] && echo "Refresh : $PACKAGE (older than $dep)"
346 echo "Refresh : $PACKAGE (older than $dep)" >> $DB_DIR/report
347 echo "$PACKAGE" >> $DB_DIR/cooklist
348 break
349 done
350 fi
351 # Rebuild unbuilt packages list with link to log file. This list
352 # is also generated by cook_inslall to have real time stats.
353 if [ ! -d $BUILD_WOK/$PACKAGE/taz ]; then
354 echo "<a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">$PACKAGE</a>" \
355 >> $DB_DIR/unbuilt
356 fi
357 done
358 packages_summary
359 }
361 # Create a new cooklist and summary (dont modify report) so 'tazbb cook-commit'
362 # can cook last changes.
363 check_commit()
364 {
365 echo "(checking commit)" > $DB_DIR/running
366 cd $HG_WOK
367 # Clean up last results.
368 rm -f $DB_DIR/cooklist && touch $DB_DIR/cooklist
369 # Get the name of modified packages by the revision range. +1 last
370 # commit was build by the previous build.
371 LAST_REV=$(($LAST_REV+1))
372 echo -e "Will cook from revision $LAST_REV to $NEW_REV\n"
373 for file in `hg log --rev=$LAST_REV:$NEW_REV --template '{files}\n'`
374 do
375 pkg=`echo $file | cut -d "/" -f 1`
376 if ! grep -q ^$pkg$ $DB_DIR/cooklist; then
377 . $pkg/receipt
378 echo "Commit : $PACKAGE ($VERSION)" >> $DB_DIR/report
379 echo "$PACKAGE" >> $DB_DIR/cooklist
380 fi
381 done
382 packages_summary
383 }
385 # Cook one package
386 cook_package()
387 {
388 EXTRAVERSION=""
389 DEPENDS=""
390 BUILD_DEPENDS=""
391 SOURCE=""
392 WANTED=""
393 echo "(cooking <a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>)" > $DB_DIR/running
394 tazwok clean $pkg
395 script -c "echo 'install' | tazwok cook $pkg" $LOG_DIR/$pkg.log
396 # Install new package (important for new shared libs). Note
397 # that tests are done separatly with 'test_packages' and should
398 # be done by tazwok.
399 if [ -f $BUILD_WOK/$pkg/taz/*/receipt ]; then
400 TAZBB_NO_INSTALL=""
401 . $BUILD_WOK/$pkg/taz/*/receipt
402 [ -n "$TAZBB_NO_INSTALL" ] && return 0
403 echo "(installing $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg)" \
404 > $DB_DIR/running
405 yes | tazpkg install \
406 $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg \
407 --forced
408 return 0
409 fi
410 return 1
411 }
413 # Sort list according WANTED and BUILD_DEPENDS
414 sort_cook_list()
415 {
416 sort | while read pkg; do
417 echo -n "$pkg"
418 WANTED=""
419 BUILD_DEPENDS=""
420 . $BUILD_WOK/$pkg/receipt
421 MISSING=""
422 for i in $WANTED $BUILD_DEPENDS ; do
423 if [ ! -f $BUILD_WOK/$i/taz/*/receipt ]; then
424 case " $MISSING " in
425 *\ $i\ *);;
426 *) echo -n " $i";;
427 esac
428 MISSING="$MISSING $i"
429 fi
430 done
431 echo ""
432 done | awk '
433 function show(name)
434 {
435 print name;
436 got[name]++;
437 if (revdepcnt[name] > 0)
438 for (i = split(revdep[name], pkg, " "); i > 0; i--)
439 if (--depcnt[pkg[i]] == 0) show(pkg[i]);
440 }
442 {
443 if ($2 == "") show($1);
444 else {
445 depcnt[$1] = NF - 1;
446 unres = unres " " $1;
447 for (i = 2; i <= NF; i++) {
448 if (got[$i] > 0) continue;
449 revdepcnt[$i]++;
450 revdep[$i] = revdep[$i] " " $1;
451 }
452 }
453 }
454 END {
455 for (i = split(unres, pkg, " "); i > 0; i--)
456 if (depcnt[pkg[i]] > 0) print pkg[i];
457 }
458 '
459 }
461 # Here we cook all packages found in the cooklist.
462 cook_install()
463 {
464 echo "" > $DB_DIR/unbuilt
465 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
466 do
467 if ! cook_package $pkg; then
468 # Link to build log.
469 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
470 $DB_DIR/unbuilt
471 fi
472 missing_depends="$(check_depends_pkg $pkg)"
473 if [ -n "$missing_depends" ]; then
474 cat >> $LOG_DIR/$pkg.log <<EOT
476 Update $pkg receipt for DEPENDS :
477 The package $pkg depends on packages $missing_depends
479 EOT
480 # Unbuild package
481 rm -rf $BUILD_WOK/$pkg/taz
482 # Link to build log.
483 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
484 $DB_DIR/unbuilt
485 fi
486 # Remove package from the cooklist and empty lines for HTML <pre>.
487 sed -i /"^$pkg$"/d $DB_DIR/cooklist
488 sed -i '/^$/d' $DB_DIR/cooklist
489 packages_summary_update
490 done
491 }
493 # Build depends_to_skip list with packages to remove from depends_to_add list
494 # These packages are already present in depends_to_add trees
495 scan_depends_to_skip()
496 {
497 local i
498 case " $depends_to_skip " in
499 *\ $1\ *) return;;
500 esac
501 [ -d $BUILD_WOK/$1 ] || return
502 DEPENDS=""
503 . $BUILD_WOK/$1/receipt
504 for i in $DEPENDS ; do
505 case " $depends_to_add " in
506 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
507 esac
508 done
509 for i in $DEPENDS ; do
510 scan_depends_to_skip $i
511 done
512 }
514 # Reduce depends list by scanning nested depends
515 show_missing_depends()
516 {
517 local i
518 depends_to_add=""
519 depends_to_skip="$2"
520 for i in $1 ; do
521 case " $depends_to_add " in
522 *\ $i\ *) continue;;
523 esac
524 depends_to_add="$depends_to_add$i "
525 done
526 for i in $depends_to_add ; do
527 scan_depends_to_skip $i
528 done
529 for i in $depends_to_add ; do
530 case " $depends_to_skip " in
531 *\ $i\ *) continue;;
532 esac
533 echo -n "$i "
534 done
535 }
537 # Build all_depends variable
538 scan_dep()
539 {
540 local i
541 all_depends="$all_depends$PACKAGE "
542 for i in $DEPENDS $SUGGESTED ; do
543 case " $all_depends " in
544 *\ $i\ *) continue;;
545 esac
546 [ -d $BUILD_WOK/$i ] || {
547 all_depends="$all_depends$i "
548 continue
549 }
550 DEPENDS=""
551 SUGGESTED=""
552 . $BUILD_WOK/$i/receipt
553 scan_dep
554 done
555 }
557 # Check for ELF file
558 is_elf()
559 {
560 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
561 }
563 # Print shared library dependencies
564 ldd()
565 {
566 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
567 }
569 # scan a file for shared libraries and display according package names
570 check_depends_file()
571 {
572 file=$1
573 is_elf $file || continue
574 case "$file" in
575 *.o|*.ko|*.ko.gz) continue;;
576 esac
577 [ -s /tmp/files.list.tazbb$$ ] ||
578 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
579 ldd $file | while read lib rem; do
580 case "$lib" in
581 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
582 continue;;
583 esac
584 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
585 case " $all_depends " in
586 *\ $dep\ *) continue 2;;
587 esac
588 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
589 case " $all_depends " in
590 *\ $vdep\ *) continue 3;;
591 esac
592 done
593 done
594 [ -n "$dep" ] || dep="UNKNOWN"
595 all_depends="$all_depends $dep"
596 if [ -n "$VERBOSE" ]; then
597 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
598 fi
599 echo -n "$dep "
600 done
601 }
603 DEFAULT_DEPENDS="glibc-base"
605 # scan a package for shared libraries and display missing package in DEPENDS
606 check_depends_pkg()
607 {
608 pkg=$1
609 echo "(checking depends for $pkg)" > $DB_DIR/running
610 tmp=/tmp/tazbb$$
611 mkdir $tmp
612 package=$(basename $pkg)
613 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
614 cd $tmp
615 tazpkg extract $pkg > /dev/null 2>&1
616 fi
617 . */receipt
618 all_depends="$DEFAULT_DEPENDS "
619 scan_dep
620 toadd=$(find */fs -type f | while read file ; do
621 check_depends_file $file
622 done)
623 . */receipt
624 rm -rf */
625 cd - > /dev/null
626 rm -rf $tmp
627 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
628 }
630 check_depends_this_file()
631 {
632 file=$1
633 all_depends="$DEFAULT_DEPENDS "
634 scan_dep
635 check_depends_file $file
636 }
638 # Remove old packages in the build wok and clean pkgs repository. The
639 # Hg wok is copied into the build wok so packages removed by hg must be
640 # removed. To remove old packages in the repository we look into the
641 # build wok and dont remove unbuilt packages. Clean-up will also remove
642 # all corrupted packages.
643 clean_up()
644 {
645 touch $DB_DIR/removed
646 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
647 echo "(cleaning)" > $DB_DIR/running
648 for pkg in `ls $BUILD_WOK`
649 do
650 if [ ! -d $HG_WOK/$pkg ]; then
651 case $2 in
652 --dry-run)
653 echo "Removing directory : $pkg" ;;
654 --verbose)
655 echo "Removing directory : $pkg"
656 rm -rf $BUILD_WOK/$pkg ;;
657 *)
658 rm -rf $BUILD_WOK/$pkg ;;
659 esac
660 fi
661 done
662 # Build a packages list with EXTRAVERSION so we can grep into it.
663 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
664 for receipt in $BUILD_WOK/*/taz/*/receipt
665 do
666 EXTRAVERSION=""
667 . $receipt
668 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
669 done
670 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
671 do
672 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
673 case $2 in
674 --dry-run)
675 echo "Removing package : $pkg" ;;
676 --verbose)
677 echo "Removing package : $pkg"
678 echo "$pkg" >> $DB_DIR/removed
679 rm -f $PACKAGES_REPOSITORY/$pkg ;;
680 *)
681 echo "$pkg" >> $DB_DIR/removed
682 rm -f $PACKAGES_REPOSITORY/$pkg ;;
683 esac
684 fi
685 done
686 # Remove all corrupted packages
687 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
688 do
689 case $2 in
690 --dry-run)
691 echo "Removing corrupted: $pkg" ;;
692 --verbose)
693 echo "Removing corrupted: $pkg"
694 echo "$pkg" >> $DB_DIR/removed
695 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
696 *)
697 echo "$pkg" >> $DB_DIR/removed
698 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
699 esac
700 done
701 echo ""
702 # Keep the 20 last removed packages list.
703 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
704 mv -f /tmp/removed.tail $DB_DIR/removed
705 # Clean packages stuff/ directory
706 echo -e "\nCleaning the build wok stuff/ directories...\n"
707 for pkg in `ls $BUILD_WOK`
708 do
709 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
710 cd $BUILD_WOK/$pkg
711 for file in `find stuff -type f`
712 do
713 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
714 echo "Removing: $pkg/$file"
715 rm $file
716 fi
717 done
718 fi
719 done
720 }
722 blocked_urls()
723 {
724 rm -f $DB_DIR/blocked.urls
725 for pkg in `cat $DB_DIR/blocked`
726 do
727 if [ -f $LOG_DIR/$pkg.log ]; then
728 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
729 $DB_DIR/blocked.urls
730 else
731 echo "$pkg" >> $DB_DIR/blocked.urls
732 fi
733 done
734 }
736 # 4k, not a meta or a get-* package and no files = buggy package
737 test_packages()
738 {
739 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
740 echo "================================================================================"
741 echo "(testing packages)" > $DB_DIR/running
742 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
743 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
744 do
745 tmp=/tmp/bb-test.$$
746 CATEGORY=""
747 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
748 mkdir -p $tmp && cd $tmp
749 cpio -i receipt >/dev/null 2>&1 < $pkg
750 . ./receipt
751 if [ "$CATEGORY" != "meta" ]; then
752 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
753 cpio -i fs.cpio.gz >/dev/null 2>&1 < $pkg
754 cpio -i fs.cpio.lzma >/dev/null 2>&1 < $pkg
755 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
756 echo "Missing filesystem `basename $pkg`"
757 if [ -f $LOG_DIR/$PACKAGE.log ];then
758 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
759 >> $DB_DIR/corrupted
760 else
761 echo "Missing filesystem `basename $pkg`" \
762 >> $DB_DIR/corrupted
763 fi
764 else
765 ( zcat fs.cpio.gz 2> /dev/null || \
766 unlzma -c fs.cpio.lzma ) | \
767 cpio -id >/dev/null 2>&1
768 files=`find fs -type f -o -type l`
769 if [ -z "$files" ]; then
770 echo "Empty filesystem `basename $pkg`"
771 if [ -f $LOG_DIR/$PACKAGE.log ]; then
772 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
773 >> $DB_DIR/corrupted
774 else
775 echo "Empty filesystem `basename $pkg`" \
776 >> $DB_DIR/corrupted
777 fi
778 fi
779 fi
780 fi
781 cd .. && rm -rf $tmp
782 fi
783 done
784 packages_summary_update
785 echo ""
786 }
788 # Generate flavor list
789 gen_flavor_list()
790 {
791 cd $PACKAGES_REPOSITORY
792 noheader=""
793 for i in *.flavor; do
794 tazlito show-flavor $i --brief $noheader
795 noheader="--noheader"
796 done > flavors.list
797 cd - > /dev/null
798 }
800 case "$1" in
801 list-pkgs)
802 # List last cooked packages.
803 list_packages ;;
804 report)
805 # Run in report mode. If an update is done we must cook-all to
806 # rebuild all updated packages.
807 [ "$2" == "--update" ] && update_wok $@ || echo ""
808 check_wok $@
809 check_flavors $@
810 test_packages $@
811 show_report ;;
812 cook)
813 # Cook, install and log a single package build.
814 if [ -z $2 ]; then
815 echo "Please specify a package on the command line."
816 rm -f $LOCK_FILE && exit 0
817 fi
818 pkg=$2
819 echo "Starting to cook and install: $pkg"
820 if ! cook_package $pkg; then
821 echo "Unable to install: $pkg"
822 fi ;;
823 cook-all)
824 # Update wok, gen report (with cooklist), cook all packages, test,
825 # clean, gen new report and lists.
826 update_wok $@
827 check_wok $@
828 cook_install
829 test_packages $@
830 check_flavors $@
831 pack_flavors
832 clean_up $@
833 check_wok $@
834 echo "(generating lists)" > $DB_DIR/running
835 tazwok gen-list --text
836 check_flavors $@
837 gen_flavor_list
838 echo "" ;;
839 cook-commit)
840 # Cook all packages affected by the last commits in the wok.
841 # Clean up is done only by cook-all to avoid rebuild of corrupted
842 # packages on each commit.
843 update_wok $@
844 check_commit
845 cook_install
846 test_packages $@
847 check_flavors $@
848 pack_flavors
849 check_wok $@
850 check_flavors $@
851 echo "(generating lists)" > $DB_DIR/running
852 tazwok gen-list --text
853 gen_flavor_list
854 echo "" ;;
855 block)
856 # Add a pkg name to the list of blocked packages.
857 echo ""
858 if grep -qs "^$2$" $DB_DIR/blocked; then
859 echo -e "$2 is already in the blocked packages list."
860 else
861 echo -n "Adding $2 to : $DB_DIR/blocked... "
862 echo "$2" >> $DB_DIR/blocked && echo "Done"
863 if grep -q "^$2$" $DB_DIR/cooklist; then
864 echo -n "Removing $2 from : $DB_DIR/cooklist... "
865 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
866 packages_summary_update
867 fi
868 fi
869 blocked_urls
870 echo "" ;;
871 unblock)
872 # Remove a pkg name from the list of blocked packages.
873 echo ""
874 if grep -qs "^$2$" $DB_DIR/blocked; then
875 echo -n "Removing $2 from : $DB_DIR/blocked... "
876 sed -i /"^$2$"/d $DB_DIR/blocked
877 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
878 echo -n "Adding $2 to : $DB_DIR/cooklist... "
879 echo "$2" >> $DB_DIR/cooklist && echo "Done"
880 packages_summary_update
881 else
882 echo -e "$2 is not in the blocked packages list."
883 fi
884 blocked_urls
885 echo "" ;;
886 test-pkgs)
887 # Start a test suite on all builded packages.
888 test_packages $@ ;;
889 test-suite)
890 # Start a test suite on all builded package and the wok using
891 # the great 'tazwok check'.
892 #
893 # test_packages > $LOG_DIR/test-suite.log
894 # tazwok check >> $LOG_DIR/test-suite.log
895 #
896 test_packages $@
897 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
898 mail)
899 # Tazbbmail Pythom script wrapper.
900 PACKAGE=$2
901 tazbbmail $PACKAGE ;;
902 clean-up)
903 # Remove old packages and generate new packages lists.
904 update_wok $@
905 clean_up $@
906 packages_summary_update
907 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
908 clean-log)
909 logs=`ls $LOG_DIR | wc -l`
910 echo -n "Cleaning: $LOG_DIR... "
911 rm -rf $LOG_DIR/*
912 echo "$logs log removed" ;;
913 check-depends)
914 case "$2" in
915 wok)
916 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
917 missing_depends="$(check_depends_pkg $pkg)"
918 [ -n "$missing_depends" ] &&
919 echo "The package $pkg depends on $missing_depends."
920 done ;;
921 package)
922 pkg=$3
923 VERBOSE=$4
924 missing_depends="$(check_depends_pkg $pkg)"
925 [ -n "$missing_depends" ] &&
926 echo "The package $pkg depends on $missing_depends."
927 ;;
928 file)
929 file=3
930 VERBOSE=$4
931 missing_depends="$(check_depends_this_file $file)"
932 [ -n "$missing_depends" ] &&
933 echo "The file $file depends on $missing_depends."
934 ;;
935 *) cat <<EOT
936 check-depends wok check every package in wok.
937 check-depends package <pkg> check one package.
938 check-depends file <filename> check one file only.
939 EOT
940 ;;
941 esac ;;
942 *)
943 usage ;;
944 esac
946 echo "" > $DB_DIR/running
947 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
949 exit 0