cookutils view cooker @ rev 13

cooker: more log and better (again)
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 05 00:06:01 2011 +0200 (2011-05-05)
parents 97ff63251957
children 01dfc1ed1e0e
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 status="$CACHE/status"
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 # Log broken packages
60 broken() {
61 echo "$pkg" >> $broken
62 }
64 # Scan packages deps an fill up cookorder list.
65 cook_order_scan() {
66 touch $cooklist $cookorder
67 for pkg in $(cat $cooklist)
68 do
69 unset DEPENDS BUILD_DEPENDS
70 . $WOK/$pkg/receipt
71 for dep in $DEPENDS $BUILD_DEPENDS
72 do
73 if grep -q "^$dep$" $cooklist; then
74 echo -e "$pkg: $dep"
75 if ! grep -q "^$dep$" $cookorder; then
76 echo "$dep" >> $cookorder
77 fi
78 fi
79 done
80 done
82 # Append unordered packages to cookored.
83 for pkg in $(cat $cooklist)
84 do
85 if ! grep -q "^$pkg$" $cookorder; then
86 echo "$pkg" >> $cookorder
87 fi
88 done
89 }
91 # Scan and rescan untill the cooklist is ordered then handle WANTED.
92 cook_order() {
93 time=$(date +%s)
94 scan=0
96 # Keep an original cooklist so we do a diff when ordering is finished.
97 cp -f $cooklist $cooklist.0
98 echo -e "\nInitial Cooker order scan"
99 separator
100 cook_order_scan
102 # Diff between the cooklist and new ordered list ? So copy the last
103 # cookorder to cooklist and rescan it.
104 while /bin/true
105 do
106 diff $cooklist $cookorder > $cookorder.diff
107 if [ -s "$cookorder.diff" ]; then
108 scan=$(($scan + 1))
109 echo -e "\nDiff scan: $scan"
110 separator
111 mv -f $cookorder $cooklist
112 cook_order_scan
113 else
114 break
115 fi
116 done
118 # Keep a diff between submited cooklist and the ordered.
119 diff $cooklist.0 $cooklist > $cooklist.diff
120 rm -f $cookorder $cookorder.diff $cooklist.0
122 # Scan is finish: append pkg to WANTED
123 echo -e "\nHandle WANTED package"
124 separator
125 for pkg in $(cat $cooklist)
126 do
127 unset WANTED
128 . $WOK/$pkg/receipt
129 if [ "$WANTED" ]; then
130 echo "$pkg: $WANTED"
131 sed -i -e "/^$pkg$/"d \
132 -e "/^$WANTED$/ a $pkg" $cooklist
133 fi
134 done
136 # Show ordered cooklist
137 echo -e "\nCooklist order"
138 separator
139 cat $cooklist
140 separator
141 time=$(($(date +%s) - $time))
142 pkgs=$(cat $cooklist | wc -l)
143 echo -e "\nSummary"
144 separator
145 cat << EOT
146 Ordered packages : $pkgs
147 Scans executed : $scan
148 Scan duration : ${time}s
149 EOT
150 separator && echo ""
151 }
153 # Uses in default mode and with all cmd.
154 cook_commits() {
155 if [ -s "$commits" ]; then
156 for pkg in $(cat $commits)
157 do
158 echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
159 echo "cook:$pkg" > $status
160 cook $pkg || broken
161 sed -i /^${pkg}$/d $commits
162 done
163 fi
164 }
166 #
167 # Commands
168 #
169 case "$1" in
170 --usage|--help)
171 usage ;;
172 --setup)
173 # Setup the Cooker environment.
174 echo -e "\nSetting up the Cooker"
175 echo "Cooker --setup using: $SLITAZ" | log
176 separator
177 for pkg in mercurial rsync slitaz-toolchain
178 do
179 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
180 done
181 mkdir -p $SLITAZ && cd $SLITAZ
182 [ -d "${wok}-hg" ] && echo -e "Hg wok already exist.\n" && exit 1
183 [ -d "$wok" ] && echo -e "Build wok already exist.\n" && exit 1
184 [ -d "flavors" ] && echo -e "Flavors repo already exist.\n" && exit 1
186 # Directories and files
187 echo "mkdir's and touch files in: $SLITAZ"
188 mkdir -p $PKGS $LOGS $CACHE $SRC
189 for f in $activity $blocked $broken $commits $cooklist $status
190 do
191 touch $f
192 done
193 hg clone $WOK_URL ${wok}-hg
194 hg clone $FLAVORS_URL flavors
195 cp -a ${wok}-hg $wok
196 separator && echo "" ;;
197 --reverse=*)
198 # Cook all reverse dependencies for a packages. This command let us
199 # control the Cooker manually for commit that will cook a lot of packages.
200 pkg=${1#--reverse=}
201 [ ! -d "$wok/$pkg" ] && echo "No package $2 found." && exit 0
202 cd $wok
203 for rev in *
204 do
205 if fgrep DEPENDS $rev/receipt | fgrep $pkg; then
206 echo "TODO: $rev"
207 fi
208 done ;;
209 --pkg=*)
210 # Same as 'cook pkg' but with log for web interface.
211 pkg=${1#--pkg=}
212 echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
213 cook $pkg || broken ;;
214 --cat=*)
215 # Cook all packages of a category.
216 rm -f $cooklist && touch $cooklist
217 cat=${1#--cat=} && cd $WOK
218 for pkg in *
219 do
220 unset CATEGORY && . $pkg/receipt
221 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
222 done
223 cook_order | tee $LOGS/cooker-order.log
224 for pkg in $(cat $cooklist)
225 do
226 echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
227 cook $pkg || broken
228 done
229 ;;
230 --all)
231 # Try to build all unbuilt packages except blocked's.
232 rm -f $cooklist && touch $cooklist
234 echo "" && cd $wok
235 echo "Cooker cooklist"
236 separator
238 # Find all unbuilt packages.
239 echo "Searching for all unbuilt packages" | log
240 for pkg in *
241 do
242 . $pkg/receipt
243 [ ! -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ] && \
244 echo $pkg >> $cooklist
245 done
247 # Remove blocked (faster this way than grepping before).
248 for pkg in $(cat $blocked)
249 do
250 sed -i /^${pkg}$/d $cooklist
251 done && sed -i /^$/d $cooklist
253 echo "Packages to cook: $(cat $cooklist | wc -l)"
254 echo "Packages to cook: $(cat $cooklist | wc -l)" | log
255 cook_order | tee $LOGS/cooker-order.log
257 # Clean DB files
258 echo "Cleaning cached DB files" | log
259 #sed /^$/ $cooklist > $cooklist.tmp
260 #uniq $cooklist.tmp > $cooklist && rm -f $cooklist.tmp
261 #echo "Cooklist: $(cat $cooklist | wc -l)"
262 echo "" ;;
263 *)
264 # Default is to cook all commits.
265 [ "$1" ] && usage
266 cooklist=$CACHE/commits
267 echo -e "\nChecking for commits"
268 separator
270 # Get revisions.
271 cd $wok || ( echo "" && exit 1 )
272 cur=$(hg head --template '{rev}\n')
273 echo "Updating Hg wok: ${wok}-hg" | log
274 echo "hg:pull" > $status
275 cd ${wok}-hg && hg pull -u
276 new=$(hg head --template '{rev}\n')
277 echo "Hg wok revision : $cur"
278 echo "Pulled revision : $new"
280 # Sync build wok with rsync so we dont take care about removing old
281 # files as before.
282 if [ "$new" -gt "$cur" ]; then
283 echo "Changes found from: $cur to $new" | log
284 echo "Syncing build work with Hg wok..."
285 cp -a ${wok}-hg/* $wok
286 cp -a ${wok}-hg/.hg $wok
287 else
288 echo "No revision changes: $cur vs $new" | log
289 separator && echo "" && exit 0
290 fi
292 # Get modifications
293 cd ${wok}-hg
294 cur=$(($cur+1))
295 msg="from revision $cur to $new"
296 [ "$new" == "$cur" ] && msg="revision: $new"
297 echo -e "Will cook $msg\n"
298 rm -f $commits.tmp && touch $commits.tmp
299 for rev in $(seq $cur $new); do
300 log=$(hg log --rev=$rev --template "{files}\n" | cut -d "/" -f 1)
301 for file in $log; do
302 echo $file >> $commits.tmp
303 done
304 done
306 # Keep previews commit and discard duplicate lines
307 cat $commits $commits.tmp | sed /"^$"/d > $commits.new
308 uniq $commits.new > $commits && rm $commits.*
309 echo "Packages to cook: $(cat $commits | wc -l)"
310 cook_order | tee $LOGS/cooker-order.log
311 cook_commits
312 echo "" > $status ;;
313 esac
315 exit 0