cookutils view cooker @ rev 260
cook: fix for set -e now ised for genpkg_rules (build fails if copying pixmaps fails)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Jun 02 04:38:46 2011 +0200 (2011-06-02) |
parents | d59cb7bee773 |
children | 89f254f33af3 |
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"
28 # PID file.
29 pidfile='/var/run/cooker.pid'
31 #
32 # Functions
33 #
35 usage() {
36 cat << EOT
38 Usage: cooker [command] [pkg|list|note]
40 Options:
41 usage|-u Display this short usage.
42 setup|-s Setup the Cooker environment.
43 note|-n Add a note to the cooknotes.
44 notes|-ns Display all the cooknotes.
45 block|-b Block a package so cook will skip it.
46 unblock|-ub Unblock a blocked package.
47 pkg|-p Same as 'cook pkg' but with cooker log.
48 flavor|-f Cook all packages of a flavor.
49 list|-l Cook all packages in the given list.
50 cat|-c Cook all packages of a category.
51 rev|-r Cook packages of a specific revision.
52 all|-a Find and cook all unbuilt packages.
54 EOT
55 exit 0
56 }
58 separator() {
59 echo "================================================================================"
60 }
62 # Lograte activity.
63 [ -s "$activity" ] && tail -n 60 $activity > /tmp/tail && \
64 mv -f /tmp/tail $activity
66 # Log activities, we want first letter capitalized.
67 log() {
68 grep ^[A-Z] | \
69 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
70 }
72 # Some messages occur in activity but log verbose output when checking for commits
73 # into a log file.
74 log_commits() {
75 sed '/^.\//'d | sed '/^.hg/'d | tee -a $LOGS/commits.log
76 }
78 # Log broken packages.
79 broken() {
80 if ! grep -q "^$pkg$" $broken; then
81 echo "$pkg" >> $broken
82 fi
83 }
85 # Clean up before exit when check and cook commits finish.
86 clean_exit() {
87 rm -f $command && touch $command
88 rm -f $pidfile
89 }
91 # Summary for commits.
92 commits_summary() {
93 msg="from revision $cur to $new"
94 [ "$new" == "$cur" ] && msg="revision $new"
95 echo "Will cook $msg"
96 separator
97 echo -e "\nSummary for commits"
98 separator
99 echo "Hg wok revision : $cur"
100 echo "Pulled revision : $new"
101 echo "Check date : $(date '+%Y-%m-%d %H:%M:%S')"
102 }
104 # Scan packages build deps and fill up cookorder list.
105 cook_order_scan() {
106 rm -f $cookorder
107 for pkg in $(cat $cooklist)
108 do
109 unset BUILD_DEPENDS
110 . $wok/$pkg/receipt
111 # The :: is for web interface color.
112 [ "$BUILD_DEPENDS" ] && echo "$pkg :: $BUILD_DEPENDS"
113 for dep in $BUILD_DEPENDS
114 do
115 if grep -q "^$dep$" $cooklist; then
116 if ! grep -q "^$dep$" $cookorder; then
117 echo "$dep" >> $cookorder
118 fi
119 fi
120 done
121 done
123 # Append unordered packages to cookorder.
124 for pkg in $(cat $cooklist)
125 do
126 if ! grep -q "^$pkg$" $cookorder; then
127 echo "$pkg" >> $cookorder
128 fi
129 done
130 }
132 # Scan and rescan until the cooklist is ordered then handle WANTED.
133 cook_order() {
134 time=$(date +%s)
135 scan=0
137 # Keep an original cooklist so we do a diff when ordering is finished.
138 cp -f $cooklist $cooklist.0
139 echo "cookorder" > $command
140 echo -e "\nInitial Cooker order scan"
141 separator
142 cook_order_scan
144 # Diff between the cooklist and new ordered list ? So copy the last
145 # cookorder to cooklist and rescan it.
146 while /bin/true
147 do
148 diff $cooklist $cookorder > $cookorder.diff
149 if [ -s "$cookorder.diff" ]; then
150 scan=$(($scan + 1))
151 echo -e "\nDiff scan: $scan"
152 separator
153 mv -f $cookorder $cooklist
154 cook_order_scan
155 else
156 break
157 fi
158 done
160 # Keep a diff between submited cooklist and the ordered.
161 diff $cooklist.0 $cooklist > $cooklist.diff
162 rm -f $cookorder $cookorder.diff $cooklist.0
164 # Scan finished: append pkg to WANTED or leave it in the ordered cooklist.
165 # TODO: grep the line number to get pkg position and keep it higher.
166 echo -e "\nHandle WANTED package"
167 separator
168 for pkg in $(cat $cooklist)
169 do
170 unset WANTED
171 . $wok/$pkg/receipt
172 if [ "$WANTED" ]; then
173 echo "$pkg :: $WANTED"
174 if grep -q ^${WANTED}$ $cooklist; then
175 sed -i -e "/^$pkg$/"d \
176 -e "/^$WANTED$/ a $pkg" $cooklist
177 fi
178 fi
179 done
181 # Show ordered cooklist
182 echo -e "\nCooklist order"
183 separator
184 cat $cooklist
185 separator
186 time=$(($(date +%s) - $time))
187 pkgs=$(cat $cooklist | wc -l)
188 echo -e "\nSummary for cookorder"
189 separator
190 cat << EOT
191 Ordered packages : $pkgs
192 Scans executed : $scan
193 Scan duration : ${time}s
194 EOT
195 separator && rm -f $command
196 }
198 # Remove blocked (faster this way than grepping before).
199 strip_blocked() {
200 for pkg in $(cat $blocked)
201 do
202 sed -i /^${pkg}$/d $cooklist
203 done && sed -i /^$/d $cooklist
204 }
206 # Use in default mode and with all cmd.
207 cook_commits() {
208 if [ -s "$commits" ]; then
209 for pkg in $(cat $commits)
210 do
211 echo "cook:$pkg" > $command
212 cook $pkg || broken
213 sed -i /^${pkg}$/d $commits
214 done
215 fi
216 }
218 # Cook all packages in a cooklist.
219 cook_list() {
220 for pkg in $(cat $cooklist)
221 do
222 cook $pkg || broken
223 sed -i /^${pkg}$/d $cooklist
224 done
225 }
227 #
228 # Commands
229 #
230 case "$1" in
231 usage|help|-u|-h)
232 usage ;;
233 setup|-s)
234 # Setup the Cooker environment.
235 echo -e "\nSetting up the Cooker"
236 echo "Cooker setup using: $SLITAZ" | log
237 separator
238 for pkg in $SETUP_PKGS mercurial rsync
239 do
240 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
241 done
242 mkdir -p $SLITAZ && cd $SLITAZ
243 [ -d "${wok}-hg" ] && echo -e "Hg wok already exists.\n" && exit 1
244 [ -d "$wok" ] && echo -e "Build wok already exists.\n" && exit 1
246 # Directories and files
247 echo "mkdir's and touch files in: $SLITAZ"
248 mkdir -p $PKGS $LOGS $CACHE $SRC
249 for f in $activity $blocked $broken $commits $cooklist $command
250 do
251 touch $f
252 done
253 hg clone $WOK_URL ${wok}-hg || exit 1
254 [ -d "$flavors" ] || hg clone $FLAVORS_URL flavors
255 cp -a ${wok}-hg $wok
256 separator && echo "" ;;
257 note|-n)
258 # Blocked a pkg and want others to know why ? Post a note!
259 note="$2"
260 date=$(date "+%Y-%m-%d %H:%M")
261 [ "$note" ] && echo "$date : $note" >> $cooknotes ;;
262 notes|-ns)
263 # View cooknotes.
264 echo -e "\nCooknotes"
265 separator
266 cat $cooknotes
267 separator && echo "" ;;
268 block|-b)
269 # Block a package.
270 [ "$pkg" ] && cook $pkg --block ;;
271 unblock|-ub)
272 # Unblock a package.
273 [ "$pkg" ] && cook $pkg --unblock ;;
274 reverse|-r)
275 # Cook all reverse dependencies for a package. This command lets us
276 # control the Cooker manually for commits that will cook a lot of packages.
277 #
278 # Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:reverse"
279 #
280 [ ! -d "$wok/$pkg" ] && echo -e "\nNo package $2 found.\n" && exit 0
281 rm -f $cooklist && touch $cooklist && cd $wok
282 echo -e "\nReverse cooklist for: $pkg"
283 separator && cd $wok
284 for rev in *
285 do
286 unset DEPENDS BUILD_DEPENDS && . $wok/$rev/receipt
287 if echo "$DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then
288 echo "$rev" | tee -a $cooklist
289 fi
290 done && separator
291 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n"
292 strip_blocked
293 cook_order | tee $LOGS/cookorder.log
294 cook_list ;;
295 pkg|-p)
296 # Same as 'cook pkg' but with log for web interface.
297 cook $pkg || broken
298 clean_exit ;;
299 cat|-c)
300 # Cook all packages of a category.
301 cat="$2"
302 rm -f $cooklist && touch $cooklist && cd $wok
303 for pkg in *
304 do
305 unset CATEGORY && . $pkg/receipt
306 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
307 done
308 strip_blocked
309 cook_order | tee $LOGS/cookorder.log
310 cook_list ;;
311 flavor|-f)
312 # Cook all packages of a flavor.
313 name="$2"
314 [ ! -d "$flavors/$name" ] && \
315 echo -e "\nSpecified flavor does not exist: $name\n" && exit 1
316 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
317 list=$flavors/$name/packages.list
318 cp -a $list $cooklist
319 strip_blocked
320 cook_order | tee $LOGS/cookorder.log
321 cook_list ;;
322 list|-l)
323 # Cook a list of packages given in argument.
324 list="$2"
325 [ ! -f "$list" ] && \
326 echo -e "\nSpecified list does not exist: $list\n" && exit 1
327 cp -a $list $cooklist
328 strip_blocked
329 cook_order | tee $LOGS/cookorder.log
330 cook_list ;;
331 rev|-r)
332 # Cook or recook a specific Hg revision.
333 rev="$2"
334 [ "$rev" ] || exit 0
335 cd $wok
336 rm -f $cooklist && touch $cooklist
337 for pkg in $(hg log --rev=$rev --template "{files}")
338 do
339 echo "$pkg" | cut -d "/" -f 1 >> $cooklist
340 done
341 strip_blocked
342 cook_order | tee $LOGS/cookorder.log
343 cook_list ;;
344 all|-a)
345 # Try to build all unbuilt packages except blocked's.
346 echo "cooker:all" > $command
347 rm -f $cooklist && touch $cooklist
348 echo "" && cd $wok
349 echo "Cooker cooklist"
350 separator
352 # Find all unbuilt packages. Get EXTRAVERSION from packed receipt
353 # if it exists since extra version is added when packing the package.
354 echo "Searching for all unbuilt packages" | log
355 for pkg in *
356 do
357 unset EXTRAVERSION
358 . $pkg/receipt
359 [ -f "$pkg/taz/$PACKAGE-$VERSION/receipt" ] && \
360 . $pkg/taz/$PACKAGE-$VERSION/receipt
361 if [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]
362 then
363 echo $pkg && echo $pkg >> $cooklist
364 fi
365 done
366 strip_blocked
367 cook_order | tee $LOGS/cookorder.log
368 echo "Packages to cook: $(cat $cooklist | wc -l)" | log
369 cook_list ;;
370 *)
371 # Default is to cook all commits if not yet running.
372 [ "$1" ] && usage
373 cooklist=$CACHE/commits
374 if [ -f "$pidfile" ]; then
375 pid=$(cat /var/run/cooker.pid)
376 gettext -e "\nStill cooking latest commits with pid:"
377 echo -e " $pid\n" && exit 0
378 fi
380 # Start and get a PID file.
381 rm -f $LOGS/commits.log
382 echo ""
383 echo "Checking for commits" | log_commits
384 separator | tee -a $LOGS/commits.log
386 echo $$ > $pidfile
387 trap 'echo -e "\nCooker stopped: PID $$\n" && \
388 rm -f $pidfile $command && exit 1' INT TERM
390 echo "Cooker PID : $$" | log_commits
391 echo "Cooker date : $(date '+%Y-%m-%d %H:%M:%S')" | log_commits
393 # Get revisions. Here we have 2 echoes since we want a msg on screen,
394 # in commits log and activity DB without a space before.
395 cd $wok || exit 1
396 cur=$(hg head --template '{rev}\n')
397 echo "Updating wok : ${wok}-hg (rev $cur)" | log_commits
398 echo "Updating wok: ${wok}-hg" | log
399 echo "hg:pull" > $command
400 cd ${wok}-hg && hg pull -u | log_commits
401 new=$(hg head --template '{rev}\n')
402 # Store last rev to be used by CGI so it doesn't need to call hg head
403 # on each load.
404 echo "$new" > $CACHE/wokrev
406 # Sync build wok with rsync so we don't take care about removing old
407 # files as before.
408 if [ "$new" -gt "$cur" ]; then
409 echo "Changes found from: $cur to $new" | log
410 echo "Syncing build wok with Hg wok..." | log_commits
411 rsync -r -t -c -l -u -v -D -E ${wok}-hg/ $wok/ | \
412 sed '/^$/'d | log_commits
413 else
414 echo "No revision changes: $cur vs $new" | log
415 separator | log_commits
416 clean_exit && echo "" && exit 0
417 fi
419 # Get and display modifications.
420 cd ${wok}-hg
421 commits_summary | log_commits
422 cur=$(($cur + 1))
423 rm -f $commits.tmp && touch $commits.tmp
424 for rev in $(seq $cur $new)
425 do
426 for file in $(hg log --rev=$rev --template "{files}")
427 do
428 pkg=$(echo $file | cut -d "/" -f 1)
429 desc=$(hg log --rev=$rev --template "{desc}" $file)
430 echo "Commited package : $pkg - $desc" | log_commits
431 echo $pkg >> $commits.tmp
432 done
433 done
435 # We may have deleted packages and files in stuff/. Remove it and
436 # clean DB as well as log file.
437 cd $wok
438 for pkg in *
439 do
440 if [ ! -d "${wok}-hg/$pkg" ]; then
441 echo "Removing package: $pkg" | log_commits
442 . $wok/$pkg/receipt
443 rm -rf $PKGS/$PACKAGE-$VERSION* $wok/$pkg $LOGS/$pkg.log
444 sed -i "/^${pkg}$/"d $CACHE/blocked $CACHE/broken $commits.tmp
445 fi
446 done
448 # Keep previous commit and discard duplicate lines
449 cat $commits $commits.tmp | sed /"^$"/d > $commits.new
450 uniq $commits.new > $commits && rm $commits.*
451 pkgs=$(cat $commits | wc -l)
452 echo "Packages to cook: $pkgs" | log
453 echo "Packages to cook : $pkgs" | log_commits
454 separator | log_commits
455 echo ""
456 strip_blocked
457 cook_order | tee $LOGS/cookorder.log
458 cook_commits
459 clean_exit ;;
460 esac
462 exit 0