|
|
|
|
@ -5,12 +5,13 @@ import traceback
|
|
|
|
|
|
|
|
|
|
TARGET_LANGUAGE = set(["python", "cpp", "go", "rust", "node", "javascript"])
|
|
|
|
|
PROJECT_PATH = "/home/rocker/project"
|
|
|
|
|
BUILD_TIMEOUT_S = 3
|
|
|
|
|
|
|
|
|
|
def go_handler():
|
|
|
|
|
source_path = f"{PROJECT_PATH}/go_project/main.go"
|
|
|
|
|
subprocess.run(["cp", "/tmp/code", source_path], capture_output=True)
|
|
|
|
|
main_path = f"{PROJECT_PATH}/go_project/main"
|
|
|
|
|
ret = subprocess.run(["go", "build", "-o", main_path], cwd=f"{PROJECT_PATH}/go_project", capture_output=True)
|
|
|
|
|
ret = subprocess.run(["/usr/bin/timeout", f"{BUILD_TIMEOUT_S}s", "go", "build", "-o", main_path], cwd=f"{PROJECT_PATH}/go_project", capture_output=True)
|
|
|
|
|
std_err = ret.stderr.decode("utf-8")
|
|
|
|
|
if len(std_err) > 0:
|
|
|
|
|
return std_err, ""
|
|
|
|
|
@ -20,7 +21,7 @@ def cpp_handler():
|
|
|
|
|
source_path = f"{PROJECT_PATH}/cpp_project/main.cpp"
|
|
|
|
|
subprocess.run(["cp", "/tmp/code", source_path], capture_output=True)
|
|
|
|
|
main_path = f"{PROJECT_PATH}/cpp_project/main"
|
|
|
|
|
ret = subprocess.run(["g++", source_path, "-o", main_path], capture_output=True)
|
|
|
|
|
ret = subprocess.run(["/usr/bin/timeout", f"{BUILD_TIMEOUT_S}s", "g++", source_path, "-o", main_path], capture_output=True)
|
|
|
|
|
std_err = ret.stderr.decode("utf-8")
|
|
|
|
|
if len(std_err) > 0:
|
|
|
|
|
return std_err, ""
|
|
|
|
|
@ -34,7 +35,7 @@ def node_handler():
|
|
|
|
|
def rust_handler():
|
|
|
|
|
source_path = f"{PROJECT_PATH}/rust_project/src/main.rs"
|
|
|
|
|
subprocess.run(["cp", "/tmp/code", source_path], capture_output=True)
|
|
|
|
|
ret = subprocess.run(["cargo", "build"], cwd=f"{PROJECT_PATH}/rust_project", capture_output=True)
|
|
|
|
|
ret = subprocess.run(["/usr/bin/timeout", f"{BUILD_TIMEOUT_S}s", "cargo", "build"], cwd=f"{PROJECT_PATH}/rust_project", capture_output=True)
|
|
|
|
|
std_err = ret.stderr.decode("utf-8")
|
|
|
|
|
if len(std_err) > 0 and ret.returncode != 0:
|
|
|
|
|
return std_err, ""
|
|
|
|
|
@ -50,12 +51,13 @@ def python_handler():
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
language = sys.argv[1]
|
|
|
|
|
timeout_s = sys.argv[2]
|
|
|
|
|
if language not in TARGET_LANGUAGE:
|
|
|
|
|
print(f"不支持的编程语言: {language}")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# 编译和执行
|
|
|
|
|
cmd = ["/usr/bin/time", "-f", "'%M %U %S %e'"]
|
|
|
|
|
cmd = ["/usr/bin/time", "-f", "'%M %U %S %e'", "/usr/bin/timeout", f"{timeout_s}s"]
|
|
|
|
|
err = ""
|
|
|
|
|
if language == "python":
|
|
|
|
|
err, main_path = python_handler()
|
|
|
|
|
|