cookutils view cooker @ rev 28

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