cookutils view cooker @ rev 62

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sat May 07 15:22:01 2011 +0100 (2011-05-07)
parents 147bded5c460
children ffb061b0826f
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 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 messages occur 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 success.
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 and 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 cookorder.
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 until 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 finished: 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 # Use 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:$pkg" > $command
202 cook $pkg || broken
203 sed -i /^${pkg}$/d $commits
204 done
205 fi
206 }
208 # Cook all packages in a cooklist.
209 cook_list() {
210 for pkg in $(cat $cooklist)
211 do
212 if [ ! -d "$wok/$pkg/install" ]; then
213 cook $pkg || broken
214 sed -i /^${pkg}$/d $cooklist
215 fi
216 done
217 }
219 #
220 # Commands
221 #
222 case "$1" in
223 usage|help|-u|-h)
224 usage ;;
225 setup|-s)
226 # Setup the Cooker environment.
227 echo -e "\nSetting up the Cooker"
228 echo "Cooker setup using: $SLITAZ" | log
229 separator
230 for pkg in $SETUP_PKGS mercurial rsync
231 do
232 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
233 done
234 mkdir -p $SLITAZ && cd $SLITAZ
235 [ -d "${wok}-hg" ] && echo -e "Hg wok already exists.\n" && exit 1
236 [ -d "$wok" ] && echo -e "Build wok already exists.\n" && exit 1
238 # Directories and files
239 echo "mkdir's and touch files in: $SLITAZ"
240 mkdir -p $PKGS $LOGS $CACHE $SRC
241 for f in $activity $blocked $broken $commits $cooklist $command
242 do
243 touch $f
244 done
245 hg clone $WOK_URL ${wok}-hg || exit 1
246 [ -d "$flavors" ] || hg clone $FLAVORS_URL flavors
247 cp -a ${wok}-hg $wok
248 separator && echo "" ;;
249 note|-n)
250 # Blocked a pkg and want others to know why ? Post a note!
251 note="$2"
252 date=$(date "+%Y-%m-%d %H:%M")
253 [ "$note" ] && echo "$date : $note" >> $cooknotes ;;
254 notes|-ns)
255 # View cooknotes.
256 echo -e "\nCooknotes"
257 separator
258 cat $cooknotes
259 separator && echo "" ;;
260 block|-b)
261 # Block a package.
262 [ "$pkg" ] && cook $pkg --block ;;
263 unblock|-ub)
264 # Unblock a package.
265 [ "$pkg" ] && cook $pkg --unblock ;;
266 reverse|-r)
267 # Cook all reverse dependencies for a package. This command lets us
268 # control the Cooker manually for commits that will cook a lot of packages.
269 #
270 # Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:reverse"
271 #
272 [ ! -d "$wok/$pkg" ] && echo -e "\nNo package $2 found.\n" && exit 0
273 rm -f $cooklist && touch $cooklist && cd $wok
274 echo -e "\nReverse cooklist for: $pkg"
275 separator && cd $wok
276 for rev in *
277 do
278 unset DEPENDS BUILD_DEPENDS && . $wok/$rev/receipt
279 if echo "$DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then
280 echo "$rev" | tee -a $cooklist
281 fi
282 done && separator
283 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n"
284 strip_blocked
285 cook_order | tee $LOGS/cookorder.log
286 cook_list ;;
287 pkg|-p)
288 # Same as 'cook pkg' but with log for web interface.
289 cook $pkg || broken
290 empty_command ;;
291 cat|-c)
292 # Cook all packages of a category.
293 cat="$2"
294 rm -f $cooklist && touch $cooklist && cd $wok
295 for pkg in *
296 do
297 unset CATEGORY && . $pkg/receipt
298 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
299 done
300 strip_blocked
301 cook_order | tee $LOGS/cookorder.log
302 cook_list ;;
303 flavor|-f)
304 # Cook all packages of a flavor.
305 name="$2"
306 [ ! -d "$flavors/$name" ] && \
307 echo -e "\nSpecified flavor does not exist: $name\n" && exit 1
308 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
309 list=$flavors/$name/packages.list
310 cp -a $list $cooklist
311 strip_blocked
312 cook_order | tee $LOGS/cookorder.log
313 cook_list ;;
314 list|-l)
315 # Cook a list of packages given in argument.
316 list="$2"
317 [ ! -f "$list" ] && \
318 echo -e "\nSpecified list does not exist: $list\n" && exit 1
319 cp -a $list $cooklist
320 strip_blocked
321 cook_order | tee $LOGS/cookorder.log
322 cook_list ;;
323 all|-a)
324 # Try to build all unbuilt packages except blocked's.
325 echo "cooker:all" > $command
326 rm -f $cooklist && touch $cooklist
327 echo "" && cd $wok
328 echo "Cooker cooklist"
329 separator
331 # Find all unbuilt packages.
332 echo "Searching for all unbuilt packages" | log
333 for pkg in *
334 do
335 . $pkg/receipt
336 [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ] && \
337 echo $pkg >> $cooklist
338 done
340 strip_blocked
341 echo "Packages to cook: $(cat $cooklist | wc -l)" | log
342 cook_order | tee $LOGS/cookorder.log
343 cook_list && empty_command;;
344 *)
345 # Default is to cook all commits.
346 [ "$1" ] && usage
347 cooklist=$CACHE/commits
348 rm -f $LOGS/commits.log
349 echo ""
350 echo "Checking for commits" | log_commits
351 separator | tee -a $LOGS/commits.log
353 # Get revisions.
354 cd $wok || exit 1
355 cur=$(hg head --template '{rev}\n')
356 echo "Updating Hg wok: ${wok}-hg" | log
357 echo "hg:pull" > $command
358 cd ${wok}-hg && hg pull -u | log_commits
359 new=$(hg head --template '{rev}\n')
361 # Sync build wok with rsync so we don't take care about removing old
362 # files as before.
363 if [ "$new" -gt "$cur" ]; then
364 echo "Changes found from: $cur to $new" | log
365 echo "Syncing build wok with Hg wok..." | log_commits
366 rsync -r -t -c -l -u -p -v -D -E ${wok}-hg/ $wok/ | \
367 sed '/^$/'d | log_commits
368 else
369 echo "No revision changes: $cur vs $new" | log
370 separator | log_commits
371 empty_command && echo "" && exit 0
372 fi
374 # Get and display modifications.
375 cd ${wok}-hg
376 cur=$(($cur + 1))
377 commits_summary | log_commits
379 rm -f $commits.tmp && touch $commits.tmp
380 for rev in $(seq $cur $new); do
381 #log=$(hg log --rev=$rev --template "{files}\t{desc}\n")
382 log=$(hg log --rev=$rev --template "{files}\n" | cut -d "/" -f 1)
384 for file in $log; do
385 desc=$(hg log --rev=$rev --template "{desc}" $file)
386 echo "Commited : $file - $desc" | log_commits
387 echo $file >> $commits.tmp
388 done
389 done
391 # Keep previous commit and discard duplicate lines
392 cat $commits $commits.tmp | sed /"^$"/d > $commits.new
393 uniq $commits.new > $commits && rm $commits.*
394 echo "Packages to cook : $(cat $commits | wc -l)" | log_commits
395 separator | log_commits
396 echo ""
397 strip_blocked
398 cook_order | tee $LOGS/cookorder.log
399 cook_commits && empty_command ;;
400 esac
402 exit 0