cookutils view cooker @ rev 14

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