]> git.xonotic.org Git - xonotic/gmqcc.git/blob - misc/check-proj.sh
b70e75f2dfdbe9c3a45f9ef0b22187ee6fd256be
[xonotic/gmqcc.git] / misc / check-proj.sh
1 #!/bin/sh
2
3 host="gmqcc.qc.to"
4 location="$host/files"
5 list="$location/files"
6 hashes="$location/hashes"
7 options="$location/options"
8
9 #download required things
10 download_list=$(wget -qO- ${list})
11 download_hashes=$(wget -qO- ${hashes})
12 download_options=$(wget -qO- ${options})
13
14 download() {
15     local old="$PWD"
16     cd ~/.gmqcc/testsuite
17     echo "$download_list" | while read -r line
18     do
19         echo "downloading $line ..."
20         wget -q "${location}/$line"
21     done
22
23     echo "$download_hashes" > ~/.gmqcc/testsuite/hashes
24     echo "$download_options" > ~/.gmqcc/testsuite/options
25
26     cd "$old"
27 }
28
29 if [ -z "$download_list" -o -z "$download_hashes" -o -z "$download_options" ]; then
30     echo "failed to download required information to check projects."
31
32     if [ "$(ping -q -c1 "${host}")" ]; then
33         echo "host ${host} seems to be up but missing required files."
34         echo "please file bug report at: github.com/graphitemaster/gmqcc"
35     else
36         echo "host ${host} seems to be down, please try again later."
37     fi
38
39     echo "aborting"
40     exit 1
41 fi
42
43 # we have existing contents around
44 if [ -f ~/.gmqcc/testsuite/hashes -a -f ~/.gmqcc/testsuite/options ]; then
45     echo "$download_hashes" > /tmp/gmqcc_download_hashes
46     echo "$download_options" > /tmp/gmqcc_download_options
47
48     diff -u ~/.gmqcc/testsuite/hashes /tmp/gmqcc_download_hashes > /dev/null
49     check_hash=$?
50     diff -u ~/.gmqcc/testsuite/options /tmp/gmqcc_download_options > /dev/null
51     check_opts=$?
52
53     if [ $check_hash -ne 0 -o $check_opts -ne 0 ]; then
54         echo "consistency errors in hashes (possible update), obtaining fresh contents"
55         rm -rf ~/.gmqcc/testsuite/projects
56         rm ~/.gmqcc/testsuite/*.zip
57
58         download
59     fi
60 else
61     # do we even have the directory
62     echo "preparing project testsuite for the first time"
63     if [ ! -d ~/.gmqcc/testsuite ]; then
64         mkdir -p ~/.gmqcc/testsuite
65     fi
66
67     download
68 fi
69
70 if [ ! -d ~/.gmqcc/testsuite/projects ]; then
71     mkdir -p ~/.gmqcc/testsuite/projects
72     old="$PWD"
73     cd ~/.gmqcc/testsuite/projects
74     echo "$(ls ../ | cat | grep -v '^hashes$' | grep -v '^projects$' | grep -v '^options$')" | while read -r line
75     do
76         echo "extracting project $line"
77         mkdir "$(echo "$line" | sed 's/\(.*\)\..*/\1/')"
78         unzip -qq "../$line" -d $(echo "$line" | sed 's/\(.*\)\..*/\1/')
79     done
80     cd "$old"
81 else
82     echo "previous state exists, using it"
83 fi
84
85 # compile projects in those directories
86 gmqcc_bin="gmqcc"
87 env -i type gmqcc 1>/dev/null 2>&1 || {
88     if [ -f ../gmqcc ]; then
89         echo "previous build of gmqcc exists, using it"
90         gmqcc_bin="$(pwd)/../gmqcc"
91     elif [ -f ./gmqcc ]; then
92         echo "previous build of gmqcc exists, using it"
93         gmqcc_bin="$(pwd)/gmqcc"
94     else
95         echo "gmqcc not installed and previous build doesn't exist"
96         echo "please run make, or make install"
97         exit 1
98     fi
99 }
100
101 end_dir="$PWD"
102 cd ~/.gmqcc/testsuite/projects
103 start="$PWD"
104 find . -maxdepth 1 -mindepth 1 -type d | while read -r line
105 do
106     line="${line#./}"
107     echo -n "compiling $line... "
108     cd "${start}/${line}"
109
110     # does the project have multiple subprojects?
111     if [ -f dirs ]; then
112         echo ""
113         cat dirs | while read -r dir
114         do
115             # change to subproject
116             echo -n "    compiling $dir... "
117             old="$PWD"
118             cd "$dir"
119             cmd="$(cat ../../../options | grep "$line:" | awk '{print substr($0, index($0, $2))}')"
120             "$gmqcc_bin" $cmd > /dev/null 2>&1
121             if [ $? -ne 0 ]; then
122                 echo "error"
123             else
124                 echo "success"
125             fi
126             cd "$old"
127         done
128     # nope only one project
129     else
130         cmd="$(cat ../../options | grep "$line:" | awk '{print substr($0, index($0, $2))}')"
131         "$gmqcc_bin" $cmd > /dev/null 2>&1
132         if [ $? -ne 0 ]; then
133             echo "error"
134         else
135             echo "success"
136         fi
137     fi
138 done
139
140 cd "$end_dir"