cookutils view cooker @ rev 410

More x86_64 support and show custom configure args in logs
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 14 11:39:33 2012 +0200 (2012-05-14)
parents f91214807ed8
children 71450d322f7b
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 echo "# Run SliTaz Cooker every $hours hours" > $crontabs
299 echo "0 */$hours * * * /usr/bin/cooker" >> $crontabs
300 /etc/init.d/crond start
301 fi
302 if ! fgrep -q /usr/bin/cooker $crontabs; then
303 echo "# Run SliTaz Cooker every $hours hours" > $crontabs
304 echo "0 */$hours * * * /usr/bin/cooker" >> $crontabs
305 killall crond 2>/dev/null && /etc/init.d/crond start
306 fi ;;
307 check-cron)
308 fgrep /usr/bin/cooker $crontabs ;;
309 note|-n)
310 # Blocked a pkg and want others to know why ? Post a note!
311 note="$2"
312 date=$(date "+%Y-%m-%d %H:%M")
313 [ "$note" ] && echo "$date : $note" >> $cooknotes ;;
314 notes|-ns)
315 # View cooknotes.
316 echo -e "\nCooknotes"
317 separator
318 cat $cooknotes
319 separator && echo "" ;;
320 block|-b)
321 # Block a package.
322 [ "$pkg" ] && cook $pkg --block ;;
323 unblock|-ub)
324 # Unblock a package.
325 [ "$pkg" ] && cook $pkg --unblock ;;
326 reverse|-r)
327 # Cook all reverse dependencies for a package. This command lets us
328 # control the Cooker manually for commits that will cook a lot of packages.
329 #
330 # Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:reverse"
331 #
332 [ ! -d "$wok/$pkg" ] && echo -e "\nNo package $2 found.\n" && exit 0
333 rm -f $cooklist && touch $cooklist && cd $wok
334 echo -e "\nReverse cooklist for: $pkg"
335 separator && cd $wok
336 for rev in *
337 do
338 unset WANTED DEPENDS BUILD_DEPENDS && . $wok/$rev/receipt
339 if echo "$WANTED $DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then
340 echo "$rev" | tee -a $cooklist
341 fi
342 done && separator
343 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n"
344 strip_blocked
345 cook_order | tee $LOGS/cookorder.log
346 cook_list ;;
347 pkg|-p)
348 # Same as 'cook pkg' but with log for web interface.
349 cook $pkg || broken
350 clean_exit ;;
351 cat|-c)
352 # Cook all packages of a category.
353 cat="$2"
354 rm -f $cooklist && touch $cooklist && cd $wok
355 for pkg in *
356 do
357 unset CATEGORY && . $pkg/receipt
358 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
359 done
360 strip_blocked
361 cook_order | tee $LOGS/cookorder.log
362 cook_list ;;
363 flavor|-f)
364 # Cook all packages of a flavor.
365 name="$2"
366 [ ! -d "$flavors/$name" ] && \
367 echo -e "\nSpecified flavor does not exist: $name\n" && exit 1
368 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
369 list=$flavors/$name/packages.list
370 cp -a $list $cooklist
371 strip_blocked
372 cook_order | tee $LOGS/cookorder.log
373 cook_list ;;
374 list|-l)
375 # Cook a list of packages given in argument.
376 list="$2"
377 [ ! -f "$list" ] && \
378 echo -e "\nSpecified list does not exist: $list\n" && exit 1
379 cp -a $list $cooklist
380 strip_blocked
381 cook_order | tee $LOGS/cookorder.log
382 cook_list ;;
383 rev|-r)
384 # Cook or recook a specific Hg revision.
385 rev="$2"
386 [ "$rev" ] || exit 0
387 cd $wok
388 rm -f $cooklist && touch $cooklist
389 for pkg in $(hg log --rev=$rev --template "{files}")
390 do
391 echo "$pkg" | cut -d "/" -f 1 >> $cooklist
392 done
393 strip_blocked
394 cook_order | tee $LOGS/cookorder.log
395 cook_list ;;
396 all|-a)
397 # Try to build all unbuilt packages except blocked's.
398 echo "cooker:all" > $command
399 rm -f $cooklist && touch $cooklist
400 echo "" && cd $wok
401 echo "Cooker cooklist"
402 separator
404 # Find all unbuilt packages. Get EXTRAVERSION from packed receipt
405 # if it exists since extra version is added when packing the package.
406 echo "Searching for all unbuilt packages" | log
407 for pkg in *
408 do
409 unset EXTRAVERSION
410 . $pkg/receipt
411 [ -f "$pkg/taz/$PACKAGE-$VERSION/receipt" ] && \
412 . $pkg/taz/$PACKAGE-$VERSION/receipt
413 if [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]
414 then
415 echo $pkg && echo $pkg >> $cooklist
416 fi
417 done
418 strip_blocked
419 cook_order | tee $LOGS/cookorder.log
420 echo "Packages to cook: $(cat $cooklist | wc -l)" | log
421 cook_list ;;
422 *)
423 # Default is to cook all commits if not yet running.
424 [ "$1" ] && usage
425 cooklist=$CACHE/commits
426 if [ -f "$pidfile" ]; then
427 pid=$(cat /var/run/cooker.pid)
428 if [ -s /proc/$pid/status ]; then
429 gettext -e "\nStill cooking latest commits with pid:"
430 echo -e " $pid\n" && exit 0
431 fi
432 rm -f "$pidfile"
433 fi
435 # Start and get a PID file.
436 rm -f $LOGS/commits.log
437 echo ""
438 echo "Checking for commits" | log_commits
439 separator | tee -a $LOGS/commits.log
441 echo $$ > $pidfile
442 trap 'echo -e "\nCooker stopped: PID $$\n" && \
443 rm -f $pidfile $command && exit 1' INT TERM
445 echo "Cooker PID : $$" | log_commits
446 echo "Cooker date : $(date '+%Y-%m-%d %H:%M:%S')" | log_commits
448 # Get revisions. Here we have 2 echoes since we want a msg on screen,
449 # in commits log and activity DB without a space before.
450 cd $wok || exit 1
451 cur=$(hg head --template '{rev}\n')
452 echo "Updating wok : ${wok}-hg (rev $cur)" | log_commits
453 echo "Updating wok: ${wok}-hg" | log
454 echo "hg:pull" > $command
455 cd ${wok}-hg && hg pull -u | log_commits
456 new=$(hg head --template '{rev}\n')
457 # Store last rev to be used by CGI so it doesn't need to call hg head
458 # on each load.
459 echo "$new" > $CACHE/wokrev
461 # Sync build wok with rsync so we don't take care about removing old
462 # files as before.
463 if [ "$new" -gt "$cur" ]; then
464 echo "Changes found from: $cur to $new" | log
465 echo "Syncing build wok with Hg wok..." | log_commits
466 rsync -r -t -c -l -u -v -D -E ${wok}-hg/ $wok/ | \
467 sed '/^$/'d | log_commits
468 else
469 echo "No revision changes: $cur vs $new" | log
470 separator | log_commits
471 clean_exit && echo "" && exit 0
472 fi
474 # Get and display modifications.
475 cd ${wok}-hg
476 commits_summary | log_commits
477 cur=$(($cur + 1))
478 rm -f $commits.tmp && touch $commits.tmp
479 for rev in $(seq $cur $new)
480 do
481 for file in $(hg log --rev=$rev --template "{files}")
482 do
483 pkg=$(echo $file | cut -d "/" -f 1)
484 desc=$(hg log --rev=$rev --template "{desc}" $file)
485 echo "Committed package : $pkg - $desc" | log_commits
486 echo $pkg >> $commits.tmp
487 done
488 done
490 # We may have deleted packages and files in stuff/. Remove it and
491 # clean DB as well as log file.
492 cd $wok
493 for pkg in *
494 do
495 if [ ! -d "${wok}-hg/$pkg" ]; then
496 echo "Removing package: $pkg" | log_commits
497 . $wok/$pkg/receipt
498 rm -rf $PKGS/$PACKAGE-$VERSION* $wok/$pkg $LOGS/$pkg.log
499 sed -i "/^${pkg}$/"d $CACHE/blocked $CACHE/broken $commits.tmp
500 fi
501 done
503 # Keep previous commit and discard duplicate lines
504 cat $commits $commits.tmp | sed /"^$"/d > $commits.new
505 uniq $commits.new > $commits && rm $commits.*
507 # Handle cross compilation. Create arch packages DB and remove pkgs
508 # not cooked for this arch from the commits list.
509 case "$ARCH" in
510 arm)
511 arch_db | log_commits
512 for pkg in $(cat $commits)
513 do
514 if [ ! -f "$wok/$pkg/arch.$ARCH" ]; then
515 echo "Cooker arch : skip $pkg (not included in: $ARCH)" | \
516 log_commits
517 sed -i "/^${pkg}$/"d $commits
518 fi
519 done ;;
520 i486)
521 echo "Cooker arch : $ARCH (default)" | log_commits ;;
522 *)
523 echo "Cooker arch : $ARCH" | log_commits ;;
524 esac
526 # Stats
527 pkgs=$(cat $commits | wc -l)
528 echo "Packages to cook: $pkgs" | log
529 echo "Packages to cook : $pkgs" | log_commits
530 separator | log_commits
531 echo ""
532 strip_blocked
533 cook_order | tee $LOGS/cookorder.log
534 cook_commits
535 clean_exit ;;
536 esac
538 exit 0