10 def normalize_ext(e, ext):
11 alias = e.cfgs["ALIAS_EXT_" + ext]
12 return alias if alias != "" else ext
15 for e in e.cfgs["EXTENSIONS"].split():
18 raise moe.MoeErr, "Unknown extension: " + ext
20 def locate(e, filename=None):
21 e.log.progress("Locating source... ")
27 dir, file = os.path.split(filename)
29 dir = e.cfgs["SOL_DIR"]
31 base, ext = os.path.splitext(file)
33 if not os.path.exists(os.path.join(dir, file)):
34 raise moe.SolutionErr, "No solution of %s called %s found" % (task,file)
39 for ext in e.cfgs["EXTENSIONS"].split():
40 if os.path.exists(os.path.join(dir, base + "." + ext)):
43 raise moe.SolutionErr, "No solution of %s found" % task
45 raise moe.SolutionErr, "Multiple solutions of %s found" % task
47 file = base + "." + ext
49 orig_path = os.path.join(dir, file)
50 norm_ext = normalize_ext(e, ext)
51 e.log.verbose("Found solution %s\n" % orig_path)
53 copy = e.cfgs["TASK"] + "." + norm_ext
54 copy_path = os.path.join(e.cfgs["TEST_DIR"], copy)
56 e.log.verbose("Renaming to %s\n" % copy)
57 moe.util.link_or_copy(orig_path, copy_path)
59 e.builtins.set("SRC", copy)
60 e.builtins.set("EXT", norm_ext)
61 e.cfgs.apply_overrides("EXT_" + norm_ext)
63 e.stat["source"] = file
64 e.log.progress(file + "\n")
67 boxdir = moe.box.setup(e)
68 pdir = e.cfgs["TASK_DIR"]
69 tdir = e.cfgs["TEST_DIR"]
70 shutil.copyfile(os.path.join(tdir, e.cfgs["SRC"]), os.path.join(boxdir, e.cfgs["SRC"]))
71 for x in e.cfgs["EXTRAS"].split() + e.cfgs["COMP_EXTRAS"].split()
72 xx = os.path.join(tdir, x)
73 if not os.path.isfile(xx):
74 xx = os.path.join(pdir, x)
75 e.log.verbose("Copying extra file %s\n" % xx)
76 shutil.copyfile(xx, os.path.join(boxdir, x))
80 moe.box.show(e, "compiler input")
81 rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], e.cfgs["COMP"])
82 moe.box.show(e, "compiler output")
92 e.main_pipe.insert(100, "compile-init", compile_init)
93 e.main_pipe.insert(150, "compile-run", compile_run)
94 e.main_pipe.insert(190, "compile-done", compile_done)
95 e.main_pipe.insert(200, "batch-tests", tests)