]> mj.ucw.cz Git - eval.git/commitdiff
Parts of compilation
authorMartin Mares <mj@ucw.cz>
Mon, 10 Aug 2009 18:32:13 +0000 (20:32 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 10 Aug 2009 18:32:13 +0000 (20:32 +0200)
t/config
t/moe/batch.py
t/moe/eval.py
t/moe/log.py
t/moe/util.py
t/test.py

index c75c2d53e006deaddbef5037ea82c72b4bd3050a..d9387bca4022b4b97e3b8f38c8f897c5b7cb8f3f 100644 (file)
--- a/t/config
+++ b/t/config
@@ -19,3 +19,38 @@ ALIAS_EXT_C=cpp
 ALIAS_EXT_p=pas
 
 # SRC is auto
+
+## Variables which control compilation and execution
+## (see below for values for individual languages)
+
+# Command used to run the compiler
+COMP=false
+
+# Sandbox options used when compiling
+COMP_SANDBOX_OPTS='-m262144 -w60 -e -i/dev/null'
+
+# EXE is auto, but can be overridden
+
+# Command used to execute the compiled program, may be ./$PROGRAM (default) or an
+# interpreter with $PROGRAM as a parameter.
+TEST_EXEC_CMD=./$EXE
+
+## Settings for individual languages
+
+# C
+EXT_c_COMP='/usr/bin/gcc -std=gnu99 -O2 -g -o $EXE $EXTRA_CFLAGS $SRC -lm'
+EXTRA_CFLAGS=
+
+# C++
+EXT_cpp_COMP='/usr/bin/g++ -O2 -g -o $EXE $EXTRA_CXXFLAGS $SRC -lm'
+EXTRA_CXXFLAGS=
+
+# Pascal
+EXT_pas_COMP='/usr/bin/fpc -Ci -g -O2 -Sg -o$EXE $EXTRA_PFLAGS $SRC'
+EXTRA_PFLAGS=
+
+### Per-task configuration variables (default values, override in per-task config)
+
+# List of extra files needed for compilation. They are copied to the compiler
+# sandbox from the problem's directory. XXX: or tdir
+#COMP_EXTRAS="extras.h"
index e4e23944b34ff51b22892bc61437492071b35970..cd0d93dcffc93f313e1000bd9d7a0a74aadb2a62 100644 (file)
@@ -2,8 +2,10 @@
 
 import os.path
 import moe
+import moe.box
 import moe.eval
 import moe.util
+import shutil
 
 def normalize_ext(e, ext):
     alias = e.cfgs["ALIAS_EXT_" + ext]
@@ -61,12 +63,33 @@ def locate(e, filename=None):
     e.stat["source"] = file
     e.log.progress(file + "\n")
 
-def compile(e):
+def compile_init(e):
+    boxdir = moe.box.setup(e)
+    pdir = e.cfgs["TASK_DIR"]
+    tdir = e.cfgs["TEST_DIR"]
+    shutil.copyfile(os.path.join(tdir, e.cfgs["SRC"]), os.path.join(boxdir, e.cfgs["SRC"]))
+    for x in e.cfgs["EXTRAS"].split() + e.cfgs["COMP_EXTRAS"].split()
+       xx = os.path.join(tdir, x)
+       if not os.path.isfile(xx):
+           xx = os.path.join(pdir, x)
+       e.log.verbose("Copying extra file %s\n" % xx)
+       shutil.copyfile(xx, os.path.join(boxdir, x))
+    pass
+
+def compile_run(e):
+    moe.box.show(e, "compiler input")
+    rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], e.cfgs["COMP"])
+    moe.box.show(e, "compiler output")
+    pass
+
+def compile_done(e):
     pass
 
 def tests(e):
     pass
 
 def prepare_pipe(e):
-    e.main_pipe.insert(100, "compile", compile)
+    e.main_pipe.insert(100, "compile-init", compile_init)
+    e.main_pipe.insert(150, "compile-run", compile_run)
+    e.main_pipe.insert(190, "compile-done", compile_done)
     e.main_pipe.insert(200, "batch-tests", tests)
index 32981440ab80fb245acf7197c7f60d9c21fce0b1..bc2e5c09ee68f649a8f794b8b1ff8d2c8493c845 100644 (file)
@@ -2,8 +2,9 @@
 
 import moe
 import moe.config
+import moe.box
 import moe.log
-import moe.stat
+import moe.status
 import moe.pipeline
 import moe.batch
 import moe.util
@@ -18,7 +19,7 @@ class Eval:
        self.builtins = moe.config.MoeConfig(type="builtins")
        self.cfgs.push(self.builtins)
        self.main_pipe = moe.pipeline.MoePipeline("main")
-       self.stat = moe.stat.MoeStatus()
+       self.stat = moe.status.MoeStatus()
        pass
 
     def init(self, overrides=None):
@@ -27,6 +28,7 @@ class Eval:
        self.init_test()
        self.init_logs()
        self.init_task()
+       moe.box.init(self)
        self.log.progress("OK\n")
 
     def init_global(self, overrides):
@@ -48,7 +50,7 @@ class Eval:
        self.log = moe.log.MoeLog()
        if self.cfgs["V"]:
            self.log.verbosity = int(self.cfgs["V"])
-       self.log.log_file = open(os.path.join(self.cfgs["TEST_DIR"], "log"), "w")
+       self.log.open(os.path.join(self.cfgs["TEST_DIR"], "log"))
        self.default_log = self.log
        moe.log.default = self.log
        self.log_config(3, "before loading the task")
index 295fac35f69c206c7e081ae926559cae5e1d1b25..56dbe8f1f8dfa92d87b354ab9c21e60e5445a834 100644 (file)
@@ -1,14 +1,22 @@
 #!/usr/bin/env python
 
 import sys
+import os
+
+progress_file = os.fdopen(os.dup(1), "w", 0)
 
 class MoeLog:
 
     def __init__(self):
        self.verbosity = 0
-       self.progress_file = sys.stdout
+       self.progress_file = progress_file
        self.log_file = None
 
+    def open(self, name):
+       self.log_file = open(name, "w")
+       os.dup2(self.log_file.fileno(), 1)
+       os.dup2(self.log_file.fileno(), 2)
+
     def say(self, msg):
        if self.log_file:
            self.log_file.write(msg)
@@ -25,4 +33,7 @@ class MoeLog:
        self.say(msg)
        self.progress(msg)
 
+    def flush(self):
+       self.log_file.flush()
+
 default = MoeLog()
index 69007a193429f62bf2eadfb68527aa120a06a463..e083f0fb6f84dbfe285d342c8482036211d05d2e 100644 (file)
@@ -22,3 +22,14 @@ def link_or_copy(src, dest):
        os.link(src, dest)
     except OSError:
        shutil.copyfile(src, dest)
+
+def remove_tree_contents(dir):
+    for f in os.listdir(dir):
+       name = os.path.join(dir, f)
+       try:
+           os.unlink(name)
+       except OSError, err:
+           if err.errno == os.errno.EISDIR:
+               shutil.rmtree(os.path.join(dir, f))
+           else:
+               raise err
index 167be9864c583bc2ec0a19390c7821b1f8ae3db5..8b8f3f124fc796a820be1cafedf4f460d5812db5 100755 (executable)
--- a/t/test.py
+++ b/t/test.py
@@ -4,7 +4,6 @@ import sys
 sys.path.append('.')
 
 import moe
-import moe.stat
 import moe.config
 import moe.eval
 import moe.pipeline