9534301ee0683b3fda07191d9cfcccfb6b7b20c4
[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
50         branch=${branch##refs/heads/}
51         branch=${branch##refs/remotes/}
52         branch=${branch##origin/}
53
54         s_time=
55         s_samplesize=
56         s_failshaders=
57         s_leaked=
58         s_error=
59
60         if [ "$status" -ne 0 ]; then
61                 s_error="exited with status $status"
62         fi
63         while IFS= read -r L; do
64                 case "$L" in
65                         *\ seconds\ elapsed)
66                                 s_time=$(($s_time + ${L%% seconds elapsed}))
67                                 ;;
68                         WARNING:\ surface\ at\ *\ too\ large\ for\ desired\ samplesize*)
69                                 s=${L##* }
70                                 if [ -z "$s_samplesize" ] || [ "$s" -gt "$s_samplesize" ]; then
71                                         s_samplesize=$s
72                                 fi
73                                 ;;
74                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ textures/NULL)
75                                 # radiant stupid
76                                 ;;
77                         WARNING:\ Couldn\'t\ find\ image\ for\ shader\ *)
78                                 s_failshaders="$s_failshaders ${L##* }"
79                                 ;;
80                         '******* leaked *******')
81                                 s_leaked=1
82                                 ;;
83                         '************ ERROR ************')
84                                 IFS= read -r s_error
85                                 ;;
86                 esac
87         done
88         s_failshaders=`echo "$s_failshaders" | sed "s, textures/, ,g"`
89         s_failshaders=${s_failshaders# }
90         if [ -n "$s_error" ]; then
91                 echo -n "[$branch $hash] \ 34failed"
92         else
93                 echo -n "[$branch $hash] finished"
94         fi
95         echo -n " map compile of $map ($url): $s_time sec"
96         if [ -n "$s_samplesize" ]; then
97                 echo -n ", FIX samplesize >= $s_samplesize"
98         fi
99         if [ -n "$s_failshaders" ]; then
100                 if [ -n "`echo "$s_failshaders" | cut -d ' ' -f 4-`" ]; then
101                         s_failshaders="`echo "$s_failshaders" | cut -d ' ' -f 1-3`..."
102                 fi
103                 echo -n ", FIX shaders $s_failshaders"
104         fi
105         if [ -n "$s_leaked" ]; then
106                 echo -n ", FIX LEAK"
107         fi
108         if [ -n "$s_error" ]; then
109                 s_error=`echo "$s_error" | sed "s,$PWD/\?,,g"`
110                 echo -n ", ERROR: $s_error"
111         fi
112         echo
113 }
114
115 buildthemap()
116 {
117         REFNAME=$1
118         HASH=$2
119         url=$3
120         bspdir=$4
121         M=$5
122         blobhash=$6
123         if [ -f "$bspdir/$M-$blobhash.pk3" ]; then
124                 continue
125         fi
126         if [ -n "$IRCSPAM" ]; then
127                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
128         fi
129         (
130                 cd maps
131                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $override > "$M.log"
132         )
133         status=$?
134         if [ -n "$IRCSPAM" ]; then
135                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" > "maps/$M.irc"
136         fi
137         zip -9r "$bspdir/$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
138         ln -snf "../$M-$blobhash.pk3" "$bspdir/latest/$M.pk3" # from ALL branches, so beware!
139         if [ -n "$IRCSPAM" ]; then
140                 $IRCSPAM < "maps/$M.irc"
141         fi
142 }
143
144 getthemap()
145 {
146         url=$1
147         bspdir_old=$2
148         bspdir=$3
149         M=$4
150         blobhash=$5
151         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
152                 continue
153         fi
154         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
155                 rm -f "$bspdir/$M-$blobhash.pk3"
156                 echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
157                 return 0
158         fi
159         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
160                 rm -f "$bspdir/$M-$blobhash.pk3"
161                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
162                 return 0
163         fi
164 }
165
166 case "$1" in
167         build)
168                 mkdir -p "$bspoutdir"
169                 mkdir -p "$bspoutdir/latest"
170                 cd data/xonotic-maps.pk3dir
171                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
172                         git reset --hard
173                         git clean -xfd
174                         git checkout "$HASH"
175                         allmaps buildthemap "$REFNAME" "$HASH" "$url" "$bspoutdir"
176                 done
177                 git checkout master
178                 ;;
179         download)
180                 mkdir -p "$bspdir" "$bspdir.old"
181                 mv "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3 "$bspdir.old"/ || true
182                 cd data/xonotic-maps.pk3dir
183                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
184                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
185                 ls -l "$bspdir.old"
186                 ;;
187         download-latest)
188                 mkdir -p "$bspdir"
189                 cd "$bspdir"
190                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
191                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
192                 ;;
193         log2spam-test)
194                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
195                 ;;
196 esac