also make a foo-full-HASH.pk3 when building a map that also contains files of the...
[xonotic/xonotic.git] / misc / tools / xonotic-map-compiler-autobuild
1 #!/bin/sh
2
3 set -e
4
5 bspdir="$PWD/data"
6 url=http://beta.xonotic.org/autobuild-bsp/
7 url_ssh=xonotic-beta:autobuild-bsp/
8 cachedir="$HOME/xonotic-map-compiler.cache/"
9 override="-bsp_timeout 900 -vis_timeout 3600 -light_timeout 14400 -minimap_timeout 900 -scale_timeout 900"
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         M=$4
120         blobhash=$5
121         if HEAD "$url$M-$blobhash.pk3"; then
122                 continue
123         fi
124         if [ -n "$IRCSPAM" ]; then
125                 pre2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" | $IRCSPAM
126         fi
127         t0=`date +%s`
128         (
129                 cd maps
130                 ../../../misc/tools/xonotic-map-compiler "$M" `grep ^- "$M.map.options" | cut -d '#' -f 1` $override > "$M.log"
131         )
132         t1=`date +%s`
133         dt=$(($t1 - $t0))
134         status=$?
135         if [ -n "$IRCSPAM" ]; then
136                 cat "maps/$M.log" | log2spam "$M" "$url$M-$blobhash.pk3" "$REFNAME" "$HASH" "$status" "$dt" > "maps/$M.irc"
137         fi
138         zip -9r "$M-$blobhash.pk3" "maps/$M.bsp" "maps/$M.log" "maps/$M.irc" "maps/$M/" "maps/$M.lin" "gfx/${M}_mini.tga"
139         ln -snf "../$M-$blobhash.pk3" "$M.pk3" # from ALL branches, so beware!
140         cp "$M-$blobhash.pk3" "$M-full-$blobhash.pk3"
141         zip -9r "$M-full-$blobhash.pk3" `git diff --name-only --diff-filter=ACMRTUXB master...HEAD` || true
142         ln -snf "../$M-full-$blobhash.pk3" "$M-full.pk3" # from ALL branches, so beware!
143         rsync -vaSHP "$M-$blobhash.pk3" "$M-full-$blobhash.pk3" "$url_ssh"
144         rsync -vaSHP "$M.pk3" "$M-full.pk3" "$url_ssh""latest/"
145         if [ -n "$IRCSPAM" ]; then
146                 $IRCSPAM < "maps/$M.irc"
147         fi
148 }
149
150 getthemap()
151 {
152         url=$1
153         bspdir_old=$2
154         bspdir=$3
155         M=$4
156         blobhash=$5
157         if mv "$bspdir_old/$M-$blobhash.pk3" "$bspdir/$M-$blobhash.pk3"; then
158                 continue
159         fi
160         if ! wget -O "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
161                 if ! curl -o "$bspdir/$M-$blobhash.pk3" "$url$M-$blobhash.pk3"; then
162                         rm -f "$bspdir/$M-$blobhash.pk3"
163                         echo "WARNING: could not download $url$M-$blobhash.pk3, maybe not ready yet"
164                         return 0
165                 fi
166         fi
167         if ! unzip -l "$bspdir/$M-$blobhash.pk3"; then
168                 rm -f "$bspdir/$M-$blobhash.pk3"
169                 echo "WARNING: could not download $url$M-$blobhash.pk3, invalid zip file"
170                 return 0
171         fi
172 }
173
174 case "$1" in
175         build)
176                 cd data/xonotic-maps.pk3dir
177                 git for-each-ref 'refs/remotes' | while read -r HASH TYPE REFNAME; do
178                         if [ -f "$cachedir/$HASH" ]; then
179                                 continue
180                         fi
181                         git reset --hard
182                         git clean -xfd
183                         git checkout -f "$HASH"
184                         allmaps buildthemap "$REFNAME" "$HASH" "$url"
185                         touch "$cachedir/$HASH"
186                 done
187                 git checkout -f master
188                 ;;
189         download)
190                 mkdir -p "$bspdir" "$bspdir.old"
191                 for b in "$bspdir"/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
192                         if [ -e "$b" ]; then
193                                 mv "$b" "$bspdir.old"/
194                         fi
195                 done
196                 cd data/xonotic-maps.pk3dir
197                 allmaps getthemap "$url" "$bspdir.old" "$bspdir"
198                 echo "List of maps that got deleted (if any) and currently are in $bspdir.old:"
199                 ls -l "$bspdir.old"
200                 ;;
201         download-latest)
202                 mkdir -p "$bspdir"
203                 cd "$bspdir"
204                 rm -f *-????????????????????????????????????????-????????????????????????????????????????.pk3
205                 wget -r -l1 -A "*.pk3" -N --no-parent --no-directories "$url""latest"
206                 ;;
207         log2spam-test)
208                 log2spam "mapname" "http://mapurl" "branch" "commit" "0"
209                 ;;
210 esac