From 5701572b35e7ebc7c2d96cc603cd720fb2649ac4 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 10 Aug 2009 20:32:13 +0200 Subject: [PATCH] Parts of compilation --- t/config | 35 +++++++++++++++++++++++++++++++++++ t/moe/batch.py | 27 +++++++++++++++++++++++++-- t/moe/eval.py | 8 +++++--- t/moe/log.py | 13 ++++++++++++- t/moe/util.py | 11 +++++++++++ t/test.py | 1 - 6 files changed, 88 insertions(+), 7 deletions(-) diff --git a/t/config b/t/config index c75c2d5..d9387bc 100644 --- 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" diff --git a/t/moe/batch.py b/t/moe/batch.py index e4e2394..cd0d93d 100644 --- a/t/moe/batch.py +++ b/t/moe/batch.py @@ -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) diff --git a/t/moe/eval.py b/t/moe/eval.py index 3298144..bc2e5c0 100644 --- a/t/moe/eval.py +++ b/t/moe/eval.py @@ -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") diff --git a/t/moe/log.py b/t/moe/log.py index 295fac3..56dbe8f 100644 --- a/t/moe/log.py +++ b/t/moe/log.py @@ -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() diff --git a/t/moe/util.py b/t/moe/util.py index 69007a1..e083f0f 100644 --- a/t/moe/util.py +++ b/t/moe/util.py @@ -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 diff --git a/t/test.py b/t/test.py index 167be98..8b8f3f1 100755 --- 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 -- 2.39.2