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