]> git.saurik.com Git - wxWidgets.git/commitdiff
Clean up the tools for offline checking of the configuration.
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Tue, 5 Feb 2008 18:10:14 +0000 (18:10 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Tue, 5 Feb 2008 18:10:14 +0000 (18:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51561 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

build/buildbot/tools/bot.xsd
build/buildbot/tools/check.sh [new file with mode: 0755]
build/buildbot/tools/embedded.xsl
build/buildbot/tools/preprocess.sh [deleted file]
build/buildbot/tools/validate.sh [deleted file]

index f19fbc1c36c2739ad7c4f2cf06717bf8c9f4a6b7..c340d2e4601423f11e699b3c13988398e8770fec 100644 (file)
@@ -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 -->
diff --git a/build/buildbot/tools/check.sh b/build/buildbot/tools/check.sh
new file mode 100755 (executable)
index 0000000..0a73455
--- /dev/null
@@ -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
index ca192823cc8d5d0d59c7cf1f9c0d6dc9ac92e6df..29e31d6d5fa69ed4528ec22b06ba5e1561a666ab 100644 (file)
@@ -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
 <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">
         </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>
 </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)"/>
diff --git a/build/buildbot/tools/preprocess.sh b/build/buildbot/tools/preprocess.sh
deleted file mode 100755 (executable)
index f6a9009..0000000
+++ /dev/null
@@ -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
diff --git a/build/buildbot/tools/validate.sh b/build/buildbot/tools/validate.sh
deleted file mode 100755 (executable)
index 09a091e..0000000
+++ /dev/null
@@ -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