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
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
Name: bot.xsd
|
||||
Purpose: Used by check.sh for offline checking of the configuration.
|
||||
Author: Mike Wetherell
|
||||
RCS-ID: $Id$
|
||||
Copyright: (c) 2007 Mike Wetherell
|
||||
Licence: wxWidgets licence
|
||||
-->
|
||||
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
<element name="bot">
|
||||
<!-- todo -->
|
||||
|
158
build/buildbot/tools/check.sh
Executable file
158
build/buildbot/tools/check.sh
Executable file
@@ -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
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<!--
|
||||
Name: embedded.xsl
|
||||
Purpose: Embedded XSLT
|
||||
Purpose: Used by check.sh for offline checking of the configuration.
|
||||
Author: Mike Wetherell
|
||||
RCS-ID: $Id$
|
||||
Copyright: (c) 2007 Mike Wetherell
|
||||
@@ -108,18 +108,9 @@
|
||||
<template mode="copy-xsl" match="*[//xsl:template[not(ancestor::*[name() != name(/*)])]/@name = name()]">
|
||||
<choose>
|
||||
<when test="ancestor::xsl:template[@name = name(current())]">
|
||||
<XSL:choose>
|
||||
<XSL:when test="name() = '{name()}'">
|
||||
<XSL:copy>
|
||||
<call-template name="copy-xsl-children"/>
|
||||
</XSL:copy>
|
||||
</XSL:when>
|
||||
<XSL:otherwise>
|
||||
<copy>
|
||||
<call-template name="copy-xsl-children"/>
|
||||
</copy>
|
||||
</XSL:otherwise>
|
||||
</XSL:choose>
|
||||
<copy>
|
||||
<call-template name="copy-xsl-children"/>
|
||||
</copy>
|
||||
</when>
|
||||
<otherwise>
|
||||
<call-template name="expand">
|
||||
@@ -195,21 +186,16 @@
|
||||
</if>
|
||||
|
||||
<for-each select="@*">
|
||||
<variable name="expr">
|
||||
<call-template name="before">
|
||||
<with-param name="string" select="substring-after(., '{')"/>
|
||||
<with-param name="target">}</with-param>
|
||||
</call-template>
|
||||
</variable>
|
||||
<variable name="len" select="string-length(.)"/>
|
||||
<choose>
|
||||
<when test="string-length($expr) = string-length(.) - 2">
|
||||
<XSL:with-param name="{name()}" select="{$expr}"/>
|
||||
<when test="substring(., 1, 1) = '{' and
|
||||
substring(., $len, 1) = '}'">
|
||||
<XSL:with-param name="{name()}"
|
||||
select="{substring(., 2, $len - 2)}"/>
|
||||
</when>
|
||||
<otherwise>
|
||||
<XSL:with-param name="{name()}">
|
||||
<call-template name="avt">
|
||||
<with-param name="string" select="."/>
|
||||
</call-template>
|
||||
<call-template name="avt"/>
|
||||
</XSL:with-param>
|
||||
</otherwise>
|
||||
</choose>
|
||||
@@ -318,7 +304,7 @@
|
||||
</template>
|
||||
|
||||
<template name="avt">
|
||||
<param name="string"/>
|
||||
<param name="string" select="."/>
|
||||
|
||||
<variable name="before1" select="substring-before(concat($string, '{'), '{')"/>
|
||||
<variable name="len1" select="string-length($before1)"/>
|
||||
|
@@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
#############################################################################
|
||||
# Name: preprocess
|
||||
# Purpose: Expand embedded xslt
|
||||
# Author: Mike Wetherell
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 2007 Mike Wetherell
|
||||
# Licence: wxWidgets licence
|
||||
#############################################################################
|
||||
|
||||
if [ $# -eq 0 -o ! -f "$1" ]; then
|
||||
echo "Usage: $0 FILE..."
|
||||
echo "Expands embedded xslt"
|
||||
exit 1
|
||||
fi >&2
|
||||
|
||||
DIR="`dirname $0`"
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
xsltproc --xinclude $DIR/embedded.xsl "$1" 2>/dev/null |
|
||||
xsltproc --xinclude - "$1"
|
||||
shift
|
||||
done
|
@@ -1,65 +0,0 @@
|
||||
#!/bin/sh
|
||||
#############################################################################
|
||||
# Name: validate
|
||||
# Purpose: Reports errors in wxWidgets buildbot configuration files
|
||||
# Author: Mike Wetherell
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 2007 Mike Wetherell
|
||||
# Licence: wxWidgets licence
|
||||
#############################################################################
|
||||
|
||||
if [ $# -eq 0 -o ! -f "$1" ]; then
|
||||
echo "Usage: $0 FILE..."
|
||||
echo "Reports errors in wxWidgets buildbot configuration files"
|
||||
exit 1
|
||||
fi >&2
|
||||
|
||||
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'`
|
||||
|
||||
# Change the names of the temporary files in an error message to something
|
||||
# to something more informative
|
||||
#
|
||||
error()
|
||||
{
|
||||
if [ -n "$1" ]; then
|
||||
echo "$1" |
|
||||
sed "s|file ${WORKPAT}|${WORKPAT}|g;\
|
||||
s|${WORKPAT}/XSLT|generated XSLT (from $NAME)|g;\
|
||||
s|${WORKPAT}/prep|$NAME (preprocessed)|g"
|
||||
fi
|
||||
}
|
||||
|
||||
# This is pretty ugly, sorry. It tries not to print the same error more than
|
||||
# once, and it tries to send success message to stdout and errors to stderr.
|
||||
# It still doesn't return a meaningful exit code.
|
||||
#
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
INPUT="$1"
|
||||
NAME="`echo \"$INPUT\" | sed 's/[|\]/\\\&/g'`"
|
||||
XSLT="$WORKDIR/XSLT"
|
||||
OUTPUT="$WORKDIR/prep"
|
||||
|
||||
if STDERR=`xsltproc --xinclude -o "$XSLT" $DIR/embedded.xsl "$INPUT" 2>&1`
|
||||
then
|
||||
STDERR=`xsltproc --xinclude -o "$OUTPUT" "$XSLT" "$INPUT" 2>&1` \
|
||||
&& OK=true || OK=false
|
||||
error "$STDERR" >&2
|
||||
|
||||
if $OK; then
|
||||
STDERR=`xmllint --noout --schema $DIR/bot.xsd "$OUTPUT" 2>&1` \
|
||||
&& OUT=1 || OUT=2
|
||||
error "$STDERR" >&$OUT
|
||||
fi
|
||||
else
|
||||
error "$STDERR" >&2
|
||||
fi
|
||||
|
||||
rm -f "$XSLT" "$OUTPUT"
|
||||
|
||||
shift
|
||||
done
|
Reference in New Issue
Block a user