OnlineJudge/judge/compiler.py

41 lines
1.6 KiB
Python
Raw Normal View History

# coding=utf-8
2016-02-01 14:17:33 +00:00
import os
import judger
2016-04-07 08:19:39 +00:00
from judge_exceptions import CompileError
from logger import logger
def compile_(language_item, src_path, exe_path, judge_base_path, compile_spj=False):
command_item = "spj_compile_command" if compile_spj else "compile_command"
compile_command = language_item[command_item].format(src_path=src_path, exe_path=exe_path).split(" ")
2016-02-01 14:17:33 +00:00
compiler = compile_command[0]
compile_args = compile_command[1:]
2016-02-02 02:14:18 +00:00
compiler_output_file = os.path.join(judge_base_path, "compiler.out")
2016-02-01 14:17:33 +00:00
compile_result = judger.run(path=compiler,
2016-02-01 14:17:33 +00:00
in_file="/dev/null",
out_file=compiler_output_file,
max_cpu_time=2000,
max_memory=2000000000,
2016-02-01 14:17:33 +00:00
args=compile_args,
env=["PATH=" + os.environ["PATH"]],
use_sandbox=False,
use_nobody=True)
2016-02-01 14:17:33 +00:00
compile_output_handler = open(compiler_output_file)
compile_output = compile_output_handler.read().strip()
2016-02-01 14:17:33 +00:00
compile_output_handler.close()
if compile_result["flag"] != 0:
logger.error("Compiler error")
2016-02-01 14:17:33 +00:00
logger.error(compile_output)
logger.error(str(compile_result))
if compile_output:
raise CompileError(compile_output)
else:
raise CompileError("Compile error, info: " + str(compile_result))
2016-02-01 14:17:33 +00:00
else:
if "error" in compile_output:
raise CompileError(compile_output)
return exe_path