]> git.saurik.com Git - wxWidgets.git/blame - build/buildbot/tools/check.sh
Add more checks for Intel compiler.
[wxWidgets.git] / build / buildbot / tools / check.sh
CommitLineData
8ab43d1b
MW
1#!/bin/sh
2#############################################################################
3# Name: check.sh
e09c4c1d 4# Purpose: Offline checker for the buildbot configuration files
8ab43d1b 5# Author: Mike Wetherell
8ab43d1b 6# Copyright: (c) 2007 Mike Wetherell
526954c5 7# Licence: wxWindows licence
8ab43d1b
MW
8#############################################################################
9
10usage() {
11 echo "Usage: $0 [options] FILE..."
e09c4c1d 12 echo "Offline checker for the buildbot configuration files"
8ab43d1b
MW
13 echo
14 echo "Options:"
15 echo " -g generate xslt"
16 echo " -h show help"
17 echo " -l N output only line N"
18 echo " -p preprocess"
19 echo " -v validate"
20 exit 0
21}
22
23badopt() {
24 echo "try '$0 -h' for more information" >&2
25 exit 1
26}
27
e09c4c1d
MW
28progcheck() {
29 prog="$1"
30 $prog --version >/dev/null 2>&1 || {
31 echo "$0: requires $prog, not found" >&2
32 exit 1
33 }
34}
35
8ab43d1b
MW
36GENERATE=1
37PREPROCESS=2
38VALIDATE=3
39
40MODE=$VALIDATE
41FILTER=cat
42
43while getopts ghl:pv opt; do
44 case "$opt" in
45 \?) badopt ;;
46 g) MODE=$GENERATE ;;
47 h) usage ;;
48 l) FILTER="sed -ne ${OPTARG}p" ;;
49 p) MODE=$PREPROCESS ;;
50 v) MODE=$VALIDATE ;;
51 esac
52done
53
54if [ $OPTIND -gt 1 ]; then
55 shift `expr $OPTIND - 1`
56fi
57
58if [ $# -eq 0 ]; then
59 usage
60fi
61
e09c4c1d
MW
62XSLTPROC=xsltproc
63XMLLINT=xmllint
64
65progcheck $XSLTPROC
66progcheck $XMLLINT
67
8ab43d1b
MW
68DIR="`dirname $0`"
69WORKDIR="${TMPDIR:-/tmp}/wx.$$"
70mkdir "$WORKDIR" || exit
71trap 'rm -rf "$WORKDIR"' EXIT
72WORKPAT=`echo "$WORKDIR" | sed 's|[^A-Za-z0-9]/|.|g'`
73XSLT="$WORKDIR/XSLT"
74PREP="$WORKDIR/PREP"
75STDERR="$WORKDIR/STDERR"
76ERR=0
77
fa5a0e70
MW
78# Filter to show lines of genertated XSLT when they are mentioned.
79showxslt() {
80 awk '{
81 print;
82 if (sub(/.*generated XSLT line */, "") && sub(/[^0-9].*/, ""))
83 {
84 system("sed -ne "$0"p '$XSLT'");
85 }
86 }'
87}
88
89# Test it works as old version of awk don't have sub or system functions.
90if showxslt </dev/null 2>/dev/null; then
91 SHOWXSLT=showxslt
92else
93 SHOWXSLT=cat
94fi
95
8ab43d1b
MW
96# Change the names of the temporary files in an error message to something
97# to something more informative
98errout()
99{
100 NAME="$1"
101
102 if [ -s "$STDERR" ]; then
103 sed "s|file ${WORKPAT}|${WORKPAT}|g;\
104 s|${WORKPAT}/XSLT|generated XSLT|g;\
fa5a0e70 105 s|${WORKPAT}/PREP|$NAME (preprocessed)|g" "$STDERR" | $SHOWXSLT
8ab43d1b
MW
106 fi
107}
108
109output()
110{
111 $FILTER "$1"
112}
113
114generate()
115{
116 INPUT="$1"
117
e09c4c1d 118 if $XSLTPROC --xinclude -o "$XSLT" $DIR/embedded.xsl "$INPUT" 2>"$STDERR" &&
8ab43d1b
MW
119 test \! -s "$STDERR"
120 then
121 if [ $MODE -eq $GENERATE ]; then
122 output "$XSLT"
123 fi
124 else
125 return 1
126 fi
127}
128
129preprocess()
130{
131 INPUT="$1"
132
133 if [ $MODE -lt $PREPROCESS ]; then
134 return 0
135 fi
136
e09c4c1d 137 if $XSLTPROC --xinclude -o "$PREP" "$XSLT" "$INPUT" 2>"$STDERR" &&
8ab43d1b
MW
138 test \! -s "$STDERR"
139 then
140 if [ $MODE -eq $PREPROCESS ]; then
141 output "$PREP"
142 fi
143 else
144 return 1
145 fi
146}
d5940c63 147
8ab43d1b
MW
148validate()
149{
150 NAME="$1"
151
152 if [ $MODE -lt $VALIDATE ]; then
153 return 0
154 fi
155
e09c4c1d 156 if $XMLLINT --noout --schema $DIR/bot.xsd "$PREP" 2>"$STDERR"
8ab43d1b
MW
157 then
158 errout "$NAME"
159 else
160 return 1
161 fi
162}
163
164while [ $# -gt 0 ]; do
165 INPUT="$1"
166 NAME="`echo \"$INPUT\" | sed 's/[|\]/\\\&/g'`"
167
168 {
169 generate "$INPUT" &&
170 preprocess "$INPUT" &&
171 validate "$NAME"
172 } || {
173 errout "$NAME" >&2
174 ERR=1
175 }
d5940c63 176
8ab43d1b
MW
177 rm -f "$XSLT" "$PREP" "$STDERR"
178
179 shift
180done
181
182exit $ERR