From 8ab43d1ba8ac134b4b077261e68f1051d089c67d Mon Sep 17 00:00:00 2001 From: Michael Wetherell Date: Tue, 5 Feb 2008 18:10:14 +0000 Subject: [PATCH] Clean up the tools for offline checking of the configuration. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51561 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build/buildbot/tools/bot.xsd | 10 ++ build/buildbot/tools/check.sh | 158 +++++++++++++++++++++++++++++ build/buildbot/tools/embedded.xsl | 36 ++----- build/buildbot/tools/preprocess.sh | 23 ----- build/buildbot/tools/validate.sh | 65 ------------ 5 files changed, 179 insertions(+), 113 deletions(-) create mode 100755 build/buildbot/tools/check.sh delete mode 100755 build/buildbot/tools/preprocess.sh delete mode 100755 build/buildbot/tools/validate.sh diff --git a/build/buildbot/tools/bot.xsd b/build/buildbot/tools/bot.xsd index f19fbc1c36..c340d2e460 100644 --- a/build/buildbot/tools/bot.xsd +++ b/build/buildbot/tools/bot.xsd @@ -1,4 +1,14 @@ + + + diff --git a/build/buildbot/tools/check.sh b/build/buildbot/tools/check.sh new file mode 100755 index 0000000000..0a734558d1 --- /dev/null +++ b/build/buildbot/tools/check.sh @@ -0,0 +1,158 @@ +#!/bin/sh +############################################################################# +# Name: check.sh +# Purpose: Check embedded xslt +# Author: Mike Wetherell +# RCS-ID: $Id$ +# Copyright: (c) 2007 Mike Wetherell +# Licence: wxWidgets licence +############################################################################# + +usage() { + echo "Usage: $0 [options] FILE..." + echo "Check embedded xslt" + echo + echo "Options:" + echo " -g generate xslt" + echo " -h show help" + echo " -l N output only line N" + echo " -p preprocess" + echo " -v validate" + exit 0 +} + +badopt() { + echo "try '$0 -h' for more information" >&2 + exit 1 +} + +GENERATE=1 +PREPROCESS=2 +VALIDATE=3 + +MODE=$VALIDATE +FILTER=cat + +while getopts ghl:pv opt; do + case "$opt" in + \?) badopt ;; + g) MODE=$GENERATE ;; + h) usage ;; + l) FILTER="sed -ne ${OPTARG}p" ;; + p) MODE=$PREPROCESS ;; + v) MODE=$VALIDATE ;; + esac +done + +if [ $OPTIND -gt 1 ]; then + shift `expr $OPTIND - 1` +fi + +if [ $# -eq 0 ]; then + usage +fi + +DIR="`dirname $0`" +WORKDIR="${TMPDIR:-/tmp}/wx.$$" +mkdir "$WORKDIR" || exit +trap 'rm -rf "$WORKDIR"' EXIT +WORKPAT=`echo "$WORKDIR" | sed 's|[^A-Za-z0-9]/|.|g'` +XSLT="$WORKDIR/XSLT" +PREP="$WORKDIR/PREP" +STDERR="$WORKDIR/STDERR" +ERR=0 + +# Change the names of the temporary files in an error message to something +# to something more informative +errout() +{ + NAME="$1" + + if [ -s "$STDERR" ]; then + sed "s|file ${WORKPAT}|${WORKPAT}|g;\ + s|${WORKPAT}/XSLT|generated XSLT|g;\ + s|${WORKPAT}/PREP|$NAME (preprocessed)|g" "$STDERR" | + awk '{ + print; + if (sub(/.*generated XSLT line */, "") && sub(/[^0-9].*/, "")) + { + system("sed -ne "$0"p '$XSLT'"); + } + }' + fi +} + +output() +{ + $FILTER "$1" +} + +generate() +{ + INPUT="$1" + + if xsltproc --xinclude -o "$XSLT" $DIR/embedded.xsl "$INPUT" 2>"$STDERR" && + test \! -s "$STDERR" + then + if [ $MODE -eq $GENERATE ]; then + output "$XSLT" + fi + else + return 1 + fi +} + +preprocess() +{ + INPUT="$1" + + if [ $MODE -lt $PREPROCESS ]; then + return 0 + fi + + if xsltproc --xinclude -o "$PREP" "$XSLT" "$INPUT" 2>"$STDERR" && + test \! -s "$STDERR" + then + if [ $MODE -eq $PREPROCESS ]; then + output "$PREP" + fi + else + return 1 + fi +} + +validate() +{ + NAME="$1" + + if [ $MODE -lt $VALIDATE ]; then + return 0 + fi + + if xmllint --noout --schema $DIR/bot.xsd "$PREP" 2>"$STDERR" + then + errout "$NAME" + else + return 1 + fi +} + +while [ $# -gt 0 ]; do + INPUT="$1" + NAME="`echo \"$INPUT\" | sed 's/[|\]/\\\&/g'`" + + { + generate "$INPUT" && + preprocess "$INPUT" && + validate "$NAME" + } || { + errout "$NAME" >&2 + ERR=1 + } + + rm -f "$XSLT" "$PREP" "$STDERR" + + shift +done + +exit $ERR diff --git a/build/buildbot/tools/embedded.xsl b/build/buildbot/tools/embedded.xsl index ca192823cc..29e31d6d5f 100644 --- a/build/buildbot/tools/embedded.xsl +++ b/build/buildbot/tools/embedded.xsl @@ -2,7 +2,7 @@