cookutils view cooker @ rev 669

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