cookutils view cooker @ rev 50

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