]> mj.ucw.cz Git - moe.git/blobdiff - bin/lib
Use per-extension overrides for setting of compilation commands.
[moe.git] / bin / lib
diff --git a/bin/lib b/bin/lib
index 9c49f9e9fac26982925a13ab61c9df97b490f978..981b01002a93e3ae4544d19285786059732d5148 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -1,5 +1,5 @@
 # The Evaluator -- Shell Function Library
-# (c) 2001--2007 Martin Mares <mj@ucw.cz>
+# (c) 2001--2008 Martin Mares <mj@ucw.cz>
 
 # General settings
 shopt -s dotglob
@@ -49,6 +49,21 @@ function try-ln
        ln $1 $2 2>/dev/null || cp $1 $2
 }
 
+# Given a <prefix>, override each variable <x> by <prefix>_<x>
+
+function override-vars
+{
+       local OR V OLDIFS
+       declare -a OR
+       OLDIFS="$IFS"
+       IFS=$'\n'
+       OR=($(set | sed "s/^$1_//;t;d")) || true
+       IFS="$OLDIFS"
+       for V in "${OR[@]}" ; do
+               eval "$V"
+       done
+}
+
 # Sandbox subroutines
 
 function box-init
@@ -57,7 +72,7 @@ function box-init
        if [ -z "$TEST_USER" -o "$TEST_USER" == $EVAL_USER ] ; then
                pcont "running locally (INSECURE), "
                TEST_USER=$EVAL_USER
-               BOXDIR=box
+               BOXDIR=`pwd`/box
                BOXCMD=bin/box
                mkdir -p box
        else
@@ -152,6 +167,7 @@ function locate-source
 function compile
 {
        pstart "Compiling... "
+       override-vars "EXT_$SRCEXT"
        # Beware, the original SRCN can be a strange user-supplied name
        SRC=$PROBLEM.$SRCEXT
        cp "$SDIR/$SRCN" $TDIR/$SRC
@@ -162,8 +178,7 @@ function compile
        box-clean
        for a in $SRC $COMP_EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
        EXE=$PROBLEM
-       CCMD=COMP_$SRCEXT
-       CCMD=`eval echo ${!CCMD}`
+       CCMD=`eval echo $COMP`
        COMP_SANDBOX_OPTS=`eval echo $COMP_SANDBOX_OPTS`
        echo "Compiler command: $CCMD"
        echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
@@ -195,6 +210,12 @@ function compile
 
 # Running of test program according to current task type (returns exit code and TEST_MSG)
 
+function test-config
+{
+       [ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config
+       override-vars "TEST_$TEST"
+}
+
 function test-run
 {
        test-run-$TASK_TYPE