cookutils view cooker @ rev 22

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