]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/xonotic-map-compiler-autobuild
also include an autoscreenshot engine log
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -e
4
5 bspdir="$PWD/data"
6 url_http=http://beta.xonotic.org/autobuild-bsp/
7 url_ssh=xonotic-beta:autobuild-bsp/
8 build_cachedir="$HOME/xonotic-map-compiler.cache/"
9 screenshot_cachedir="$HOME/xonotic-map-screenshot.cache/"
10 build_override="-bsp_timeout 1800 -vis_timeout 3600 -light_timeout 14400 -minimap_timeout 900 -scale_timeout 900"
11 screenshot_override="9 900 5 +g_ctf 1"
12
13 getthemap_fail=false
14
15 allmaps()
16 {
17         commithash=$1
18         shift
19         for F in `git show "${commithash}:maps/"`; do
20                 case "$F" in
21                         *.map.options)
22                                 ;;
23                         *)
24                                 continue
25                                 ;;
26                 esac
27                 M=${F%.map.options}
28                 blobhash=`git rev-parse --revs-only "${commithash}:maps/$M.map.options" || true`-`git rev-parse --revs-only "${commithash}:maps/$M.map" || true`
29                 case "$blobhash" in
30                         -*)
31                                 ;;
32                         *-)
33                                 ;;
34                         *)
35                                 "$@" "$M" "$blobhash" "$commithash"
36                                 ;;
37                 esac
38         done
39 }
40
41 pre2spam()
42 {
43         map=$1
44         url=$2
45         branch=$3
46         hash=$4
47
48         branch=${branch##refs/heads/}
49         branch=${branch##refs/remotes/}
50         branch=${branch##origin/}
51         hash=`echo "$hash" | cut -c 1-7`
52
53         echo "[$branch $hash] starting map compile of $map"
54 }
55
56 ss2spam()
57 {
58         map=$1
59         url=$2
60         branch=$3
61         hash=$4
62         status=$5
63
64         branch=${branch##refs/heads/}
65         branch=${branch##refs/remotes/}
66         branch=${branch##origin/}
67         hash=`echo "$hash" | cut -c 1-7`
68
69         s_error=
70
71         if [ "$status" -ne 0 ]; then
72                 s_error="exited with status $status"
73         fi
74
75         if [ -n "$s_error" ]; then
76                 echo "[$branch $hash] \ 34screenshots of $map could not be made: $s_error"
77         else
78                 echo "[$branch $hash] screenshots of $map are available on $url"
79         fi
80 }
81
82 log2spam()
83 {
84         map=$1
85         url=$2
86         branch=$3
87         hash=$4
88         status=$5
89         time=$6
90
91         hash=`echo "$hash" | cut -c 1-7`
92
93         branch=${branch##refs/heads/}
94         branch=${branch##refs/remotes/}
95         branch=${branch##origin/}
96
97         s_samplesize=
98         s_failshaders=
99         s_leaked=
100         s_error=
101
102         if [ "$status" -ne 0 ]; then
103                 s_error="exited with status $status"
104         fi
105         while IFS= read -r L; do
106                 case "$L" in
107                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
108                                 s=${L##* }
109                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
110                                         s_samplesize=$s
111                                 fi
112                                 ;;
113                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
114                                 # radiant stupid
115                                 ;;
116                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
117                                 s_failshaders="$s_failshaders ${L##* }"
118                                 ;;
119                         ERROR:\ *)
120                                 if [ -z "$s_error" ]; then
121                                         s_error=$L
122                                 fi
123                                 ;;
124                         '******* leaked *******')
125                                 s_leaked=1
126                                 ;;
127                         '************ ERROR ************')
128                                 IFS= read -r s_error
129                                 ;;
130                 esac
131         done
132         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
133         s_failshaders=${s_failshaders# }
134         if [ -n "$s_error" ]; then
135                 echo -n "[$branch $hash] \ 34failed"
136         else
137                 echo -n "[$branch $hash] finished"
138         fi
139         echo -n " map compile of $map ($url): $time sec"
140         if [ -n "$s_samplesize" ]; then
141                 echo -n ", FIX samplesize >= $s_samplesize"
142         fi
143         if [ -n "$s_failshaders" ]; then
144                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
145                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
146                 fi
147                 echo -n ", FIX shaders $s_failshaders"
148         fi
149         if [ -n "$s_leaked" ]; then
150                 echo -n ", FIX LEAK"
151         fi
152         if [ -n "$s_error" ]; then
153                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
154                 echo -n ", ERROR: $s_error"
155         fi
156         echo
157 }
158
159 buildthemap()
160 {
161         REFNAME=$1
162         url=$2
163         M=$3
164         blobhash=$4
165         commithash=$5
166         if lwp-request -m HEAD "$url$M-$blobhash.pk3"; then
167                 continue
168         fi
169
170         git reset --hard
171         git clean -xfd
172         git checkout -f "$commithash"
173
174         if [ -n "$IRCSPAM" ]; then
175                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$commithash" | $IRCSPAM
176         fi
177         t0=`date +%s`
178         (
179                 cd maps
180                 sz=`grep '^size ' "$M.mapinfo" 2>/dev/null || true`
181                 if [ -n "$sz" ]; then
182                         minimap_override="-minimap + -minmax ${sz#size }"
183                 else
184                         minimap_override=
185                 fi
186                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $minimap_override $build_override > "$M.log" 2>&1
187         )
188         status=$?
189         if ! [ -f "maps/$M.bsp" ]; then
190                 echo >>"$M.log" "ERROR: No BSP file"
191         fi
192         t1=`date +%s`
193         dt=$(($t1 - $t0))
194         if [ -n "$IRCSPAM" ]; then
195                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$commithash" "$status" "$dt" > "maps/$M.irc"
196         fi
197         zip -9r "$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
198         ln -snf "../$M-$blobhash.pk3" "$M.pk3" # from ALL branches, so beware!
199         cp "$M-$blobhash.pk3" "$M-full-$blobhash.pk3"
200         zip -9r "$M-full-$blobhash.pk3" `git diff --name-only --diff-filter=ACMRTUXB master...HEAD` || true
201         ln -snf "../$M-full-$blobhash.pk3" "$M-full.pk3" # from ALL branches, so beware!
202         rsync -vaSHP "$M-$blobhash.pk3" "$M-full-$blobhash.pk3" "$url_ssh"
203         rsync -vaSHP "$M.pk3" "$M-full.pk3" "$url_ssh""latest/"
204         if [ -n "$IRCSPAM" ]; then
205                 $IRCSPAM < "maps/$M.irc"
206         fi
207 }
208
209 screenshotthemap()
210 {
211         REFNAME=$1
212         url=$2
213         M=$3
214         blobhash=$4
215         commithash=$5
216         if lwp-request -m HEAD "$url$M-$blobhash/"; then
217                 continue
218         fi
219
220         if ! unzip -l "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp"; then
221                 # no BSP file
222                 continue
223         fi
224
225         rm -rf ~/.xonotic
226         (
227                 cd ../..
228                 if [ -n "$DISPLAY" ]; then
229                         misc/tools/xonotic-map-screenshot "$M" $screenshot_override $DRIVERFLAGS +"scr_screenshot_name \"$M-\""
230                 else
231                         case "$DRIVER" in
232                                 gl)
233                                         startx "$PWD/misc/tools/xonotic-map-screenshot" "$M" $screenshot_override $DRIVERFLAGS +"scr_screenshot_name \"$M-\"" -- :8
234                                         ;;
235                                 soft|*)
236                                         startx "$PWD/misc/tools/xonotic-map-screenshot" "$M" $screenshot_override +"vid_soft 1" $DRIVERFLAGS +"scr_screenshot_name \"$M-\"" -- /usr/bin/Xvfb :8 -screen 0 1024x768x24
237                                         ;;
238                         esac
239                 fi
240         ) >~/.xonotic/autoscreenshot.log 2>&1
241         if ! mv ~/.xonotic/data/screenshots "$M-$blobhash"; then
242                 if [ -n "$IRCSPAM" ]; then
243                         #ss2spam "$M" "$url$M-$blobhash/" "$REFNAME" "$commithash" 1 > "maps/$M.ircss"
244                         ss2spam "$M" "$url?d" "$REFNAME" "$commithash" 1 > "maps/$M.ircss"
245                 fi
246                 return 1
247         fi
248         mv ~/.xonotic/autoscreenshot.log "$M-$blobhash"/ || true
249         if [ -n "$IRCSPAM" ]; then
250                 #ss2spam "$M" "$url$M-$blobhash/" "$REFNAME" "$commithash" 0 > "maps/$M.ircss"
251                 ss2spam "$M" "$url?d" "$REFNAME" "$commithash" 0 > "maps/$M.ircss"
252         fi
253         chmod 1777 "$M-$blobhash"
254         ln -snf "../$M-$blobhash" "$M" # from ALL branches, so beware!
255         rsync -vaSHP "$M-$blobhash" "$url_ssh"
256         rsync -vaSHP "$M" "$url_ssh""latest/"
257         if [ -n "$IRCSPAM" ]; then
258                 $IRCSPAM < "maps/$M.ircss"
259         fi
260 }
261
262 getthemap()
263 {
264         url=$1
265         bspdir_old=$2
266         bspdir=$3
267         M=$4
268         blobhash=$5
269         commithash=$6
270         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
271                 if unzip -l "$bspdir/$M-$blobhash.pk3" >/dev/null 2>&1; then
272                         return 0
273                 fi
274         fi
275         if ! wget -c -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
276                 if ! curl -o "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
277                         rm -f "$bspdir/$M-$blobhash.pk3"
278                         echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
279                         getthemap_fail=true
280                         return 0
281                 fi
282         fi
283         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
284                 rm -f "$bspdir/$M-$blobhash.pk3"
285                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
286                 getthemap_fail=true
287                 return 0
288         fi
289 }
290
291 indexthemap()
292 {
293         REFNAME=$1
294         M=$2
295         blobhash=$3
296         commithash=$4
297         echo "$M $blobhash $commithash $REFNAME"
298 }
299
300 rundownload()
301 {
302         mkdir -p "$bspdir" "$bspdir.old"
303         for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
304                 if [ -e "$b" ]; then
305                         mv "$b" "$bspdir.old"/
306                 fi
307         done
308         allmaps "HEAD" getthemap "$url_http" "$bspdir.old" "$bspdir"
309 }
310
311 branches()
312 {
313         git for-each-ref 'refs/remotes' | grep -vE '    refs/remotes/([^/]*/HEAD|.*/archived/.*)$'
314 }
315
316 runmakeindex()
317 {
318         cd data/xonotic-maps.pk3dir
319         branches | while read -r HASH TYPE REFNAME; do
320                 allmaps "$HASH" indexthemap "$REFNAME"
321         done
322         cd ../..
323 }
324
325 case "$1" in
326         build)
327                 cd data/xonotic-maps.pk3dir
328                 branches | while read -r HASH TYPE REFNAME; do
329                         if [ -f "$build_cachedir/$HASH" ]; then
330                                 continue
331                         fi
332                         allmaps "$HASH" buildthemap "$REFNAME" "$url_http"
333                         touch "$build_cachedir/$HASH"
334                 done
335                 git checkout -f master
336                 ;;
337         screenshot)
338                 runmakeindex > "branches.idx.new"
339                 rsync -vaSHP "branches.idx.new" "$url_ssh""branches.idx.new"
340                 rm -f "branches.idx.new"
341                 cd data/xonotic-maps.pk3dir
342                 branches | while read -r HASH TYPE REFNAME; do
343                         if [ -f "$screenshot_cachedir/$HASH" ]; then
344                                 continue
345                         fi
346
347                         git reset --hard
348                         git clean -xfd
349                         git checkout -f "$HASH"
350
351                         rundownload
352                         if $getthemap_fail; then
353                                 continue
354                         fi
355
356                         allmaps "$HASH" screenshotthemap "$REFNAME" "$url_http"
357
358                         touch "$screenshot_cachedir/$HASH"
359                 done
360                 git checkout -f master
361                 ;;
362         makeindex)
363                 runmakeindex
364                 ;;
365         download)
366                 if ! cd data/xonotic-maps.pk3dir >/dev/null 2>&1; then
367                         echo "data/xonotic-maps.pk3dir does not exist, not downloading"
368                         exit 0
369                 fi
370                 rundownload
371                 cd ../..
372                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
373                 ls -l "$bspdir.old" || true
374                 ;;
375         download-latest)
376                 mkdir -p "$bspdir"
377                 cd "$bspdir"
378                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
379                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url_http""latest"
380                 ;;
381         log2spam-test)
382                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
383                 ;;
384 esac