Ejemplo n.º 1
0
    def __init__(self, file):
        DEVNULL = open(os.devnull, 'wb')
        SubmissionWrapper.__init__(self)
        tmpdir = tempfile.TemporaryDirectory(prefix="aoc")
        tmpdir.cleanup()
        try:
            subprocess.check_output(
                ["cargo", "test", "--bin",
                 file.replace('/', '-')[:-3]],
                stderr=DEVNULL).decode()
        except subprocess.CalledProcessError as e:
            raise CompilationError(e.output)

        e = subprocess.Popen([
            "cargo", "build", "--release", "--bin",
            file.replace('/', '-')[:-3]
        ],
                             env={
                                 **os.environ, "CARGO_TARGET_DIR": tmpdir.name
                             },
                             stdout=DEVNULL,
                             stderr=DEVNULL).wait()
        if e > 0:
            raise CompilationError("Could not compile " + file)
        self.executable = tmpdir.name + "/release/" + file.replace('/',
                                                                   '-')[:-3]
Ejemplo n.º 2
0
 def __init__(self, file):
     SubmissionWrapper.__init__(self)
     tmp = tempfile.NamedTemporaryFile(prefix="aoc")
     tmp.close()
     compile_output = subprocess.check_output(["g++", "-Wall", "-Wno-sign-compare", "-O3", "-std=c++14", "-o", tmp.name, file]).decode()
     if compile_output:
         raise CompilationError(compile_output)
     self.executable = tmp.name
Ejemplo n.º 3
0
 def __init__(self, file):
     SubmissionWrapper.__init__(self)
     # Create a temporary directory to put the compiled java in,
     # in order to have it destroyed once we are done
     self.temporary_directory = tempfile.mkdtemp(prefix="aoc")
     compile_output = subprocess.check_output(
         ["javac", file, "-d", self.temporary_directory]).decode()
     if compile_output:
         raise CompilationError(compile_output)
Ejemplo n.º 4
0
 def exec(self, input):
     try:
         return subprocess.check_output([self.executable, input]).decode()
     except OSError as e:
         if e.errno == errno.ENOENT:
             # executable not found
             return CompilationError(e)
         else:
             # subprocess exited with another error
             return RuntimeError(e)
Ejemplo n.º 5
0
 def exec(self, input):
     try:
         p = Popen([self.executable], stdin=PIPE, stdout=PIPE)
         stdout, _ = p.communicate(input.encode())
         return stdout.decode()
     except OSError as e:
         if e.errno == errno.ENOENT:
             # executable not found
             raise CompilationError(e)
         else:
             # subprocess exited with another error
             raise RuntimeError(e)
Ejemplo n.º 6
0
 def exec(self, input):
     try:
         # main class MUST be named Solution
         return subprocess.check_output(
             ["java", "-cp", self.temporary_directory, "Solution",
              input]).decode()
     except OSError as e:
         if e.errno == errno.ENOENT:
             # executable not found
             return CompilationError(e)
         else:
             # subprocess exited with another error
             return RuntimeError(e)
Ejemplo n.º 7
0
 def __init__(self, file):
     SubmissionWrapper.__init__(self)
     relpath = os.path.join(".", file)
     abspath = os.path.realpath(file)
     gopath = os.path.realpath(
         check_output(["go", "env", "GOPATH"]).decode().strip())
     if not abspath.startswith(gopath):
         dep_output = check_output(["go", "get", "-d", relpath]).decode()
         if dep_output:
             raise DependenciesError(dep_output)
     tmp = tempfile.NamedTemporaryFile(prefix="aoc")
     tmp.close()
     compile_output = check_output(["go", "build", "-o", tmp.name,
                                    file]).decode()
     if compile_output:
         raise CompilationError(compile_output)
     os.chmod(tmp.name, os.stat(tmp.name).st_mode | stat.S_IEXEC)
     self.executable = tmp.name