cookutils annotate cooker @ rev 942

cooker: explain usage, improve cook order to be used with split v1 & v2, add tasks support.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Jun 25 14:14:30 2017 +0300 (2017-06-25)
parents 9b8a08ce85c9
children 48b237fbb760
rev   line source
pankso@4 1 #!/bin/sh
pankso@4 2 #
pankso@383 3 # SliTaz Build Bot. The Cooker is a tool to automate and test SliTaz package
pankso@383 4 # building. Please read the Cookbook documentation for more information
paul@54 5 # and discuss with the AUTHORS before adding anything here. PS: no translations
paul@495 6 # here since it's not an end user tool and it's not useful. All devs should
pankso@4 7 # at least understand basic English.
pankso@4 8 #
al@728 9
pankso@431 10 . /usr/lib/slitaz/libcook.sh
pankso@4 11
pankso@49 12 # Set pkg name and use same wok as cook.
pankso@49 13 pkg="$2"
pankso@4 14 wok="$WOK"
pankso@4 15
pankso@81 16 # PID file.
pankso@81 17 pidfile='/var/run/cooker.pid'
pankso@81 18
pankso@4 19 #
pankso@4 20 # Functions
pankso@4 21 #
pankso@4 22
pankso@4 23 usage() {
al@728 24 cat <<EOT
pankso@4 25
al@942 26 Usage: cooker [<command>] [<options>]
pankso@4 27
al@942 28 Commands with <options>:
al@942 29 -u | usage Display this short usage.
al@942 30 -s | setup Setup the Cooker environment.
al@942 31 setup-cron [<hours>] Setup a cron job for the Cooker.
al@942 32 check-cron Check Cooker cron job.
al@942 33 arch-db Create host arch packages DB.
al@942 34 -n | note <note_text> Add a note to the cooknotes.
al@942 35 -ns | notes Display all the cooknotes.
al@942 36 -b | block <package> Block a package so cook will skip it.
al@942 37 -ub | unblock <package> Unblock a blocked package.
al@942 38 -R | reverse <package> Cook all reverse dependencies for a package.
al@942 39 -p | pkg <package> Same as 'cook pkg' but with cooker log.
al@942 40 -f | flavor <flavor_name> Cook all packages of a flavor.
al@942 41 -l | list <list_file> Cook all packages in the given list.
al@942 42 -c | cat <category> Cook all packages of a category.
al@942 43 -r | rev <rev_number> Cook packages of a specific revision.
al@942 44 -a | all Find and cook all unbuilt packages.
al@942 45 -T | tasks List existing cooker tasks.
al@942 46 -t | task <task> Executing specified task.
pankso@4 47
pankso@4 48 EOT
pankso@4 49 exit 0
pankso@4 50 }
pankso@4 51
al@728 52
paul@54 53 # Some messages occur in activity but log verbose output when checking for commits
pankso@14 54 # into a log file.
al@728 55
pankso@14 56 log_commits() {
al@931 57 sed '/^.\//d' | sed '/^.hg/d' | tee -a $LOGS/commits.log
pankso@14 58 }
pankso@14 59
al@728 60
pankso@81 61 # Clean up before exit when check and cook commits finish.
al@728 62
pankso@81 63 clean_exit() {
al@728 64 rm -f $command; touch $command
pascal@766 65 [ "$previous_command" ] && ps | grep -q "${previous_command/:/ }" &&
pascal@766 66 echo -n "$previous_command" > $command
pankso@81 67 rm -f $pidfile
pankso@14 68 }
pankso@14 69
al@728 70
pankso@35 71 # Summary for commits.
al@728 72
pankso@35 73 commits_summary() {
pankso@35 74 msg="from revision $cur to $new"
pankso@35 75 [ "$new" == "$cur" ] && msg="revision $new"
pankso@35 76 echo "Will cook $msg"
pankso@35 77 separator
al@942 78 title "Summary for commits"
pankso@35 79 echo "Hg wok revision : $cur"
pankso@35 80 echo "Pulled revision : $new"
al@728 81 echo "Check date : $(date '+%F %T')"
pankso@35 82 }
pankso@35 83
al@728 84
al@942 85 # Return all the names of packages bundled in this receipt
al@942 86
al@942 87 all_names() {
al@942 88 local split=" $SPLIT "
al@942 89 unset SPLIT
al@942 90 . $wok/$pkg/receipt
al@942 91
al@942 92 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
al@942 93 # For receipts v1: $SPLIT may present in the $WANTED package,
al@942 94 # but split packages have their own receipts
al@942 95 echo $PACKAGE
al@942 96 elif [ "${split/ $PACKAGE /}" != "$split" ]; then
al@942 97 echo $SPLIT
al@942 98 else
al@942 99 echo $PACKAGE $SPLIT
al@942 100 fi
al@942 101 }
al@942 102
al@942 103
paul@54 104 # Scan packages build deps and fill up cookorder list.
al@728 105
pankso@4 106 cook_order_scan() {
al@942 107 rm -f $cookorder $cookorder.split
al@942 108 touch $cookorder $cookorder.split
al@942 109
al@942 110 # Make combined split table: beginning from actual information with fresh
al@942 111 # commits. Example:
al@942 112 # freetype freetype freetype-dev
al@942 113 # harfbuzz harfbuzz harfbuzz-apps harfbuzz-dev
al@942 114 while read pkg; do
al@942 115 echo "$pkg $(all_names)" >> $cookorder.split
al@942 116 done < $cooklist
al@942 117 cat $cache/split.db >> $cookorder.split
al@942 118
al@942 119 maxlen=$(wc -L < $cooklist)
al@942 120
al@931 121 while read pkg; do
pascal@273 122 unset WANTED BUILD_DEPENDS
pankso@14 123 . $wok/$pkg/receipt
al@942 124 bdeps=$(
al@942 125 # Substitite each package of BUILD_DEPENDS list by the "main"
al@942 126 # receipt which builds this package. Example:
al@942 127 # BUILD_DEPENDS="freetype-dev harfbuzz-dev" -> bdeps="freetype harfbuzz"
al@942 128 for i in $BUILD_DEPENDS; do
al@942 129 main="$(awk -F$'\t' -vi="$i" '{
al@942 130 if (index(" " $2 " ", i)) {print $1; exit}
al@942 131 }' $cookorder.split)"
al@942 132 echo ${main:-$i}
al@942 133 done
al@942 134 )
pankso@29 135 # The :: is for web interface color.
al@942 136 bdeps=$(echo $WANTED $bdeps | tr '\n' ' ')
al@942 137 printf "%-${maxlen}s :: %s\n" "$pkg" "$bdeps"
al@942 138 for dep in $bdeps; do
pankso@4 139 if grep -q "^$dep$" $cooklist; then
pankso@4 140 if ! grep -q "^$dep$" $cookorder; then
pankso@4 141 echo "$dep" >> $cookorder
pankso@4 142 fi
pankso@4 143 fi
pankso@4 144 done
al@931 145 done < $cooklist
pankso@383 146
paul@54 147 # Append unordered packages to cookorder.
al@931 148 while read pkg; do
pankso@4 149 if ! grep -q "^$pkg$" $cookorder; then
pankso@4 150 echo "$pkg" >> $cookorder
pankso@4 151 fi
al@931 152 done < $cooklist
pankso@4 153 }
pankso@4 154
al@728 155
paul@54 156 # Scan and rescan until the cooklist is ordered then handle WANTED.
al@728 157
pankso@4 158 cook_order() {
pankso@4 159 time=$(date +%s)
pankso@4 160 scan=0
al@942 161 rm -rf $cache/cookorder.d
al@942 162 mkdir -p $cache/cookorder.d
pankso@4 163
pankso@4 164 # Keep an original cooklist so we do a diff when ordering is finished.
pankso@4 165 cp -f $cooklist $cooklist.0
al@728 166 echo 'cookorder' > $command
al@942 167 title 'Initial Cooker order scan'
pankso@4 168 cook_order_scan
pankso@383 169
pankso@4 170 # Diff between the cooklist and new ordered list ? So copy the last
pankso@4 171 # cookorder to cooklist and rescan it.
al@728 172 while /bin/true; do
al@942 173 if ! cmp -s $cooklist $cookorder; then
pankso@4 174 scan=$(($scan + 1))
al@942 175 title "Diff scan: $scan"
al@942 176
al@942 177 md5stamp=$(md5sum $cookorder | cut -d' ' -f1)
al@942 178 if [ -e "$cache/cookorder.d/$md5stamp" ]; then
al@942 179 newline
al@942 180 echo 'A dependency loop was detected. Interrupting the cookorder.'
al@942 181 break
al@942 182 fi
al@942 183 touch $cache/cookorder.d/$md5stamp
al@942 184
pankso@4 185 mv -f $cookorder $cooklist
pankso@4 186 cook_order_scan
al@942 187
pankso@4 188 else
pankso@4 189 break
pankso@4 190 fi
pankso@4 191 done
al@942 192 # Clean
al@942 193 rm -rf $cache/cookorder.d; rm $cookorder.split
pankso@4 194
paul@647 195 # Keep a diff between submitted cooklist and the ordered.
pankso@4 196 diff $cooklist.0 $cooklist > $cooklist.diff
al@942 197 rm -f $cookorder $cooklist.0
pankso@4 198
pankso@107 199 # Scan finished: append pkg to WANTED or leave it in the ordered cooklist.
paul@214 200 # TODO: grep the line number to get pkg position and keep it higher.
al@942 201 title 'Handle WANTED package'
al@931 202 while read pkg; do
pankso@4 203 unset WANTED
pankso@14 204 . $wok/$pkg/receipt
al@728 205 for wanted in $WANTED; do
pascal@291 206 echo "$pkg :: $wanted"
pascal@291 207 if grep -q ^${wanted}$ $cooklist; then
al@931 208 sed -i -e "/^$pkg$/d" \
pascal@291 209 -e "/^$wanted$/ a $pkg" $cooklist
pankso@107 210 fi
pascal@291 211 done
al@931 212 done < $cooklist
pankso@4 213
pankso@4 214 # Show ordered cooklist
al@942 215 title 'Cooklist order'
pankso@4 216 cat $cooklist
pankso@4 217 separator
al@728 218
pankso@4 219 time=$(($(date +%s) - $time))
al@931 220 pkgs=$(wc -l < $cooklist)
al@942 221 title 'Summary for cookorder'
al@728 222 cat <<EOT
pankso@4 223 Ordered packages : $pkgs
pankso@4 224 Scans executed : $scan
pankso@4 225 Scan duration : ${time}s
pankso@4 226 EOT
al@728 227 separator
al@728 228
al@728 229 rm -f $command
pankso@4 230 }
pankso@4 231
al@728 232
pankso@14 233 # Remove blocked (faster this way than grepping before).
al@728 234
pankso@14 235 strip_blocked() {
al@931 236 while read pkg; do
al@931 237 sed -i "/^${pkg}$/d" $cooklist
al@931 238 done < $blocked
al@931 239 sed -i '/^$/d' $cooklist
pankso@14 240 }
pankso@14 241
al@728 242
paul@54 243 # Use in default mode and with all cmd.
al@728 244
pankso@4 245 cook_commits() {
pankso@4 246 if [ -s "$commits" ]; then
al@931 247 while read pkg; do
pascal@765 248 ps | grep -q "cook $pkg$" && continue
pankso@14 249 echo "cook:$pkg" > $command
pankso@394 250 cook $pkg || broken
al@931 251 sed -i "/^${pkg}$/d" $commits
al@931 252 done < $commits
pankso@4 253 fi
pankso@4 254 }
pankso@4 255
al@728 256
paul@54 257 # Cook all packages in a cooklist.
al@728 258
pankso@14 259 cook_list() {
al@931 260 while read pkg; do
pascal@765 261 ps | grep -q "cook $pkg$" && continue
pankso@79 262 cook $pkg || broken
al@931 263 sed -i "/^${pkg}$/d" $cooklist
al@931 264 done < $cooklist
pankso@14 265 }
pankso@14 266
al@728 267
paul@388 268 # Create a arch.$ARCH file for each package cooked for the target host
pankso@383 269 # architecture
pankso@383 270 #
al@931 271 # The deal: we don't want all packages handled by cooker commands and stats,
al@931 272 # since we don't cross compile all packages for each arch but only a set of
paul@388 273 # packages to provide one full featured desktop, servers and goodies useful
pankso@383 274 # for the host system.
pankso@383 275 #
al@728 276
pankso@383 277 arch_db() {
pankso@383 278 count=0
pankso@391 279 echo "Cleaning packages DB : arch.$ARCH"
pankso@390 280 rm -f $wok/*/arch.$ARCH && cd $wok
pankso@383 281 echo "Creating $ARCH packages DB..."
al@728 282 for pkg in *; do
pascal@800 283 [ -s $wok/$pkg/receipt ] || continue
pascal@693 284 HOST_ARCH=
pascal@693 285 . $wok/$pkg/receipt
pascal@693 286 if [ -n "$HOST_ARCH" ]; then
pankso@678 287 if $(echo "$HOST_ARCH" | egrep -q "$ARCH|any"); then
pankso@678 288 count=$(($count + 1))
pankso@678 289 echo "Adding: $pkg"
pankso@678 290 touch $pkg/arch.$ARCH
pankso@678 291 fi
pankso@678 292 unset HOST_ARCH
pankso@678 293 else
pankso@678 294 # HOST_ARCH not set --> in i486
al@728 295 if [ "$ARCH" == 'i486' ]; then
pankso@678 296 count=$(($count + 1))
pankso@678 297 echo "Adding: $pkg"
pankso@678 298 touch $pkg/arch.$ARCH
pankso@678 299 fi
pankso@383 300 fi
pankso@383 301 done
pankso@391 302 echo "Packages for $ARCH : $count"
pankso@383 303 }
pankso@383 304
al@728 305
pankso@4 306 #
pankso@4 307 # Commands
pankso@4 308 #
al@728 309
al@933 310 previous_command="$(cat $command 2>/dev/null)"
pankso@4 311 case "$1" in
pankso@31 312 usage|help|-u|-h)
pankso@4 313 usage ;;
al@728 314
pankso@31 315 setup|-s)
pankso@4 316 # Setup the Cooker environment.
al@942 317 title 'Setting up the Cooker'
pankso@349 318 mkdir -p $CACHE
pankso@31 319 echo "Cooker setup using: $SLITAZ" | log
al@728 320 for pkg in $SETUP_PKGS mercurial rsync tazlito; do
pankso@4 321 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
pankso@4 322 done
pankso@4 323 mkdir -p $SLITAZ && cd $SLITAZ
al@728 324 if [ -d "${wok}-hg" ]; then
al@728 325 echo -e 'Hg wok already exists.\n'
al@728 326 exit 1
al@728 327 fi
al@728 328 if [ -d "$wok" ]; then
al@728 329 echo -e 'Build wok already exists.\n'
al@728 330 exit 1
al@728 331 fi
pankso@4 332
pankso@4 333 # Directories and files
pankso@4 334 echo "mkdir's and touch files in: $SLITAZ"
pankso@311 335 mkdir -p $PKGS $LOGS $FEEDS $CACHE $SRC
al@728 336 for f in $activity $blocked $broken $commits $cooklist $command; do
pankso@4 337 touch $f
pankso@4 338 done
pankso@14 339 hg clone $WOK_URL ${wok}-hg || exit 1
pankso@60 340 [ -d "$flavors" ] || hg clone $FLAVORS_URL flavors
pankso@4 341 cp -a ${wok}-hg $wok
al@942 342 footer ;;
al@728 343
pankso@383 344 arch-db)
pankso@383 345 # Manually create arch packages DB.
pankso@383 346 arch_db ;;
al@728 347
pankso@341 348 setup-cron)
pankso@341 349 # Create cron job for the cooker.
pankso@341 350 [ "$2" ] || hours=2
pankso@341 351 if [ ! -f "$crontabs" ]; then
pankso@341 352 mkdir -p /var/spool/cron/crontabs
pankso@341 353 fi
pankso@341 354 if ! fgrep -q /usr/bin/cooker $crontabs; then
al@931 355 cat > $crontabs <<EOT
pascal@760 356 # Run SliTaz Cooker every $hours hours
pascal@777 357 59 */$hours * * * touch $CACHE/cooker-request
pascal@760 358 */5 * * * * [ $CACHE/cooker-request -nt $CACHE/activity ] && /usr/bin/cooker --output=html
pascal@777 359 */5 * * * * [ -z "$(pidof cooker)" ] && [ -s $CACHE/recook-packages ] && /usr/bin/cooker list $CACHE/recook-packages
pascal@760 360 EOT
pascal@773 361 touch $CACHE/cooker-request $CACHE/recook-packages
pascal@773 362 chmod 666 $CACHE/cooker-request $CACHE/recook-packages
pankso@341 363 killall crond 2>/dev/null && /etc/init.d/crond start
pankso@341 364 fi ;;
al@728 365
pankso@341 366 check-cron)
al@728 367 if [ ! -f "$crontabs" ]; then
al@728 368 echo "There is no $crontabs here. Use setup-cron option."
al@728 369 exit 1
al@728 370 fi
pankso@341 371 fgrep /usr/bin/cooker $crontabs ;;
al@728 372
pankso@31 373 note|-n)
al@728 374 # Blocked a pkg and want others to know why? Post a note!
al@728 375 [ -n "$2" ] && echo "$(date '+%F %R') : $2" >> $cooknotes ;;
al@728 376
pankso@31 377 notes|-ns)
pankso@29 378 # View cooknotes.
al@942 379 title 'Cooknotes'
pankso@29 380 cat $cooknotes
al@942 381 footer ;;
al@728 382
pankso@49 383 block|-b)
pankso@49 384 # Block a package.
pankso@49 385 [ "$pkg" ] && cook $pkg --block ;;
al@728 386
pankso@49 387 unblock|-ub)
pankso@49 388 # Unblock a package.
pankso@49 389 [ "$pkg" ] && cook $pkg --unblock ;;
al@728 390
pankso@31 391 reverse|-r)
paul@54 392 # Cook all reverse dependencies for a package. This command lets us
paul@54 393 # control the Cooker manually for commits that will cook a lot of packages.
pankso@14 394 #
al@728 395 # Use hg commit? Ex: hg commit -m "Message bla bla | cooker:reverse"
pankso@14 396 #
al@728 397 if [ ! -d "$wok/$pkg" ]; then
al@728 398 echo -e "\nNo package $2 found.\n"
al@728 399 exit 0
al@728 400 fi
al@728 401 rm -f $cooklist; touch $cooklist
al@942 402 title "Reverse cooklist for: $pkg"
al@728 403
al@728 404 cd $wok
al@728 405 for rev in *; do
pascal@800 406 [ -s $wok/$rev/receipt ] || continue
al@728 407 unset WANTED DEPENDS BUILD_DEPENDS; . $wok/$rev/receipt
pascal@273 408 if echo "$WANTED $DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then
pankso@32 409 echo "$rev" | tee -a $cooklist
pankso@4 410 fi
al@728 411 done
al@942 412 footer "Reverse dependencies found: $(wc -l < $cooklist)"
pankso@32 413 strip_blocked
pankso@32 414 cook_order | tee $LOGS/cookorder.log
pankso@32 415 cook_list ;;
al@728 416
pankso@31 417 pkg|-p)
pankso@12 418 # Same as 'cook pkg' but with log for web interface.
pascal@765 419 ps | grep -q "cook $pkg$" && echo 'Already running' && continue
pankso@394 420 cook $pkg || broken
pankso@81 421 clean_exit ;;
al@728 422
pankso@31 423 cat|-c)
pankso@4 424 # Cook all packages of a category.
pankso@31 425 cat="$2"
al@728 426 rm -f $cooklist; touch $cooklist
al@728 427
al@728 428 cd $wok
al@728 429 for pkg in *; do
pascal@800 430 [ -s $pkg/receipt ] || continue
al@728 431 unset CATEGORY; . $pkg/receipt
pankso@4 432 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
pankso@4 433 done
pankso@14 434 strip_blocked
pankso@14 435 cook_order | tee $LOGS/cookorder.log
pankso@26 436 cook_list ;;
al@728 437
pankso@31 438 flavor|-f)
pankso@21 439 # Cook all packages of a flavor.
pankso@31 440 name="$2"
al@728 441 if [ ! -d "$flavors/$name" ]; then
al@728 442 echo -e "\nSpecified flavor does not exist: $name\n"
al@728 443 exit 1
al@728 444 fi
al@728 445 if [ -d "$flavors/.hg" ]; then
al@728 446 cd $flavors; hg pull -u
al@728 447 fi
al@728 448 list="$flavors/$name/packages.list"
pankso@21 449 cp -a $list $cooklist
pankso@21 450 strip_blocked
pankso@21 451 cook_order | tee $LOGS/cookorder.log
pankso@32 452 cook_list ;;
al@728 453
pankso@31 454 list|-l)
paul@54 455 # Cook a list of packages given in argument.
pankso@31 456 list="$2"
al@728 457 if [ ! -f "$list" ]; then
al@728 458 echo -e "\nSpecified list does not exist: $list\n"
al@728 459 exit 1
al@728 460 fi
pascal@774 461 cat $list >> $cooklist
pascal@774 462 echo -n > $list
pankso@26 463 strip_blocked
pankso@98 464 cook_order | tee $LOGS/cookorder.log
pankso@98 465 cook_list ;;
al@728 466
pankso@79 467 rev|-r)
pankso@79 468 # Cook or recook a specific Hg revision.
pankso@79 469 rev="$2"
pankso@79 470 [ "$rev" ] || exit 0
al@728 471 rm -f $cooklist; touch $cooklist
al@728 472
pankso@79 473 cd $wok
al@728 474 for pkg in $(hg log --rev=$rev --template "{files}"); do
al@728 475 echo "$pkg" | cut -d/ -f1 >> $cooklist
pankso@79 476 done
pankso@79 477 strip_blocked
pankso@26 478 cook_order | tee $LOGS/cookorder.log
pankso@26 479 cook_list ;;
al@728 480
pankso@31 481 all|-a)
pankso@4 482 # Try to build all unbuilt packages except blocked's.
al@728 483 echo 'cooker:all' > $command
al@728 484 rm -f $cooklist; touch $cooklist
al@942 485 title 'Cooker cooklist'
pankso@383 486
pankso@118 487 # Find all unbuilt packages. Get EXTRAVERSION from packed receipt
paul@132 488 # if it exists since extra version is added when packing the package.
al@728 489 echo 'Searching for all unbuilt packages' | log
al@728 490
al@728 491 cd $wok
al@728 492 for pkg in *; do
pascal@800 493 [ -s $pkg/receipt ] || continue
pankso@118 494 unset EXTRAVERSION
pankso@4 495 . $pkg/receipt
pankso@118 496 [ -f "$pkg/taz/$PACKAGE-$VERSION/receipt" ] && \
pankso@118 497 . $pkg/taz/$PACKAGE-$VERSION/receipt
al@728 498 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
al@728 499 echo $pkg; echo $pkg >> $cooklist
pankso@118 500 fi
pankso@4 501 done
pankso@14 502 strip_blocked
pankso@99 503 cook_order | tee $LOGS/cookorder.log
al@931 504 echo "Packages to cook: $(wc -l < $cooklist)" | log
pankso@79 505 cook_list ;;
al@728 506
al@942 507 tasks|-T)
al@942 508 # List existing cooker tasks
al@942 509 [ ! -d "$tasks" ] && echo 'There are no tasks.' && exit 0
al@942 510 title 'Cooker tasks list'
al@942 511 last=$(ls $tasks | tail -n1)
al@942 512 for task in $(ls $tasks); do
al@942 513 . $tasks/$task
al@942 514 echo "Task name : $task"
al@942 515 echo "Description : $DESC"
al@942 516 separator $([ $task != $last ] && echo '-')
al@942 517 done
al@942 518 newline ;;
al@942 519
al@942 520 task|-t)
al@942 521 # Executing specified task
al@942 522 task="$2"
al@942 523 title "Executing cooker task: $task"
al@942 524 . $tasks/$task; task
al@942 525 footer "Task $task finished" ;;
al@942 526
pankso@4 527 *)
pankso@81 528 # Default is to cook all commits if not yet running.
al@728 529 [ -n "$1" ] && usage
slaxemulator@489 530 cooklist=$commits
pankso@81 531 if [ -f "$pidfile" ]; then
slaxemulator@488 532 pid=$(cat $pidfile)
pascal@274 533 if [ -s /proc/$pid/status ]; then
al@728 534 echo -e "\nStill cooking latest commits with pid:"
al@728 535 echo -e " $pid\n"
al@728 536 exit 0
pascal@274 537 fi
pascal@274 538 rm -f "$pidfile"
pankso@81 539 fi
pankso@81 540
pankso@81 541 # Start and get a PID file.
pankso@14 542 rm -f $LOGS/commits.log
slaxemulator@486 543 newline
al@728 544 echo 'Checking for commits' | log_commits
pankso@14 545 separator | tee -a $LOGS/commits.log
pankso@383 546
pankso@82 547 echo $$ > $pidfile
pankso@233 548 trap 'echo -e "\nCooker stopped: PID $$\n" && \
pankso@233 549 rm -f $pidfile $command && exit 1' INT TERM
pankso@383 550
pankso@82 551 echo "Cooker PID : $$" | log_commits
al@728 552 echo "Cooker date : $(date '+%F %T')" | log_commits
pankso@383 553
paul@132 554 # Get revisions. Here we have 2 echoes since we want a msg on screen,
paul@132 555 # in commits log and activity DB without a space before.
pankso@60 556 cd $wok || exit 1
pankso@4 557 cur=$(hg head --template '{rev}\n')
pankso@82 558 echo "Updating wok : ${wok}-hg (rev $cur)" | log_commits
pankso@82 559 echo "Updating wok: ${wok}-hg" | log
al@728 560 echo 'hg:pull' > $command
al@728 561 cd $wok-hg; hg pull -u | log_commits
pankso@4 562 new=$(hg head --template '{rev}\n')
paul@168 563 # Store last rev to be used by CGI so it doesn't need to call hg head
pankso@164 564 # on each load.
slaxemulator@488 565 echo "$new" > $wokrev
pankso@383 566
paul@54 567 # Sync build wok with rsync so we don't take care about removing old
pankso@4 568 # files as before.
pankso@4 569 if [ "$new" -gt "$cur" ]; then
pankso@4 570 echo "Changes found from: $cur to $new" | log
al@728 571 echo 'Syncing build wok with Hg wok...' | log_commits
al@728 572 rsync -r -t -c -l -u -v -D -E $wok-hg/ $wok/ | \
al@931 573 sed '/^$/d' | log_commits
pankso@4 574 else
pankso@13 575 echo "No revision changes: $cur vs $new" | log
pankso@14 576 separator | log_commits
al@728 577 clean_exit; newline
al@728 578 exit 0
pankso@4 579 fi
pankso@383 580
pankso@35 581 # Get and display modifications.
al@728 582 cd $wok-hg
pankso@110 583 commits_summary | log_commits
pankso@14 584 cur=$(($cur + 1))
al@728 585 rm -f $commits.tmp; touch $commits.tmp
al@728 586 for rev in $(seq $cur $new); do
al@728 587 for file in $(hg log --rev=$rev --template "{files}"); do
al@728 588 pkg=$(echo $file | cut -d/ -f1)
pankso@36 589 desc=$(hg log --rev=$rev --template "{desc}" $file)
paul@388 590 echo "Committed package : $pkg - $desc" | log_commits
pankso@80 591 echo $pkg >> $commits.tmp
pankso@4 592 done
pankso@4 593 done
pankso@248 594
pankso@248 595 # We may have deleted packages and files in stuff/. Remove it and
pankso@248 596 # clean DB as well as log file.
pankso@248 597 cd $wok
al@728 598 for pkg in *; do
al@921 599 if [ ! -d "$wok-hg/$pkg" ]; then
pankso@248 600 echo "Removing package: $pkg" | log_commits
pascal@799 601 if [ -s $wok/$pkg/receipt ]; then
pascal@799 602 . $wok/$pkg/receipt
pascal@799 603 rm -f $PKGS/$PACKAGE-$VERSION*
pascal@799 604 fi
pascal@799 605 rm -rf $wok/$pkg $LOGS/$pkg.log
al@931 606 sed -i "/^${pkg}$/d" $blocked $broken $commits.tmp
pankso@248 607 fi
al@921 608 if [ -d "$wok/$pkg/stuff" ]; then
al@921 609 if [ ! -d "$wok-hg/$pkg/stuff" ]; then
al@921 610 echo "Removing stuff: $pkg/stuff" | log_commits
al@922 611 rm -rf $wok/$pkg/stuff
al@921 612 else
al@922 613 for stuff_file in $(cd $wok/$pkg/stuff; find \( -type f -o -type l \) | sed 's|^\./||'); do
al@921 614 if [ ! -f "$wok-hg/$pkg/stuff/$stuff_file" -a \
al@921 615 ! -h "$wok-hg/$pkg/stuff/$stuff_file" ]; then
al@921 616 echo "Removing file from stuff: $wok/$pkg/stuff/$stuff_file" | log_commits
al@922 617 rm -f $wok/$pkg/stuff/$stuff_file
al@922 618 rmdir --parents --ignore-fail-on-non-empty $(dirname "$wok/$pkg/stuff/$stuff_file")
al@921 619 fi
al@921 620 done
al@921 621 fi
al@921 622 fi
pankso@248 623 done
pankso@383 624
paul@54 625 # Keep previous commit and discard duplicate lines
al@931 626 cat $commits $commits.tmp | sed '/^$/d' > $commits.new
al@728 627 uniq $commits.new > $commits; rm $commits.*
pankso@383 628
paul@388 629 # Handle cross compilation. Create arch packages DB and remove pkgs
pankso@383 630 # not cooked for this arch from the commits list.
pankso@677 631 arch_db
al@931 632 while read pkg; do
pankso@677 633 if [ ! -f "$wok/$pkg/arch.$ARCH" ]; then
pankso@677 634 echo "Cooker arch : skip $pkg (not included in: $ARCH)" | \
pankso@677 635 log_commits
al@931 636 sed -i "/^${pkg}$/d" $commits
pankso@677 637 else
pankso@677 638 echo "Cooker arch : $ARCH" | log_commits
pankso@677 639 fi
al@931 640 done < $commits
al@728 641
pankso@383 642 # Stats
al@931 643 pkgs=$(wc -l < $commits)
pankso@100 644 echo "Packages to cook: $pkgs" | log
pankso@109 645 echo "Packages to cook : $pkgs" | log_commits
pankso@35 646 separator | log_commits
slaxemulator@486 647 newline
pankso@14 648 strip_blocked
pankso@14 649 cook_order | tee $LOGS/cookorder.log
pankso@81 650 cook_commits
pankso@81 651 clean_exit ;;
pankso@4 652 esac
pankso@4 653
pankso@4 654 exit 0