From 7acaf00e7883c53af80bd5f8122dc517fca6730a Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 11 Mar 2022 12:43:23 +0800 Subject: [PATCH] judge: auto apply compile.sh and execute.sh --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/compile.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index f1696a41b..3b8f291a9 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.14.2", + "version": "2.14.3", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/compile.ts b/packages/hydrojudge/src/compile.ts index 44b69544a..bd7500e5d 100644 --- a/packages/hydrojudge/src/compile.ts +++ b/packages/hydrojudge/src/compile.ts @@ -10,25 +10,29 @@ export = async function compile( lang: LangConfig, code: string, copyIn: Record = {}, next?: Function, ): Promise { const target = lang.target || 'foo'; - copyIn[lang.code_file] = { content: code }; + const execute = copyIn['execute.sh'] ? '/bin/bash execute.sh' : lang.execute; + const time = lang.time_limit_rate || 1; if (lang.compile) { const { status, stdout, stderr, fileIds, } = await run( - lang.compile, - { copyIn, copyOutCached: [target] }, + copyIn['compile.sh'] ? '/bin/bash compile.sh' : lang.compile, + { copyIn: { ...copyIn, [lang.code_file]: { content: code } }, copyOutCached: [target] }, ); if (status !== STATUS.STATUS_ACCEPTED) throw new CompileError({ status, stdout, stderr }); if (!fileIds[target]) throw new CompileError({ stderr: 'Executable file not found.' }); if (next) next({ compiler_text: compilerText(stdout, stderr) }); return { - execute: lang.execute, + execute, copyIn: { ...copyIn, [target]: { fileId: fileIds[target] } }, clean: () => del(fileIds[target]), - time: lang.time_limit_rate || 1, + time, }; } return { - execute: lang.execute, copyIn, clean: () => Promise.resolve(null), time: lang.time_limit_rate || 1, + execute, + copyIn: { ...copyIn, [lang.code_file]: { content: code } }, + clean: () => Promise.resolve(null), + time, }; };