cookutils annotate cooker @ rev 51
cook: fix blocked
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat May 07 05:41:58 2011 +0200 (2011-05-07) |
parents | 8df3646e9d8f |
children | 7cfa8aa2860a |
rev | line source |
---|---|
pankso@4 | 1 #!/bin/sh |
pankso@4 | 2 # |
pankso@4 | 3 # SliTaz Build Bot. The Cooker is a tool to automate and test SliTaz package |
pankso@4 | 4 # building. Please read the Cookbook documentation for more information |
pankso@4 | 5 # and put talk to AUTHORS before adding anything here. PS: no translation |
pankso@4 | 6 # here since it's not a end user tool and it's not usfull, all devs should |
pankso@4 | 7 # at least understand basic English. |
pankso@4 | 8 # |
pankso@4 | 9 |
pankso@4 | 10 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf |
pankso@4 | 11 [ -f "cook.conf" ] && . ./cook.conf |
pankso@4 | 12 |
pankso@49 | 13 # Set pkg name and use same wok as cook. |
pankso@49 | 14 pkg="$2" |
pankso@4 | 15 wok="$WOK" |
pankso@31 | 16 flavors="$SLITAZ/flavors" |
pankso@4 | 17 |
pankso@4 | 18 # Cooker DB files. |
pankso@4 | 19 activity="$CACHE/activity" |
pankso@4 | 20 commits="$CACHE/commits" |
pankso@4 | 21 cooklist="$CACHE/cooklist" |
pankso@4 | 22 cookorder="$CACHE/cookorder" |
pankso@14 | 23 command="$CACHE/command" |
pankso@4 | 24 blocked="$CACHE/blocked" |
pankso@4 | 25 broken="$CACHE/broken" |
pankso@22 | 26 cooknotes="$CACHE/cooknotes" |
pankso@4 | 27 |
pankso@4 | 28 # |
pankso@4 | 29 # Functions |
pankso@4 | 30 # |
pankso@4 | 31 |
pankso@4 | 32 usage() { |
pankso@4 | 33 cat << EOT |
pankso@4 | 34 |
pankso@31 | 35 Usage: cooker [command] [pkg|list|note] |
pankso@4 | 36 |
pankso@4 | 37 Options: |
pankso@49 | 38 usage|-u Display this short usage. |
pankso@49 | 39 setup|-s Setup the Cooker environment. |
pankso@49 | 40 note|-n Add a note to the cooknotes. |
pankso@49 | 41 notes|-ns Display all the cooknotes. |
pankso@49 | 42 block|-b Block a package so cook will skip it. |
pankso@49 | 43 unblock|-ub Unblock a blocked package. |
pankso@49 | 44 pkg|-p Same as 'cook pkg' but with cooker log. |
pankso@49 | 45 flavor|-f Cook all packages of a flavor. |
pankso@49 | 46 list|-l Cook all package in the given list. |
pankso@49 | 47 cat|-c Cook all packages of a category. |
pankso@49 | 48 all|-a Find and cook all unbuilt packages. |
pankso@4 | 49 |
pankso@4 | 50 EOT |
pankso@4 | 51 exit 0 |
pankso@4 | 52 } |
pankso@4 | 53 |
pankso@4 | 54 separator() { |
pankso@4 | 55 echo "================================================================================" |
pankso@4 | 56 } |
pankso@4 | 57 |
pankso@4 | 58 # Lograte activity. |
pankso@4 | 59 [ -s "$activity" ] && tail -n 20 $activity > /tmp/tail && \ |
pankso@4 | 60 mv -f /tmp/tail $activity |
pankso@4 | 61 |
pankso@13 | 62 # Log activities, we want first letter capitalized. |
pankso@4 | 63 log() { |
pankso@27 | 64 grep ^[A-Z] | \ |
pankso@4 | 65 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity |
pankso@4 | 66 } |
pankso@4 | 67 |
pankso@14 | 68 # Some message goes in activity but log verbose output when checking for commits |
pankso@14 | 69 # into a log file. |
pankso@14 | 70 log_commits() { |
pankso@35 | 71 sed '/^.\//'d | sed '/^.hg/'d | tee -a $LOGS/commits.log |
pankso@14 | 72 } |
pankso@14 | 73 |
pankso@4 | 74 # Log broken packages |
pankso@4 | 75 broken() { |
pankso@4 | 76 echo "$pkg" >> $broken |
pankso@4 | 77 } |
pankso@4 | 78 |
pankso@14 | 79 # Clean up after cook sucess. |
pankso@27 | 80 empty_command() { |
pankso@14 | 81 rm -f $command && touch $command |
pankso@14 | 82 } |
pankso@14 | 83 |
pankso@35 | 84 # Summary for commits. |
pankso@35 | 85 commits_summary() { |
pankso@35 | 86 msg="from revision $cur to $new" |
pankso@35 | 87 [ "$new" == "$cur" ] && msg="revision $new" |
pankso@35 | 88 echo "Will cook $msg" |
pankso@35 | 89 separator |
pankso@35 | 90 echo -e "\nSummary for commits" |
pankso@35 | 91 separator |
pankso@35 | 92 echo "Hg wok revision : $cur" |
pankso@35 | 93 echo "Pulled revision : $new" |
pankso@35 | 94 echo "Check date : $(date '+%Y-%m-%d %H:%M')" |
pankso@35 | 95 } |
pankso@35 | 96 |
pankso@29 | 97 # Scan packages build deps an fill up cookorder list. |
pankso@4 | 98 cook_order_scan() { |
pankso@4 | 99 touch $cooklist $cookorder |
pankso@4 | 100 for pkg in $(cat $cooklist) |
pankso@4 | 101 do |
pankso@29 | 102 unset BUILD_DEPENDS |
pankso@14 | 103 . $wok/$pkg/receipt |
pankso@29 | 104 # The :: is for web interface color. |
pankso@29 | 105 [ "$BUILD_DEPENDS" ] && echo "$pkg :: $BUILD_DEPENDS" |
pankso@29 | 106 for dep in $BUILD_DEPENDS |
pankso@4 | 107 do |
pankso@4 | 108 if grep -q "^$dep$" $cooklist; then |
pankso@4 | 109 if ! grep -q "^$dep$" $cookorder; then |
pankso@29 | 110 |
pankso@4 | 111 echo "$dep" >> $cookorder |
pankso@4 | 112 fi |
pankso@4 | 113 fi |
pankso@4 | 114 done |
pankso@4 | 115 done |
pankso@4 | 116 |
pankso@4 | 117 # Append unordered packages to cookored. |
pankso@4 | 118 for pkg in $(cat $cooklist) |
pankso@4 | 119 do |
pankso@4 | 120 if ! grep -q "^$pkg$" $cookorder; then |
pankso@4 | 121 echo "$pkg" >> $cookorder |
pankso@4 | 122 fi |
pankso@4 | 123 done |
pankso@4 | 124 } |
pankso@4 | 125 |
pankso@4 | 126 # Scan and rescan untill the cooklist is ordered then handle WANTED. |
pankso@4 | 127 cook_order() { |
pankso@4 | 128 time=$(date +%s) |
pankso@4 | 129 scan=0 |
pankso@4 | 130 |
pankso@4 | 131 # Keep an original cooklist so we do a diff when ordering is finished. |
pankso@4 | 132 cp -f $cooklist $cooklist.0 |
pankso@4 | 133 echo -e "\nInitial Cooker order scan" |
pankso@4 | 134 separator |
pankso@4 | 135 cook_order_scan |
pankso@4 | 136 |
pankso@4 | 137 # Diff between the cooklist and new ordered list ? So copy the last |
pankso@4 | 138 # cookorder to cooklist and rescan it. |
pankso@4 | 139 while /bin/true |
pankso@4 | 140 do |
pankso@4 | 141 diff $cooklist $cookorder > $cookorder.diff |
pankso@4 | 142 if [ -s "$cookorder.diff" ]; then |
pankso@4 | 143 scan=$(($scan + 1)) |
pankso@4 | 144 echo -e "\nDiff scan: $scan" |
pankso@4 | 145 separator |
pankso@4 | 146 mv -f $cookorder $cooklist |
pankso@4 | 147 cook_order_scan |
pankso@4 | 148 else |
pankso@4 | 149 break |
pankso@4 | 150 fi |
pankso@4 | 151 done |
pankso@4 | 152 |
pankso@4 | 153 # Keep a diff between submited cooklist and the ordered. |
pankso@4 | 154 diff $cooklist.0 $cooklist > $cooklist.diff |
pankso@4 | 155 rm -f $cookorder $cookorder.diff $cooklist.0 |
pankso@4 | 156 |
pankso@4 | 157 # Scan is finish: append pkg to WANTED |
pankso@4 | 158 echo -e "\nHandle WANTED package" |
pankso@4 | 159 separator |
pankso@4 | 160 for pkg in $(cat $cooklist) |
pankso@4 | 161 do |
pankso@4 | 162 unset WANTED |
pankso@14 | 163 . $wok/$pkg/receipt |
pankso@4 | 164 if [ "$WANTED" ]; then |
pankso@29 | 165 echo "$pkg :: $WANTED" |
pankso@4 | 166 sed -i -e "/^$pkg$/"d \ |
pankso@4 | 167 -e "/^$WANTED$/ a $pkg" $cooklist |
pankso@4 | 168 fi |
pankso@4 | 169 done |
pankso@4 | 170 |
pankso@4 | 171 # Show ordered cooklist |
pankso@4 | 172 echo -e "\nCooklist order" |
pankso@4 | 173 separator |
pankso@4 | 174 cat $cooklist |
pankso@4 | 175 separator |
pankso@4 | 176 time=$(($(date +%s) - $time)) |
pankso@4 | 177 pkgs=$(cat $cooklist | wc -l) |
pankso@35 | 178 echo -e "\nSummary for cookorder" |
pankso@4 | 179 separator |
pankso@4 | 180 cat << EOT |
pankso@4 | 181 Ordered packages : $pkgs |
pankso@4 | 182 Scans executed : $scan |
pankso@4 | 183 Scan duration : ${time}s |
pankso@4 | 184 EOT |
pankso@35 | 185 separator |
pankso@4 | 186 } |
pankso@4 | 187 |
pankso@14 | 188 # Remove blocked (faster this way than grepping before). |
pankso@14 | 189 strip_blocked() { |
pankso@14 | 190 for pkg in $(cat $blocked) |
pankso@14 | 191 do |
pankso@14 | 192 sed -i /^${pkg}$/d $cooklist |
pankso@14 | 193 done && sed -i /^$/d $cooklist |
pankso@14 | 194 } |
pankso@14 | 195 |
pankso@4 | 196 # Uses in default mode and with all cmd. |
pankso@4 | 197 cook_commits() { |
pankso@4 | 198 if [ -s "$commits" ]; then |
pankso@4 | 199 for pkg in $(cat $commits) |
pankso@4 | 200 do |
pankso@16 | 201 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log |
pankso@14 | 202 echo "cook:$pkg" > $command |
pankso@4 | 203 cook $pkg || broken |
pankso@4 | 204 sed -i /^${pkg}$/d $commits |
pankso@4 | 205 done |
pankso@4 | 206 fi |
pankso@4 | 207 } |
pankso@4 | 208 |
pankso@14 | 209 # Cook all package in a cooklist. |
pankso@14 | 210 cook_list() { |
pankso@14 | 211 for pkg in $(cat $cooklist) |
pankso@14 | 212 do |
pankso@14 | 213 if [ ! -d "$wok/$pkg/install" ]; then |
pankso@16 | 214 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log |
pankso@14 | 215 cook $pkg || broken |
pankso@14 | 216 sed -i /^${pkg}$/d $cooklist |
pankso@14 | 217 fi |
pankso@14 | 218 done |
pankso@14 | 219 } |
pankso@14 | 220 |
pankso@4 | 221 # |
pankso@4 | 222 # Commands |
pankso@4 | 223 # |
pankso@4 | 224 case "$1" in |
pankso@31 | 225 usage|help|-u|-h) |
pankso@4 | 226 usage ;; |
pankso@31 | 227 setup|-s) |
pankso@4 | 228 # Setup the Cooker environment. |
pankso@4 | 229 echo -e "\nSetting up the Cooker" |
pankso@31 | 230 echo "Cooker setup using: $SLITAZ" | log |
pankso@4 | 231 separator |
pankso@29 | 232 for pkg in $SETUP_PKGS mercurial rsync |
pankso@4 | 233 do |
pankso@4 | 234 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg |
pankso@4 | 235 done |
pankso@4 | 236 mkdir -p $SLITAZ && cd $SLITAZ |
pankso@4 | 237 [ -d "${wok}-hg" ] && echo -e "Hg wok already exist.\n" && exit 1 |
pankso@4 | 238 [ -d "$wok" ] && echo -e "Build wok already exist.\n" && exit 1 |
pankso@31 | 239 [ -d "$flavors" ] && echo -e "Flavors repo already exist.\n" && exit 1 |
pankso@4 | 240 |
pankso@4 | 241 # Directories and files |
pankso@4 | 242 echo "mkdir's and touch files in: $SLITAZ" |
pankso@4 | 243 mkdir -p $PKGS $LOGS $CACHE $SRC |
pankso@14 | 244 for f in $activity $blocked $broken $commits $cooklist $command |
pankso@4 | 245 do |
pankso@4 | 246 touch $f |
pankso@4 | 247 done |
pankso@14 | 248 hg clone $WOK_URL ${wok}-hg || exit 1 |
pankso@4 | 249 hg clone $FLAVORS_URL flavors |
pankso@4 | 250 cp -a ${wok}-hg $wok |
pankso@4 | 251 separator && echo "" ;; |
pankso@31 | 252 note|-n) |
pankso@31 | 253 # Blocked a pkg and want other to know why ? Post a note! |
pankso@31 | 254 note="$2" |
pankso@48 | 255 date=$(date "+%Y-%m-%d %H:%M") |
pankso@48 | 256 [ "$note" ] && echo "$date : $note" >> $cooknotes ;; |
pankso@31 | 257 notes|-ns) |
pankso@29 | 258 # View cooknotes. |
pankso@29 | 259 echo -e "\nCooknotes" |
pankso@29 | 260 separator |
pankso@29 | 261 cat $cooknotes |
pankso@29 | 262 separator && echo "" ;; |
pankso@49 | 263 block|-b) |
pankso@49 | 264 # Block a package. |
pankso@49 | 265 [ "$pkg" ] && cook $pkg --block ;; |
pankso@49 | 266 unblock|-ub) |
pankso@49 | 267 # Unblock a package. |
pankso@49 | 268 [ "$pkg" ] && cook $pkg --unblock ;; |
pankso@31 | 269 reverse|-r) |
pankso@4 | 270 # Cook all reverse dependencies for a packages. This command let us |
pankso@11 | 271 # control the Cooker manually for commit that will cook a lot of packages. |
pankso@14 | 272 # |
pankso@21 | 273 # Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:reverse" |
pankso@14 | 274 # |
pankso@32 | 275 [ ! -d "$wok/$pkg" ] && echo -e "\nNo package $2 found.\n" && exit 0 |
pankso@32 | 276 rm -f $cooklist && touch $cooklist && cd $wok |
pankso@32 | 277 echo -e "\nReverse cooklist for: $pkg" |
pankso@32 | 278 separator && cd $wok |
pankso@4 | 279 for rev in * |
pankso@4 | 280 do |
pankso@32 | 281 unset DEPENDS BUILD_DEPENDS && . $wok/$rev/receipt |
pankso@32 | 282 if echo "$DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then |
pankso@32 | 283 echo "$rev" | tee -a $cooklist |
pankso@4 | 284 fi |
pankso@32 | 285 done && separator |
pankso@32 | 286 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n" |
pankso@32 | 287 strip_blocked |
pankso@32 | 288 cook_order | tee $LOGS/cookorder.log |
pankso@32 | 289 cook_list ;; |
pankso@31 | 290 pkg|-p) |
pankso@12 | 291 # Same as 'cook pkg' but with log for web interface. |
pankso@16 | 292 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log |
pankso@32 | 293 cook $pkg || broken |
pankso@32 | 294 empty_command ;; |
pankso@31 | 295 cat|-c) |
pankso@4 | 296 # Cook all packages of a category. |
pankso@31 | 297 cat="$2" |
pankso@14 | 298 rm -f $cooklist && touch $cooklist && cd $wok |
pankso@4 | 299 for pkg in * |
pankso@4 | 300 do |
pankso@4 | 301 unset CATEGORY && . $pkg/receipt |
pankso@4 | 302 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist |
pankso@4 | 303 done |
pankso@14 | 304 strip_blocked |
pankso@14 | 305 cook_order | tee $LOGS/cookorder.log |
pankso@26 | 306 cook_list ;; |
pankso@31 | 307 flavor|-f) |
pankso@21 | 308 # Cook all packages of a flavor. |
pankso@31 | 309 name="$2" |
pankso@31 | 310 [ ! -d "$flavors/$name" ] && \ |
pankso@31 | 311 echo -e "\nSpecified flavor does not exist: $name\n" && exit 1 |
pankso@31 | 312 list=$flavors/$name/packages.list |
pankso@21 | 313 cp -a $list $cooklist |
pankso@21 | 314 strip_blocked |
pankso@21 | 315 cook_order | tee $LOGS/cookorder.log |
pankso@32 | 316 cook_list ;; |
pankso@31 | 317 list|-l) |
pankso@26 | 318 # Cook a list og package given in argument. |
pankso@31 | 319 list="$2" |
pankso@26 | 320 [ ! -f "$list" ] && \ |
pankso@26 | 321 echo -e "\nSpecified list does not exist: $list\n" && exit 1 |
pankso@26 | 322 cp -a $list $cooklist |
pankso@26 | 323 strip_blocked |
pankso@26 | 324 cook_order | tee $LOGS/cookorder.log |
pankso@26 | 325 cook_list ;; |
pankso@31 | 326 all|-a) |
pankso@4 | 327 # Try to build all unbuilt packages except blocked's. |
pankso@31 | 328 echo "cooker:all" > $command |
pankso@4 | 329 rm -f $cooklist && touch $cooklist |
pankso@4 | 330 echo "" && cd $wok |
pankso@4 | 331 echo "Cooker cooklist" |
pankso@4 | 332 separator |
pankso@4 | 333 |
pankso@4 | 334 # Find all unbuilt packages. |
pankso@4 | 335 echo "Searching for all unbuilt packages" | log |
pankso@4 | 336 for pkg in * |
pankso@4 | 337 do |
pankso@4 | 338 . $pkg/receipt |
pankso@4 | 339 [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ] && \ |
pankso@4 | 340 echo $pkg >> $cooklist |
pankso@4 | 341 done |
pankso@4 | 342 |
pankso@14 | 343 strip_blocked |
pankso@13 | 344 echo "Packages to cook: $(cat $cooklist | wc -l)" | log |
pankso@14 | 345 cook_order | tee $LOGS/cookorder.log |
pankso@27 | 346 cook_list && empty_command;; |
pankso@4 | 347 *) |
pankso@4 | 348 # Default is to cook all commits. |
pankso@4 | 349 [ "$1" ] && usage |
pankso@4 | 350 cooklist=$CACHE/commits |
pankso@14 | 351 rm -f $LOGS/commits.log |
pankso@14 | 352 echo "" |
pankso@14 | 353 echo "Checking for commits" | log_commits |
pankso@14 | 354 separator | tee -a $LOGS/commits.log |
pankso@4 | 355 |
pankso@4 | 356 # Get revisions. |
pankso@14 | 357 cd $wok || ( echo "No wok found: $wok" && exit 1 ) |
pankso@4 | 358 cur=$(hg head --template '{rev}\n') |
pankso@13 | 359 echo "Updating Hg wok: ${wok}-hg" | log |
pankso@14 | 360 echo "hg:pull" > $command |
pankso@41 | 361 [ -f "${wok}-hg/.hg/hgrc" ] && cd ${wok}-hg && hg pull -u | log_commits |
pankso@4 | 362 new=$(hg head --template '{rev}\n') |
pankso@14 | 363 |
pankso@4 | 364 # Sync build wok with rsync so we dont take care about removing old |
pankso@4 | 365 # files as before. |
pankso@4 | 366 if [ "$new" -gt "$cur" ]; then |
pankso@4 | 367 echo "Changes found from: $cur to $new" | log |
pankso@35 | 368 echo "Syncing build wok with Hg wok..." | log_commits |
pankso@46 | 369 rsync -r -t -c -l -u -p -v -D -E ${wok}-hg/ $wok/ | \ |
pankso@35 | 370 sed '/^$/'d | log_commits |
pankso@4 | 371 else |
pankso@13 | 372 echo "No revision changes: $cur vs $new" | log |
pankso@14 | 373 separator | log_commits |
pankso@27 | 374 empty_command && echo "" && exit 0 |
pankso@4 | 375 fi |
pankso@4 | 376 |
pankso@35 | 377 # Get and display modifications. |
pankso@4 | 378 cd ${wok}-hg |
pankso@14 | 379 cur=$(($cur + 1)) |
pankso@35 | 380 commits_summary | log_commits |
pankso@35 | 381 |
pankso@4 | 382 rm -f $commits.tmp && touch $commits.tmp |
pankso@4 | 383 for rev in $(seq $cur $new); do |
pankso@35 | 384 #log=$(hg log --rev=$rev --template "{files}\t{desc}\n") |
pankso@35 | 385 log=$(hg log --rev=$rev --template "{files}\n" | cut -d "/" -f 1) |
pankso@36 | 386 |
pankso@4 | 387 for file in $log; do |
pankso@36 | 388 desc=$(hg log --rev=$rev --template "{desc}" $file) |
pankso@36 | 389 echo "Commited : $file - $desc" | log_commits |
pankso@4 | 390 echo $file >> $commits.tmp |
pankso@4 | 391 done |
pankso@4 | 392 done |
pankso@4 | 393 |
pankso@4 | 394 # Keep previews commit and discard duplicate lines |
pankso@4 | 395 cat $commits $commits.tmp | sed /"^$"/d > $commits.new |
pankso@4 | 396 uniq $commits.new > $commits && rm $commits.* |
pankso@35 | 397 echo "Packages to cook : $(cat $commits | wc -l)" | log_commits |
pankso@35 | 398 separator | log_commits |
pankso@35 | 399 echo "" |
pankso@14 | 400 strip_blocked |
pankso@14 | 401 cook_order | tee $LOGS/cookorder.log |
pankso@27 | 402 cook_commits && empty_command ;; |
pankso@4 | 403 esac |
pankso@4 | 404 |
pankso@4 | 405 exit 0 |