cookutils view cooker @ rev 78

rsync woks: we dont need -p since Hg wok is clone by root
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 07 23:23:59 2011 +0200 (2011-05-07)
parents dad3f6ed300c
children 246abb0e12d9
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 60 $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 if ! grep -q "^$pkg$" $broken; then
77 echo "$pkg" >> $broken
78 fi
79 }
81 # Clean up after cook success.
82 empty_command() {
83 rm -f $command && touch $command
84 }
86 # Summary for commits.
87 commits_summary() {
88 msg="from revision $cur to $new"
89 [ "$new" == "$cur" ] && msg="revision $new"
90 echo "Will cook $msg"
91 separator
92 echo -e "\nSummary for commits"
93 separator
94 echo "Hg wok revision : $cur"
95 echo "Pulled revision : $new"
96 echo "Check date : $(date '+%Y-%m-%d %H:%M')"
97 }
99 # Scan packages build deps and fill up cookorder list.
100 cook_order_scan() {
101 touch $cooklist $cookorder
102 for pkg in $(cat $cooklist)
103 do
104 unset BUILD_DEPENDS
105 . $wok/$pkg/receipt
106 # The :: is for web interface color.
107 [ "$BUILD_DEPENDS" ] && echo "$pkg :: $BUILD_DEPENDS"
108 for dep in $BUILD_DEPENDS
109 do
110 if grep -q "^$dep$" $cooklist; then
111 if ! grep -q "^$dep$" $cookorder; then
113 echo "$dep" >> $cookorder
114 fi
115 fi
116 done
117 done
119 # Append unordered packages to cookorder.
120 for pkg in $(cat $cooklist)
121 do
122 if ! grep -q "^$pkg$" $cookorder; then
123 echo "$pkg" >> $cookorder
124 fi
125 done
126 }
128 # Scan and rescan until the cooklist is ordered then handle WANTED.
129 cook_order() {
130 time=$(date +%s)
131 scan=0
133 # Keep an original cooklist so we do a diff when ordering is finished.
134 cp -f $cooklist $cooklist.0
135 echo -e "\nInitial Cooker order scan"
136 separator
137 cook_order_scan
139 # Diff between the cooklist and new ordered list ? So copy the last
140 # cookorder to cooklist and rescan it.
141 while /bin/true
142 do
143 diff $cooklist $cookorder > $cookorder.diff
144 if [ -s "$cookorder.diff" ]; then
145 scan=$(($scan + 1))
146 echo -e "\nDiff scan: $scan"
147 separator
148 mv -f $cookorder $cooklist
149 cook_order_scan
150 else
151 break
152 fi
153 done
155 # Keep a diff between submited cooklist and the ordered.
156 diff $cooklist.0 $cooklist > $cooklist.diff
157 rm -f $cookorder $cookorder.diff $cooklist.0
159 # Scan is finished: append pkg to WANTED
160 echo -e "\nHandle WANTED package"
161 separator
162 for pkg in $(cat $cooklist)
163 do
164 unset WANTED
165 . $wok/$pkg/receipt
166 if [ "$WANTED" ]; then
167 echo "$pkg :: $WANTED"
168 sed -i -e "/^$pkg$/"d \
169 -e "/^$WANTED$/ a $pkg" $cooklist
170 fi
171 done
173 # Show ordered cooklist
174 echo -e "\nCooklist order"
175 separator
176 cat $cooklist
177 separator
178 time=$(($(date +%s) - $time))
179 pkgs=$(cat $cooklist | wc -l)
180 echo -e "\nSummary for cookorder"
181 separator
182 cat << EOT
183 Ordered packages : $pkgs
184 Scans executed : $scan
185 Scan duration : ${time}s
186 EOT
187 separator
188 }
190 # Remove blocked (faster this way than grepping before).
191 strip_blocked() {
192 for pkg in $(cat $blocked)
193 do
194 sed -i /^${pkg}$/d $cooklist
195 done && sed -i /^$/d $cooklist
196 }
198 # Use in default mode and with all cmd.
199 cook_commits() {
200 if [ -s "$commits" ]; then
201 for pkg in $(cat $commits)
202 do
203 echo "cook:$pkg" > $command
204 cook $pkg || broken
205 sed -i /^${pkg}$/d $commits
206 done
207 fi
208 }
210 # Cook all packages in a cooklist.
211 cook_list() {
212 for pkg in $(cat $cooklist)
213 do
214 if [ ! -d "$wok/$pkg/install" ]; then
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 exists.\n" && exit 1
238 [ -d "$wok" ] && echo -e "Build wok already exists.\n" && exit 1
240 # Directories and files
241 echo "mkdir's and touch files in: $SLITAZ"
242 mkdir -p $PKGS $LOGS $CACHE $SRC
243 for f in $activity $blocked $broken $commits $cooklist $command
244 do
245 touch $f
246 done
247 hg clone $WOK_URL ${wok}-hg || exit 1
248 [ -d "$flavors" ] || hg clone $FLAVORS_URL flavors
249 cp -a ${wok}-hg $wok
250 separator && echo "" ;;
251 note|-n)
252 # Blocked a pkg and want others to know why ? Post a note!
253 note="$2"
254 date=$(date "+%Y-%m-%d %H:%M")
255 [ "$note" ] && echo "$date : $note" >> $cooknotes ;;
256 notes|-ns)
257 # View cooknotes.
258 echo -e "\nCooknotes"
259 separator
260 cat $cooknotes
261 separator && echo "" ;;
262 block|-b)
263 # Block a package.
264 [ "$pkg" ] && cook $pkg --block ;;
265 unblock|-ub)
266 # Unblock a package.
267 [ "$pkg" ] && cook $pkg --unblock ;;
268 reverse|-r)
269 # Cook all reverse dependencies for a package. This command lets us
270 # control the Cooker manually for commits that will cook a lot of packages.
271 #
272 # Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:reverse"
273 #
274 [ ! -d "$wok/$pkg" ] && echo -e "\nNo package $2 found.\n" && exit 0
275 rm -f $cooklist && touch $cooklist && cd $wok
276 echo -e "\nReverse cooklist for: $pkg"
277 separator && cd $wok
278 for rev in *
279 do
280 unset DEPENDS BUILD_DEPENDS && . $wok/$rev/receipt
281 if echo "$DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then
282 echo "$rev" | tee -a $cooklist
283 fi
284 done && separator
285 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n"
286 strip_blocked
287 cook_order | tee $LOGS/cookorder.log
288 cook_list ;;
289 pkg|-p)
290 # Same as 'cook pkg' but with log for web interface.
291 cook $pkg || broken
292 empty_command ;;
293 cat|-c)
294 # Cook all packages of a category.
295 cat="$2"
296 rm -f $cooklist && touch $cooklist && cd $wok
297 for pkg in *
298 do
299 unset CATEGORY && . $pkg/receipt
300 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
301 done
302 strip_blocked
303 cook_order | tee $LOGS/cookorder.log
304 cook_list ;;
305 flavor|-f)
306 # Cook all packages of a flavor.
307 name="$2"
308 [ ! -d "$flavors/$name" ] && \
309 echo -e "\nSpecified flavor does not exist: $name\n" && exit 1
310 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
311 list=$flavors/$name/packages.list
312 cp -a $list $cooklist
313 strip_blocked
314 cook_order | tee $LOGS/cookorder.log
315 cook_list ;;
316 list|-l)
317 # Cook a list of packages given in argument.
318 list="$2"
319 [ ! -f "$list" ] && \
320 echo -e "\nSpecified list does not exist: $list\n" && exit 1
321 cp -a $list $cooklist
322 strip_blocked
323 cook_order | tee $LOGS/cookorder.log
324 cook_list ;;
325 all|-a)
326 # Try to build all unbuilt packages except blocked's.
327 echo "cooker:all" > $command
328 rm -f $cooklist && touch $cooklist
329 echo "" && cd $wok
330 echo "Cooker cooklist"
331 separator
333 # Find all unbuilt packages.
334 echo "Searching for all unbuilt packages" | log
335 for pkg in *
336 do
337 . $pkg/receipt
338 [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ] && \
339 echo $pkg >> $cooklist
340 done
342 strip_blocked
343 echo "Packages to cook: $(cat $cooklist | wc -l)" | log
344 cook_order | tee $LOGS/cookorder.log
345 cook_list && empty_command;;
346 *)
347 # Default is to cook all commits.
348 [ "$1" ] && usage
349 cooklist=$CACHE/commits
350 rm -f $LOGS/commits.log
351 echo ""
352 echo "Checking for commits" | log_commits
353 separator | tee -a $LOGS/commits.log
355 # Get revisions.
356 cd $wok || exit 1
357 cur=$(hg head --template '{rev}\n')
358 echo "Updating Hg wok: ${wok}-hg" | log
359 echo "hg:pull" > $command
360 cd ${wok}-hg && hg pull -u | log_commits
361 new=$(hg head --template '{rev}\n')
363 # Sync build wok with rsync so we don't take care about removing old
364 # files as before.
365 if [ "$new" -gt "$cur" ]; then
366 echo "Changes found from: $cur to $new" | log
367 echo "Syncing build wok with Hg wok..." | log_commits
368 rsync -r -t -c -l -u -v -D -E ${wok}-hg/ $wok/ | \
369 sed '/^$/'d | log_commits
370 else
371 echo "No revision changes: $cur vs $new" | log
372 separator | log_commits
373 empty_command && echo "" && exit 0
374 fi
376 # Get and display modifications.
377 cd ${wok}-hg
378 cur=$(($cur + 1))
379 commits_summary | log_commits
381 rm -f $commits.tmp && touch $commits.tmp
382 for rev in $(seq $cur $new); do
383 #log=$(hg log --rev=$rev --template "{files}\t{desc}\n")
384 log=$(hg log --rev=$rev --template "{files}\n" | cut -d "/" -f 1)
386 for file in $log; do
387 desc=$(hg log --rev=$rev --template "{desc}" $file)
388 echo "Commited : $file - $desc" | log_commits
389 echo $file >> $commits.tmp
390 done
391 done
393 # Keep previous commit and discard duplicate lines
394 cat $commits $commits.tmp | sed /"^$"/d > $commits.new
395 uniq $commits.new > $commits && rm $commits.*
396 echo "Packages to cook : $(cat $commits | wc -l)" | log_commits
397 separator | log_commits
398 echo ""
399 strip_blocked
400 cook_order | tee $LOGS/cookorder.log
401 cook_commits && empty_command ;;
402 esac
404 exit 0