mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-04 03:22:06 +00:00
使用 judger 运行编译器
This commit is contained in:
parent
bab289d652
commit
65c2033120
@ -1,42 +1,39 @@
|
||||
# coding=utf-8
|
||||
import time
|
||||
import os
|
||||
import judger
|
||||
import commands
|
||||
|
||||
from settings import lrun_uid, lrun_gid
|
||||
from judge_exceptions import CompileError, JudgeClientError
|
||||
from utils import parse_lrun_output
|
||||
from logger import logger
|
||||
from settings import judger_workspace
|
||||
|
||||
|
||||
def compile_(language_item, src_path, exe_path):
|
||||
compile_command = language_item["compile_command"].format(src_path=src_path, exe_path=exe_path)
|
||||
compile_command = language_item["compile_command"].format(src_path=src_path, exe_path=exe_path).split(" ")
|
||||
compiler = compile_command[0]
|
||||
compile_args = compile_command[1:]
|
||||
compiler_output_file = os.path.join(judger_workspace, str(time.time()) + ".out")
|
||||
|
||||
# 防止编译器卡死 或者 include </dev/random>等
|
||||
execute_command = "lrun" + \
|
||||
" --max-real-time 5" + \
|
||||
" --uid " + str(lrun_uid) + \
|
||||
" --gid " + str(lrun_gid) + \
|
||||
" " + \
|
||||
compile_command + \
|
||||
" 3>&2"
|
||||
status, output = commands.getstatusoutput(execute_command)
|
||||
compile_result = judger.run(exe_path=compiler,
|
||||
in_file="/dev/null",
|
||||
out_file=compiler_output_file,
|
||||
max_cpu_time=2000,
|
||||
max_memory=200000000,
|
||||
args=compile_args,
|
||||
env=["PATH=" + os.environ["PATH"]],
|
||||
use_sandbox=False)
|
||||
|
||||
output_start = output.rfind("MEMORY")
|
||||
compile_output_handler = open(compiler_output_file)
|
||||
compile_output = compile_output_handler.read()
|
||||
compile_output_handler.close()
|
||||
os.remove(compiler_output_file)
|
||||
|
||||
if output_start == -1:
|
||||
if compile_result["flag"] != 0:
|
||||
logger.error("Compiler error")
|
||||
logger.error(output)
|
||||
raise JudgeClientError("Error running compiler in lrun")
|
||||
|
||||
# 返回值不为 0 或者 stderr 中 lrun 的输出之前有 erro r字符串
|
||||
# 判断 error 字符串的原因是链接的时候可能会有一些不推荐使用的函数的的警告,
|
||||
# 但是 -w 参数并不能关闭链接时的警告
|
||||
if status or "error" in output[0:output_start]:
|
||||
raise CompileError(output[0:output_start])
|
||||
|
||||
parse_result = parse_lrun_output(output[output_start:])
|
||||
|
||||
if parse_result["exit_code"] or parse_result["term_sig"] or parse_result["siginaled"] or parse_result["exceed"]:
|
||||
logger.error("Compiler error")
|
||||
logger.error(output)
|
||||
logger.error(compile_output)
|
||||
logger.error(str(compile_result))
|
||||
raise CompileError("Compile error")
|
||||
return exe_path
|
||||
else:
|
||||
if "error" in compile_output:
|
||||
raise CompileError(compile_output)
|
||||
return exe_path
|
||||
|
@ -14,11 +14,3 @@ lrun_gid = 1002
|
||||
|
||||
# judger工作目录
|
||||
judger_workspace = "/var/judger/"
|
||||
|
||||
submission_db = {
|
||||
"host": os.environ.get("MYSQL_PORT_3306_TCP_ADDR", "127.0.0.1"),
|
||||
"port": 3306,
|
||||
"db": "oj_submission",
|
||||
"user": "root",
|
||||
"password": os.environ.get("MYSQL_ENV_MYSQL_ROOT_PASSWORD", "root")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user