]> git.xonotic.org Git - xonotic/gmqcc.git/blob - misc/check-proj.sh
80d3ee2e7e27571f3a5009fbc4cc3a8e65f0f448
[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
8 #download required things
9 download_list=$(wget -qO- ${list})
10 download_hashes=$(wget -qO- ${hashes})
11
12 download() {
13     pushd ~/.gmqcc/testsuite >> /dev/null
14     echo "$download_list" | while read -r line
15     do
16         echo "downloading $line ..."
17         wget -q "${location}/$line"
18     done
19
20     echo "$download_hashes" > ~/.gmqcc/testsuite/hashes
21     popd >> /dev/null
22 }
23
24 if [ -z "$download_list" -o -z "$download_hashes" ]; then
25     echo "failed to download required information to check projects."
26
27     if [ "$(ping -q -c1 "${host}")" ]; then
28         echo "host ${host} seems to be up but missing required files."
29         echo "please file bug report at: github.com/graphitemaster/gmqcc"
30     else
31         echo "host ${host} seems to be down, please try again later."
32     fi
33
34     echo "aborting"
35     exit 1
36 fi
37
38 # we have existing contents around
39 if [ -f ~/.gmqcc/testsuite/hashes ]; then
40     echo "$download_hashes" > /tmp/gmqcc_download_hashes
41     diff -u ~/.gmqcc/testsuite/hashes /tmp/gmqcc_download_hashes >> /dev/null
42     if [ $? -ne 0 ]; then
43         echo "consistency errors in hashes (possible update), obtaining fresh contents"
44         rm -rf ~/.gmqcc/testsuite/projects
45         rm ~/.gmqcc/testsuite/*.zip
46
47         download
48     fi
49 else
50     # do we even have the directory
51     echo "preparing project testsuite for the first time"
52     if [ ! -d ~/.gmqcc/testsuite ]; then
53         mkdir -p ~/.gmqcc/testsuite
54     fi
55
56     download
57 fi
58
59 if [ ! -d ~/.gmqcc/testsuite/projects ]; then
60     mkdir -p ~/.gmqcc/testsuite/projects
61     pushd ~/.gmqcc/testsuite/projects >> /dev/null
62     echo "$(ls ../ | cat | grep -v '^hashes$' | grep -v '^projects$')" | while read -r line
63     do
64         echo "extracting project $line"
65         mkdir "$(echo "$line" | sed 's/\(.*\)\..*/\1/')"
66         unzip -qq "../$line" -d $(echo "$line" | sed 's/\(.*\)\..*/\1/')
67     done
68     popd >> /dev/null
69 else
70     echo "previous state exists, using it"
71 fi
72
73 # compile projects in those directories
74 gmqcc_bin="gmqcc"
75 env -i type gmqcc 1>/dev/null 2>&1 || {
76     if [ -f ../gmqcc ]; then
77         echo "found previous build of gmqcc, using it"
78         gmqcc_bin="$(pwd)/../gmqcc"
79     else
80         echo "gmqcc not installed, and previous build doesn't exist"
81         echo "please run make, or make install"
82         exit 1
83     fi
84 }
85
86 pushd ~/.gmqcc/testsuite/projects >> /dev/null
87 find . -maxdepth 1 -mindepth 1 -type d -printf "%f\n" | while read -r line
88 do
89     echo -n "compiling $line... "
90     pushd "$line" >> /dev/null
91     "$gmqcc_bin" -std=qcc > /dev/null 2>&1
92     if [ $? -ne 0 ]; then
93         echo "error"
94     else
95         echo "success"
96     fi
97
98     popd >> /dev/null
99 done
100 popd >> /dev/null