Merge branch 'master' into divVerent/crypto2
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -e
4
5 bspdir="$PWD/data"
6 url=http://141.2.16.23/~xonotic/bsp-autobuilds/
7 override="-bsp_timeout 900 -vis_timeout 3600 -light_timeout 14400 -minimap_timeout 900 -scale_timeout 900"
8
9 bspoutdir="$HOME/public_html/bsp-autobuilds/"
10
11 allmaps()
12 {
13         for F in maps/*.map.options; do
14                 if ! [ -f "$F" ]; then
15                         continue
16                 fi
17                 if ! [ -f "${F%.options}" ]; then
18                         continue
19                 fi
20                 M=${F#maps/}
21                 M=${M%.map.options}
22                 blobhash=`git ls-files -s -- "$F" | cut -d ' ' -f 2`-`git ls-files -s -- "${F%.options}" | cut -d ' ' -f 2`
23                 "$@" "$M" "$blobhash"
24         done
25 }
26
27 pre2spam()
28 {
29         map=$1
30         url=$2
31         branch=$3
32         hash=$4
33
34         branch=${branch##refs/heads/}
35         branch=${branch##refs/remotes/}
36         branch=${branch##origin/}
37         hash=`echo "$hash" | cut -c 1-7`
38
39         echo "[$branch $hash] starting map compile of $map"
40 }
41
42 log2spam()
43 {
44         map=$1
45         url=$2
46         branch=$3
47         hash=$4
48         status=$5
49         time=$6
50
51         hash=`echo "$hash" | cut -c 1-7`
52
53         branch=${branch##refs/heads/}
54         branch=${branch##refs/remotes/}
55         branch=${branch##origin/}
56
57         s_samplesize=
58         s_failshaders=
59         s_leaked=
60         s_error=
61
62         if [ "$status" -ne 0 ]; then
63                 s_error="exited with status $status"
64         fi
65         while IFS= read -r L; do
66                 case "$L" in
67                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
68                                 s=${L##* }
69                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
70                                         s_samplesize=$s
71                                 fi
72                                 ;;
73                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
74                                 # radiant stupid
75                                 ;;
76                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
77                                 s_failshaders="$s_failshaders ${L##* }"
78                                 ;;
79                         '******* leaked *******')
80                                 s_leaked=1
81                                 ;;
82                         '************ ERROR ************')
83                                 IFS= read -r s_error
84                                 ;;
85                 esac
86         done
87         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
88         s_failshaders=${s_failshaders# }
89         if [ -n "$s_error" ]; then
90                 echo -n "[$branch $hash] \ 34failed"
91         else
92                 echo -n "[$branch $hash] finished"
93         fi
94         echo -n " map compile of $map ($url): $time sec"
95         if [ -n "$s_samplesize" ]; then
96                 echo -n ", FIX samplesize >= $s_samplesize"
97         fi
98         if [ -n "$s_failshaders" ]; then
99                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
100                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
101                 fi
102                 echo -n ", FIX shaders $s_failshaders"
103         fi
104         if [ -n "$s_leaked" ]; then
105                 echo -n ", FIX LEAK"
106         fi
107         if [ -n "$s_error" ]; then
108                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
109                 echo -n ", ERROR: $s_error"
110         fi
111         echo
112 }
113
114 buildthemap()
115 {
116         REFNAME=$1
117         HASH=$2
118         url=$3
119         bspdir=$4
120         M=$5
121         blobhash=$6
122         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
123                 continue
124         fi
125         if [ -n "$IRCSPAM" ]; then
126                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
127         fi
128         t0=`date +%s`
129         (
130                 cd maps
131                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $override > "$M.log"
132         )
133         t1=`date +%s`
134         dt=$(($t1 - $t0))
135         status=$?
136         if [ -n "$IRCSPAM" ]; then
137                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" "$dt" > "maps/$M.irc"
138         fi
139         zip -9r "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
140         ln -snf "../$M-$blobhash.pk3" "$bspdir/latest/$M.pk3" # from ALL branches, so beware!
141         if [ -n "$IRCSPAM" ]; then
142                 $IRCSPAM < "maps/$M.irc"
143         fi
144 }
145
146 getthemap()
147 {
148         url=$1
149         bspdir_old=$2
150         bspdir=$3
151         M=$4
152         blobhash=$5
153         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
154                 continue
155         fi
156         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
157                 rm -f "$bspdir/$M-$blobhash.pk3"
158                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
159                 return 0
160         fi
161         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
162                 rm -f "$bspdir/$M-$blobhash.pk3"
163                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
164                 return 0
165         fi
166 }
167
168 case "$1" in
169         build)
170                 mkdir -p "$bspoutdir"
171                 mkdir -p "$bspoutdir/latest"
172                 cd data/xonotic-maps.pk3dir
173                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
174                         git reset --hard
175                         git clean -xfd
176                         git checkout "$HASH"
177                         allmaps buildthemap "$REFNAME" "$HASH" "$url" "$bspoutdir"
178                 done
179                 git checkout master
180                 ;;
181         download)
182                 mkdir -p "$bspdir" "$bspdir.old"
183                 for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
184                         if [ -e "$b" ]; then
185                                 mv "$b" "$bspdir.old"/
186                         fi
187                 done
188                 cd data/xonotic-maps.pk3dir
189                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
190                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
191                 ls -l "$bspdir.old"
192                 ;;
193         download-latest)
194                 mkdir -p "$bspdir"
195                 cd "$bspdir"
196                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
197                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
198                 ;;
199         log2spam-test)
200                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
201                 ;;
202 esac