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"
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]
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)
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
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):
self.init_test()
self.init_logs()
self.init_task()
+ moe.box.init(self)
self.log.progress("OK\n")
def init_global(self, overrides):
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")
#!/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)
self.say(msg)
self.progress(msg)
+ def flush(self):
+ self.log_file.flush()
+
default = MoeLog()
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
sys.path.append('.')
import moe
-import moe.stat
import moe.config
import moe.eval
import moe.pipeline