cookutils view cooker @ rev 425

cross: glibc --enable-kernel=2.6.32
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 19 23:40:17 2012 +0200 (2012-05-19)
parents 07b26101f8da
children d9b8c75bb5bb
line source
1 #!/bin/sh
2 #
3 # SliTaz Build Bot. The Cooker is a tool to automate and test SliTaz package
4 # building. Please read the Cookbook documentation for more information
5 # and discuss with the AUTHORS before adding anything here. PS: no translations
6 # here since it's not an end user tool and it's not useful, all devs should
7 # at least understand basic English.
8 #
10 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
11 [ -f "cook.conf" ] && . ./cook.conf
13 # Set pkg name and use same wok as cook.
14 pkg="$2"
15 wok="$WOK"
16 flavors="$SLITAZ/flavors"
18 # Cooker DB files.
19 activity="$CACHE/activity"
20 commits="$CACHE/commits"
21 cooklist="$CACHE/cooklist"
22 cookorder="$CACHE/cookorder"
23 command="$CACHE/command"
24 blocked="$CACHE/blocked"
25 broken="$CACHE/broken"
26 cooknotes="$CACHE/cooknotes"
27 crontabs="/var/spool/cron/crontabs/root"
29 # PID file.
30 pidfile='/var/run/cooker.pid'
32 #
33 # Functions
34 #
36 usage() {
37 cat << EOT
39 Usage: cooker [command] [pkg|list|note|hours]
41 Options:
42 usage|-u Display this short usage.
43 setup|-s Setup the Cooker environment.
44 setup-cron Setup a cron job for the Cooker.
45 arch-db Create host arch packages DB.
46 note|-n Add a note to the cooknotes.
47 notes|-ns Display all the cooknotes.
48 block|-b Block a package so cook will skip it.
49 unblock|-ub Unblock a blocked package.
50 pkg|-p Same as 'cook pkg' but with cooker log.
51 flavor|-f Cook all packages of a flavor.
52 list|-l Cook all packages in the given list.
53 cat|-c Cook all packages of a category.
54 rev|-r Cook packages of a specific revision.
55 all|-a Find and cook all unbuilt packages.
57 EOT
58 exit 0
59 }
61 separator() {
62 echo "================================================================================"
63 }
65 # Lograte activity.
66 [ -s "$activity" ] && tail -n 60 $activity > /tmp/tail && \
67 mv -f /tmp/tail $activity
69 # Log activities, we want first letter capitalized.
70 log() {
71 grep ^[A-Z] | \
72 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
73 }
75 # Some messages occur in activity but log verbose output when checking for commits
76 # into a log file.
77 log_commits() {
78 sed '/^.\//'d | sed '/^.hg/'d | tee -a $LOGS/commits.log
79 }
81 # Log broken packages.
82 broken() {
83 if ! grep -q "^$pkg$" $broken; then
84 echo "$pkg" >> $broken
85 fi
86 }
88 # Clean up before exit when check and cook commits finish.
89 clean_exit() {
90 rm -f $command && touch $command
91 rm -f $pidfile
92 }
94 # Summary for commits.
95 commits_summary() {
96 msg="from revision $cur to $new"
97 [ "$new" == "$cur" ] && msg="revision $new"
98 echo "Will cook $msg"
99 separator
100 echo -e "\nSummary for commits"
101 separator
102 echo "Hg wok revision : $cur"
103 echo "Pulled revision : $new"
104 echo "Check date : $(date '+%Y-%m-%d %H:%M:%S')"
105 }
107 # Scan packages build deps and fill up cookorder list.
108 cook_order_scan() {
109 rm -f $cookorder
110 touch $cookorder
111 for pkg in $(cat $cooklist)
112 do
113 unset WANTED BUILD_DEPENDS
114 . $wok/$pkg/receipt
115 # The :: is for web interface color.
116 [ "$WANTED$BUILD_DEPENDS" ] && echo "$pkg :: $WANTED $BUILD_DEPENDS"
117 for dep in $WANTED $BUILD_DEPENDS
118 do
119 if grep -q "^$dep$" $cooklist; then
120 if ! grep -q "^$dep$" $cookorder; then
121 echo "$dep" >> $cookorder
122 fi
123 fi
124 done
125 done
127 # Append unordered packages to cookorder.
128 for pkg in $(cat $cooklist)
129 do
130 if ! grep -q "^$pkg$" $cookorder; then
131 echo "$pkg" >> $cookorder
132 fi
133 done
134 }
136 # Scan and rescan until the cooklist is ordered then handle WANTED.
137 cook_order() {
138 time=$(date +%s)
139 scan=0
141 # Keep an original cooklist so we do a diff when ordering is finished.
142 cp -f $cooklist $cooklist.0
143 echo "cookorder" > $command
144 echo -e "\nInitial Cooker order scan"
145 separator
146 cook_order_scan
148 # Diff between the cooklist and new ordered list ? So copy the last
149 # cookorder to cooklist and rescan it.
150 while /bin/true
151 do
152 diff $cooklist $cookorder > $cookorder.diff
153 if [ -s "$cookorder.diff" ]; then
154 scan=$(($scan + 1))
155 echo -e "\nDiff scan: $scan"
156 separator
157 mv -f $cookorder $cooklist
158 cook_order_scan
159 else
160 break
161 fi
162 done
164 # Keep a diff between submited cooklist and the ordered.
165 diff $cooklist.0 $cooklist > $cooklist.diff
166 rm -f $cookorder $cookorder.diff $cooklist.0
168 # Scan finished: append pkg to WANTED or leave it in the ordered cooklist.
169 # TODO: grep the line number to get pkg position and keep it higher.
170 echo -e "\nHandle WANTED package"
171 separator
172 for pkg in $(cat $cooklist)
173 do
174 unset WANTED
175 . $wok/$pkg/receipt
176 for wanted in $WANTED
177 do
178 echo "$pkg :: $wanted"
179 if grep -q ^${wanted}$ $cooklist; then
180 sed -i -e "/^$pkg$/"d \
181 -e "/^$wanted$/ a $pkg" $cooklist
182 fi
183 done
184 done
186 # Show ordered cooklist
187 echo -e "\nCooklist order"
188 separator
189 cat $cooklist
190 separator
191 time=$(($(date +%s) - $time))
192 pkgs=$(cat $cooklist | wc -l)
193 echo -e "\nSummary for cookorder"
194 separator
195 cat << EOT
196 Ordered packages : $pkgs
197 Scans executed : $scan
198 Scan duration : ${time}s
199 EOT
200 separator && rm -f $command
201 }
203 # Remove blocked (faster this way than grepping before).
204 strip_blocked() {
205 for pkg in $(cat $blocked)
206 do
207 sed -i /^${pkg}$/d $cooklist
208 done && sed -i /^$/d $cooklist
209 }
211 # Use in default mode and with all cmd.
212 cook_commits() {
213 if [ -s "$commits" ]; then
214 for pkg in $(cat $commits)
215 do
216 echo "cook:$pkg" > $command
217 cook $pkg || broken
218 sed -i /^${pkg}$/d $commits
219 done
220 fi
221 }
223 # Cook all packages in a cooklist.
224 cook_list() {
225 for pkg in $(cat $cooklist)
226 do
227 cook $pkg || broken
228 sed -i /^${pkg}$/d $cooklist
229 done
230 }
232 # Create a arch.$ARCH file for each package cooked for the target host
233 # architecture
234 #
235 # The deal: we dont want all packages handled by cooker commands and stats,
236 # since we dont cross compile all packages for each arch but only a set of
237 # packages to provide one full featured desktop, servers and goodies useful
238 # for the host system.
239 #
240 arch_db() {
241 count=0
242 echo "Cleaning packages DB : arch.$ARCH"
243 rm -f $wok/*/arch.$ARCH && cd $wok
244 echo "Creating $ARCH packages DB..."
245 for pkg in *
246 do
247 unset HOST_ARCH
248 . $wok/$pkg/receipt
249 #: ${HOST_ARCH=i486}
250 if $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
251 count=$(($count + 1))
252 echo "Adding: $pkg"
253 touch $pkg/arch.$ARCH
254 fi
255 done
256 echo "Packages for $ARCH : $count"
257 }
259 #
260 # Commands
261 #
262 case "$1" in
263 usage|help|-u|-h)
264 usage ;;
265 setup|-s)
266 # Setup the Cooker environment.
267 echo -e "\nSetting up the Cooker"
268 mkdir -p $CACHE
269 echo "Cooker setup using: $SLITAZ" | log
270 separator
271 for pkg in $SETUP_PKGS mercurial rsync tazlito
272 do
273 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
274 done
275 mkdir -p $SLITAZ && cd $SLITAZ
276 [ -d "${wok}-hg" ] && echo -e "Hg wok already exists.\n" && exit 1
277 [ -d "$wok" ] && echo -e "Build wok already exists.\n" && exit 1
279 # Directories and files
280 echo "mkdir's and touch files in: $SLITAZ"
281 mkdir -p $PKGS $LOGS $FEEDS $CACHE $SRC
282 for f in $activity $blocked $broken $commits $cooklist $command
283 do
284 touch $f
285 done
286 hg clone $WOK_URL ${wok}-hg || exit 1
287 [ -d "$flavors" ] || hg clone $FLAVORS_URL flavors
288 cp -a ${wok}-hg $wok
289 separator && echo "" ;;
290 arch-db)
291 # Manually create arch packages DB.
292 arch_db ;;
293 setup-cron)
294 # Create cron job for the cooker.
295 [ "$2" ] || hours=2
296 if [ ! -f "$crontabs" ]; then
297 mkdir -p /var/spool/cron/crontabs
298 fi
299 if ! fgrep -q /usr/bin/cooker $crontabs; then
300 echo "# Run SliTaz Cooker every $hours hours" > $crontabs
301 echo "0 */$hours * * * /usr/bin/cooker --output=html" >> $crontabs
302 killall crond 2>/dev/null && /etc/init.d/crond start
303 fi ;;
304 check-cron)
305 fgrep /usr/bin/cooker $crontabs ;;
306 note|-n)
307 # Blocked a pkg and want others to know why ? Post a note!
308 note="$2"
309 date=$(date "+%Y-%m-%d %H:%M")
310 [ "$note" ] && echo "$date : $note" >> $cooknotes ;;
311 notes|-ns)
312 # View cooknotes.
313 echo -e "\nCooknotes"
314 separator
315 cat $cooknotes
316 separator && echo "" ;;
317 block|-b)
318 # Block a package.
319 [ "$pkg" ] && cook $pkg --block ;;
320 unblock|-ub)
321 # Unblock a package.
322 [ "$pkg" ] && cook $pkg --unblock ;;
323 reverse|-r)
324 # Cook all reverse dependencies for a package. This command lets us
325 # control the Cooker manually for commits that will cook a lot of packages.
326 #
327 # Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:reverse"
328 #
329 [ ! -d "$wok/$pkg" ] && echo -e "\nNo package $2 found.\n" && exit 0
330 rm -f $cooklist && touch $cooklist && cd $wok
331 echo -e "\nReverse cooklist for: $pkg"
332 separator && cd $wok
333 for rev in *
334 do
335 unset WANTED DEPENDS BUILD_DEPENDS && . $wok/$rev/receipt
336 if echo "$WANTED $DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then
337 echo "$rev" | tee -a $cooklist
338 fi
339 done && separator
340 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n"
341 strip_blocked
342 cook_order | tee $LOGS/cookorder.log
343 cook_list ;;
344 pkg|-p)
345 # Same as 'cook pkg' but with log for web interface.
346 cook $pkg || broken
347 clean_exit ;;
348 cat|-c)
349 # Cook all packages of a category.
350 cat="$2"
351 rm -f $cooklist && touch $cooklist && cd $wok
352 for pkg in *
353 do
354 unset CATEGORY && . $pkg/receipt
355 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
356 done
357 strip_blocked
358 cook_order | tee $LOGS/cookorder.log
359 cook_list ;;
360 flavor|-f)
361 # Cook all packages of a flavor.
362 name="$2"
363 [ ! -d "$flavors/$name" ] && \
364 echo -e "\nSpecified flavor does not exist: $name\n" && exit 1
365 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
366 list=$flavors/$name/packages.list
367 cp -a $list $cooklist
368 strip_blocked
369 cook_order | tee $LOGS/cookorder.log
370 cook_list ;;
371 list|-l)
372 # Cook a list of packages given in argument.
373 list="$2"
374 [ ! -f "$list" ] && \
375 echo -e "\nSpecified list does not exist: $list\n" && exit 1
376 cp -a $list $cooklist
377 strip_blocked
378 cook_order | tee $LOGS/cookorder.log
379 cook_list ;;
380 rev|-r)
381 # Cook or recook a specific Hg revision.
382 rev="$2"
383 [ "$rev" ] || exit 0
384 cd $wok
385 rm -f $cooklist && touch $cooklist
386 for pkg in $(hg log --rev=$rev --template "{files}")
387 do
388 echo "$pkg" | cut -d "/" -f 1 >> $cooklist
389 done
390 strip_blocked
391 cook_order | tee $LOGS/cookorder.log
392 cook_list ;;
393 all|-a)
394 # Try to build all unbuilt packages except blocked's.
395 echo "cooker:all" > $command
396 rm -f $cooklist && touch $cooklist
397 echo "" && cd $wok
398 echo "Cooker cooklist"
399 separator
401 # Find all unbuilt packages. Get EXTRAVERSION from packed receipt
402 # if it exists since extra version is added when packing the package.
403 echo "Searching for all unbuilt packages" | log
404 for pkg in *
405 do
406 unset EXTRAVERSION
407 . $pkg/receipt
408 [ -f "$pkg/taz/$PACKAGE-$VERSION/receipt" ] && \
409 . $pkg/taz/$PACKAGE-$VERSION/receipt
410 if [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]
411 then
412 echo $pkg && echo $pkg >> $cooklist
413 fi
414 done
415 strip_blocked
416 cook_order | tee $LOGS/cookorder.log
417 echo "Packages to cook: $(cat $cooklist | wc -l)" | log
418 cook_list ;;
419 *)
420 # Default is to cook all commits if not yet running.
421 [ "$1" ] && usage
422 cooklist=$CACHE/commits
423 if [ -f "$pidfile" ]; then
424 pid=$(cat /var/run/cooker.pid)
425 if [ -s /proc/$pid/status ]; then
426 gettext -e "\nStill cooking latest commits with pid:"
427 echo -e " $pid\n" && exit 0
428 fi
429 rm -f "$pidfile"
430 fi
432 # Start and get a PID file.
433 rm -f $LOGS/commits.log
434 echo ""
435 echo "Checking for commits" | log_commits
436 separator | tee -a $LOGS/commits.log
438 echo $$ > $pidfile
439 trap 'echo -e "\nCooker stopped: PID $$\n" && \
440 rm -f $pidfile $command && exit 1' INT TERM
442 echo "Cooker PID : $$" | log_commits
443 echo "Cooker date : $(date '+%Y-%m-%d %H:%M:%S')" | log_commits
445 # Get revisions. Here we have 2 echoes since we want a msg on screen,
446 # in commits log and activity DB without a space before.
447 cd $wok || exit 1
448 cur=$(hg head --template '{rev}\n')
449 echo "Updating wok : ${wok}-hg (rev $cur)" | log_commits
450 echo "Updating wok: ${wok}-hg" | log
451 echo "hg:pull" > $command
452 cd ${wok}-hg && hg pull -u | log_commits
453 new=$(hg head --template '{rev}\n')
454 # Store last rev to be used by CGI so it doesn't need to call hg head
455 # on each load.
456 echo "$new" > $CACHE/wokrev
458 # Sync build wok with rsync so we don't take care about removing old
459 # files as before.
460 if [ "$new" -gt "$cur" ]; then
461 echo "Changes found from: $cur to $new" | log
462 echo "Syncing build wok with Hg wok..." | log_commits
463 rsync -r -t -c -l -u -v -D -E ${wok}-hg/ $wok/ | \
464 sed '/^$/'d | log_commits
465 else
466 echo "No revision changes: $cur vs $new" | log
467 separator | log_commits
468 clean_exit && echo "" && exit 0
469 fi
471 # Get and display modifications.
472 cd ${wok}-hg
473 commits_summary | log_commits
474 cur=$(($cur + 1))
475 rm -f $commits.tmp && touch $commits.tmp
476 for rev in $(seq $cur $new)
477 do
478 for file in $(hg log --rev=$rev --template "{files}")
479 do
480 pkg=$(echo $file | cut -d "/" -f 1)
481 desc=$(hg log --rev=$rev --template "{desc}" $file)
482 echo "Committed package : $pkg - $desc" | log_commits
483 echo $pkg >> $commits.tmp
484 done
485 done
487 # We may have deleted packages and files in stuff/. Remove it and
488 # clean DB as well as log file.
489 cd $wok
490 for pkg in *
491 do
492 if [ ! -d "${wok}-hg/$pkg" ]; then
493 echo "Removing package: $pkg" | log_commits
494 . $wok/$pkg/receipt
495 rm -rf $PKGS/$PACKAGE-$VERSION* $wok/$pkg $LOGS/$pkg.log
496 sed -i "/^${pkg}$/"d $CACHE/blocked $CACHE/broken $commits.tmp
497 fi
498 done
500 # Keep previous commit and discard duplicate lines
501 cat $commits $commits.tmp | sed /"^$"/d > $commits.new
502 uniq $commits.new > $commits && rm $commits.*
504 # Handle cross compilation. Create arch packages DB and remove pkgs
505 # not cooked for this arch from the commits list.
506 case "$ARCH" in
507 arm)
508 arch_db | log_commits
509 for pkg in $(cat $commits)
510 do
511 if [ ! -f "$wok/$pkg/arch.$ARCH" ]; then
512 echo "Cooker arch : skip $pkg (not included in: $ARCH)" | \
513 log_commits
514 sed -i "/^${pkg}$/"d $commits
515 fi
516 done ;;
517 i486)
518 echo "Cooker arch : $ARCH (default)" | log_commits ;;
519 *)
520 echo "Cooker arch : $ARCH" | log_commits ;;
521 esac
523 # Stats
524 pkgs=$(cat $commits | wc -l)
525 echo "Packages to cook: $pkgs" | log
526 echo "Packages to cook : $pkgs" | log_commits
527 separator | log_commits
528 echo ""
529 strip_blocked
530 cook_order | tee $LOGS/cookorder.log
531 cook_commits
532 clean_exit ;;
533 esac
535 exit 0