cookutils view cooker @ rev 390

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