From ed605d1d741c75b3671f2b112024370eeb52263c Mon Sep 17 00:00:00 2001 From: Yutao Fang Date: Sat, 8 May 2021 20:39:49 +0800 Subject: [PATCH] add javascript and php (cherry picked from commit 9a9fd10942f7e30bb27cd7e7dec980e4fef2d7ca) --- Dockerfile | 9 +++++++-- client/Python/client.py | 28 +++++++++++++++++++++++++--- client/Python/languages.py | 24 ++++++++++++++++++++++-- server/compiler.py | 3 ++- server/judge_client.py | 7 +++++-- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87ccbbf..682689b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,18 @@ FROM ubuntu:18.04 COPY build/java_policy /etc #RUN sed -E -i -e 's/(archive|ports).ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' -e '/security.ubuntu.com/d' /etc/apt/sources.list -RUN buildDeps='software-properties-common git libtool cmake python-dev python3-pip python-pip libseccomp-dev' && \ +ENV DEBIAN_FRONTEND=noninteractive +RUN buildDeps='software-properties-common git libtool cmake python-dev python3-pip python-pip libseccomp-dev curl' && \ apt-get update && apt-get install -y python python3 python-pkg-resources python3-pkg-resources $buildDeps && \ add-apt-repository ppa:openjdk-r/ppa && add-apt-repository ppa:longsleep/golang-backports && \ add-apt-repository ppa:ubuntu-toolchain-r/test && \ - apt-get update && apt-get install -y golang-go openjdk-11-jdk gcc-9 g++-9 && \ + add-apt-repository ppa:ondrej/php && \ + curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \ + apt-get update && apt-get install -y golang-go openjdk-11-jdk php-cli nodejs gcc-9 g++-9 && \ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 40 && \ update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 40 && \ + phpJitOption='opcache.enable=1\nopcache.enable_cli=1\nopcache.jit=1205\nopcache.jit_buffer_size=64M' && \ + echo $phpJitOption > /etc/php/8.0/cli/conf.d/10-opcache-jit.ini && \ pip3 install -I --no-cache-dir psutil gunicorn flask requests idna && \ cd /tmp && git clone -b newnew --depth 1 https://github.com/QingdaoU/Judger && cd Judger && \ mkdir build && cd build && cmake .. && make && make install && cd ../bindings/Python && python3 setup.py install && \ diff --git a/client/Python/client.py b/client/Python/client.py index 6d3947e..cb3d62e 100644 --- a/client/Python/client.py +++ b/client/Python/client.py @@ -3,8 +3,7 @@ import requests -from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, \ - c_lang_spj_compile, py2_lang_config, py3_lang_config, go_lang_config +from .languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile, py2_lang_config, py3_lang_config, go_lang_config, php_lang_config, js_lang_config class JudgeServerClientError(Exception): @@ -117,6 +116,20 @@ def compile_spj(self, src, spj_version, spj_compile_config): fmt.Printf("%d", a + b) }""" + php_src = """ { + if (input === '') { + return rl.close(); + } + const [a, b] = input.split(' ').map(Number) + console.log(a + b); +});""" + client = JudgeServerClient(token=token, server_base_url="http://127.0.0.1:12358") print("ping") print(client.ping(), "\n\n") @@ -147,7 +160,6 @@ def compile_spj(self, src, spj_version, spj_compile_config): spj_version="3", spj_config=c_lang_spj_config, spj_compile_config=c_lang_spj_compile, spj_src=c_spj_src), "\n\n") - print("py2_judge") print(client.judge(src=py2_src, language_config=py2_lang_config, max_cpu_time=1000, max_memory=128 * 1024 * 1024, @@ -163,6 +175,16 @@ def compile_spj(self, src, spj_version, spj_compile_config): max_cpu_time=1000, max_memory=128 * 1024 * 1024, test_case_id="normal", output=True), "\n\n") + print("php_judge") + print(client.judge(src=php_src, language_config=php_lang_config, + max_cpu_time=1000, max_memory=128 * 1024 * 1024, + test_case_id="normal", output=True), "\n\n") + + print("js_judge") + print(client.judge(src=js_src, language_config=js_lang_config, + max_cpu_time=1000, max_memory=128 * 1024 * 1024, + test_case_id="normal", output=True), "\n\n") + print("c_dynamic_input_judge") print(client.judge(src=c_src, language_config=c_lang_config, max_cpu_time=1000, max_memory=1024 * 1024 * 128, diff --git a/client/Python/languages.py b/client/Python/languages.py index f795880..518d56c 100644 --- a/client/Python/languages.py +++ b/client/Python/languages.py @@ -110,7 +110,7 @@ "max_real_time": 5000, "max_memory": 1024 * 1024 * 1024, "compile_command": "/usr/bin/go build -o {exe_path} {src_path}", - "env": ["GOCACHE=/tmp"] + "env": ["GOCACHE=/tmp", "GOPATH=/tmp/go"] }, "run": { "command": "{exe_path}", @@ -119,4 +119,24 @@ "env": ["GODEBUG=madvdontneed=1", "GOCACHE=off"] + default_env, "memory_limit_check_only": 1 } -} \ No newline at end of file +} + +php_lang_config = { + "run": { + "exe_name": "solution.php", + "command": "/usr/bin/php {exe_path}", + "seccomp_rule": "", + "env": default_env, + "memory_limit_check_only": 1 + } +} + +js_lang_config = { + "run": { + "exe_name": "solution.js", + "command": "/usr/bin/node {exe_path}", + "seccomp_rule": "", + "env": ["NO_COLOR=true"] + default_env, + "memory_limit_check_only": 1 + } +} diff --git a/server/compiler.py b/server/compiler.py index e8a6f5a..ecb76a5 100644 --- a/server/compiler.py +++ b/server/compiler.py @@ -4,6 +4,7 @@ from config import COMPILER_LOG_PATH, COMPILER_USER_UID, COMPILER_GROUP_GID from exception import CompileError +import shlex class Compiler(object): @@ -12,7 +13,7 @@ def compile(self, compile_config, src_path, output_dir): exe_path = os.path.join(output_dir, compile_config["exe_name"]) command = command.format(src_path=src_path, exe_dir=output_dir, exe_path=exe_path) compiler_out = os.path.join(output_dir, "compiler.out") - _command = command.split(" ") + _command = shlex.split(command) os.chdir(output_dir) env = compile_config.get("env", []) diff --git a/server/judge_client.py b/server/judge_client.py index 0963759..ec94050 100644 --- a/server/judge_client.py +++ b/server/judge_client.py @@ -4,6 +4,7 @@ import os import shutil from multiprocessing import Pool +import shlex import psutil @@ -70,7 +71,8 @@ def _spj(self, in_file_path, user_out_file_path): os.chmod(user_out_file_path, 0o740) command = self._spj_config["command"].format(exe_path=self._spj_exe, in_file_path=in_file_path, - user_out_file_path=user_out_file_path).split(" ") + user_out_file_path=user_out_file_path) + command = shlex.split(command) seccomp_rule_name = self._spj_config["seccomp_rule"] result = _judger.run(max_cpu_time=self._max_cpu_time * 3, max_real_time=self._max_cpu_time * 9, @@ -116,7 +118,8 @@ def _judge_one(self, test_case_file_id): kwargs = {"input_path": in_file, "output_path": real_user_output_file, "error_path": real_user_output_file} command = self._run_config["command"].format(exe_path=self._exe_path, exe_dir=os.path.dirname(self._exe_path), - max_memory=int(self._max_memory / 1024)).split(" ") + max_memory=int(self._max_memory / 1024)) + command = shlex.split(command) env = ["PATH=" + os.environ.get("PATH", "")] + self._run_config.get("env", []) seccomp_rule = self._run_config["seccomp_rule"]