]> de.git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/xonotic-map-compiler-autobuild
Foo. Fixed.
[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 3600 -vis_timeout 10800 -light_timeout 18000 -minimap_timeout 900 -scale_timeout 900 -timeout_stealing 0.75"
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 || true
176         fi
177
178         t0=`date +%s`
179
180         # It's sad that we must enforce this rule by code.
181         if grep -- '-nosRGB' "maps/$M.map.options" >/dev/null; then
182                 is_nosrgb=true
183         else
184                 is_nosrgb=false
185         fi
186         allow_build=true
187         case "$map" in
188                 afterslime|dance|drain|glowplant|leave_em_behind|newtonian-nightmare|nexballarena|oilrig|red-planet|runningmanctf|runningman|space-elevator|stormkeep|techassault|xoylent)
189                         if ! $is_nosrgb; then
190                                 if [ -n "$IRCSPAM" ]; then
191                                         echo "CONGRATULATIONS: map $map does not use -nosRGB any more. Please remove the map name from the list in xonotic-map-compiler-autobuild once this is merged to master." | $IRCSPAM || true
192                                 fi
193                         fi
194                         ;;
195                 *)
196                         if $is_nosrgb; then
197                                 case "$REFNAME" in
198                                         master|refs/heads/master|origin/master|refs/remotes/origin/master)
199                                                 if [ -n "$IRCSPAM" ]; then
200                                                         echo "\ 34ERROR: map $map uses -nosRGB. This is not acceptable in master. Please fix." | $IRCSPAM || true
201                                                 fi
202                                                 allow_build=false
203                                                 ;;
204                                         *)
205                                                 if [ -n "$IRCSPAM" ]; then
206                                                         echo "\ 34WARNING:\ f map $map uses -nosRGB. This is not acceptable in master. Please fix." | $IRCSPAM || true
207                                                 fi
208                                                 ;;
209                                 esac
210                         fi
211                         ;;
212         esac
213
214         set +e
215         $allow_build && (
216                 cd ../..
217                 misc/tools/xonotic-map-compiler-optionsfile "data/xonotic-maps.pk3dir/maps/$M" $build_override > "data/xonotic-maps.pk3dir/maps/$M.log" 2>&1
218         )
219         status=$?
220         set -e
221         if ! [ -f "maps/$M.bsp" ]; then
222                 echo >>"maps/$M.log" "ERROR: No BSP file"
223         fi
224         t1=`date +%s`
225         dt=$(($t1 - $t0))
226         if [ -n "$IRCSPAM" ]; then
227                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$commithash" "$status" "$dt" > "maps/$M.irc"
228         fi
229         zip -9r "$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
230         ln -snf "../$M-$blobhash.pk3" "$M.pk3" # from ALL branches, so beware!
231         cp "$M-$blobhash.pk3" "$M-full-$blobhash.pk3"
232         zip -9r "$M-full-$blobhash.pk3" `git diff --name-only --diff-filter=ACMRTUXB master...HEAD` || true
233         ln -snf "../$M-full-$blobhash.pk3" "$M-full.pk3" # from ALL branches, so beware!
234         rsync -vaSHP "$M-$blobhash.pk3" "$M-full-$blobhash.pk3" "$url_ssh"
235         rsync -vaSHP "$M.pk3" "$M-full.pk3" "$url_ssh""latest/"
236         if [ -n "$IRCSPAM" ]; then
237                 $IRCSPAM < "maps/$M.irc" || true
238         fi
239         if [ -n "$BUILD_ONE" ]; then
240                 exit
241         fi
242 }
243
244 screenshotthemap()
245 {
246         REFNAME=$1
247         url=$2
248         M=$3
249         blobhash=$4
250         commithash=$5
251         if lwp-request -m HEAD "$url$M-$blobhash/$M-000000.jpg"; then
252                 continue
253         fi
254
255         if ! unzip -l "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp"; then
256                 # no BSP file
257                 continue
258         fi
259
260         rm -rf ~/.xonotic/data
261         mkdir -p ~/.xonotic/data
262         (
263                 cd ../..
264                 if [ -n "$DISPLAY" ]; then
265                         misc/tools/xonotic-map-screenshot "$M" $screenshot_override $DRIVERFLAGS +"scr_screenshot_name \"$M-\""
266                 else
267                         case "$DRIVER" in
268                                 gl)
269                                         startx "$PWD/misc/tools/xonotic-map-screenshot" "$M" $screenshot_override $DRIVERFLAGS +"scr_screenshot_name \"$M-\"" -- :8
270                                         ;;
271                                 soft|*)
272                                         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
273                                         ;;
274                         esac
275                 fi
276         ) 2>&1 | tee ~/.xonotic/data/autoscreenshot.log
277         good=false
278         if mv ~/.xonotic/data/screenshots "$M-$blobhash"; then
279                 ss2spam "$M" "$url?d" "$REFNAME" "$commithash" 0 > ~/.xonotic/data/"$M.ircss"
280         else
281                 mkdir "$M-$blobhash"
282                 ss2spam "$M" "$url?d" "$REFNAME" "$commithash" 1 > ~/.xonotic/data/"$M.ircss"
283         fi
284         mv ~/.xonotic/data/"$M.ircss" "$M-$blobhash"/
285         mv ~/.xonotic/data/autoscreenshot.log "$M-$blobhash"/
286         chmod 1777 "$M-$blobhash"
287         ln -snf "../$M-$blobhash" "$M" # from ALL branches, so beware!
288         rsync -vaSHP "$M-$blobhash" "$url_ssh"
289         rsync -vaSHP "$M" "$url_ssh""latest/"
290         if [ -n "$IRCSPAM" ]; then
291                 $IRCSPAM < "$M-$blobhash/$M.ircss" || true
292         fi
293         if [ -n "$BUILD_ONE" ]; then
294                 exit
295         fi
296 }
297
298 getthemap()
299 {
300         url=$1
301         bspdir_old=$2
302         bspdir=$3
303         M=$4
304         blobhash=$5
305         commithash=$6
306         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
307                 if unzip -l "$bspdir/$M-$blobhash.pk3" >/dev/null 2>&1; then
308                         return 0
309                 fi
310         fi
311         if ! wget -c -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
312                 if ! curl -o "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
313                         rm -f "$bspdir/$M-$blobhash.pk3"
314                         echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
315                         getthemap_fail=true
316                         return 0
317                 fi
318         fi
319         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
320                 rm -f "$bspdir/$M-$blobhash.pk3"
321                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
322                 getthemap_fail=true
323                 return 0
324         fi
325 }
326
327 indexthemap()
328 {
329         REFNAME=$1
330         M=$2
331         blobhash=$3
332         commithash=$4
333         echo "$M $blobhash $commithash $REFNAME"
334 }
335
336 rundownload()
337 {
338         mkdir -p "$bspdir" "$bspdir.old"
339         for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
340                 if [ -e "$b" ]; then
341                         mv "$b" "$bspdir.old"/
342                 fi
343         done
344         allmaps "HEAD" getthemap "$url_http" "$bspdir.old" "$bspdir"
345 }
346
347 branches()
348 {
349         git for-each-ref 'refs/remotes' | grep -vE '    refs/remotes/([^/]*/HEAD|.*/archived/.*)$'
350 }
351
352 runmakeindex()
353 {
354         cd data/xonotic-maps.pk3dir
355         branches | while read -r HASH TYPE REFNAME; do
356                 allmaps "$HASH" indexthemap "$REFNAME"
357         done
358         cd ../..
359 }
360
361 case "$1" in
362         build)
363                 cd data/xonotic-maps.pk3dir
364                 branches | while read -r HASH TYPE REFNAME; do
365                         if [ -f "$build_cachedir/$HASH" ]; then
366                                 continue
367                         fi
368                         allmaps "$HASH" buildthemap "$REFNAME" "$url_http"
369                         touch "$build_cachedir/$HASH"
370                 done
371                 git checkout -f master
372                 ;;
373         screenshot)
374                 runmakeindex > "branches.idx.new"
375                 rsync -vaSHP "branches.idx.new" "$url_ssh""branches.idx.new"
376                 rm -f "branches.idx.new"
377                 cd data/xonotic-maps.pk3dir
378                 branches | while read -r HASH TYPE REFNAME; do
379                         if [ -f "$screenshot_cachedir/$HASH" ]; then
380                                 continue
381                         fi
382
383                         git reset --hard
384                         git clean -xfd
385                         git checkout -f "$HASH"
386
387                         rundownload
388                         if $getthemap_fail; then
389                                 continue
390                         fi
391
392                         allmaps "$HASH" screenshotthemap "$REFNAME" "$url_http"
393
394                         touch "$screenshot_cachedir/$HASH"
395                 done
396                 git checkout -f master
397                 ;;
398         makeindex)
399                 runmakeindex
400                 ;;
401         download)
402                 if ! which unzip >/dev/null 2>&1; then
403                         echo "Cannot find unzip, bailing out"
404                         exit 1
405                 fi
406                 if ! cd data/xonotic-maps.pk3dir >/dev/null 2>&1; then
407                         echo "data/xonotic-maps.pk3dir does not exist, not downloading"
408                         exit 0
409                 fi
410                 rundownload
411                 cd ../..
412                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
413                 ls -l "$bspdir.old" || true
414                 ;;
415         download-latest)
416                 mkdir -p "$bspdir"
417                 cd "$bspdir"
418                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
419                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url_http""latest"
420                 ;;
421         log2spam-test)
422                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
423                 ;;
424 esac