cookutils view cooker @ rev 79

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