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