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