From e6927bcc49aa465576f866472f9ea97b6dc425cb Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 11 Jun 2021 16:15:50 +0800 Subject: [PATCH] judge: fix copyIn --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/compile.ts | 6 +++--- packages/hydrojudge/src/judge/default.ts | 10 ++++------ packages/hydrojudge/src/judge/hack.ts | 14 +++++--------- packages/hydrojudge/src/judge/interactive.ts | 10 ++++------ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 567fcc0c3..579d0e6e3 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.8.3", + "version": "2.8.4", "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 cd53fe7ed..894d0b988 100644 --- a/packages/hydrojudge/src/compile.ts +++ b/packages/hydrojudge/src/compile.ts @@ -6,7 +6,7 @@ import { compilerText } from './utils'; import { Execute } from './interface'; export = async function compile( - lang: LangConfig, code: string, target: string, copyIn: any, next?: Function, + lang: LangConfig, code: string, target: string, copyIn: any = {}, next?: Function, ): Promise { target = lang.target || target; const f = {}; @@ -23,11 +23,11 @@ export = async function compile( if (next) next({ compiler_text: compilerText(stdout, stderr) }); f[target] = { fileId: fileIds[target] }; return { - execute: lang.execute, copyIn: f, clean: () => del(fileIds[target]), time: lang.time_limit_rate || 1, + execute: lang.execute, copyIn: { ...copyIn, ...f }, clean: () => del(fileIds[target]), time: lang.time_limit_rate || 1, }; } f[target] = { content: code }; return { - execute: lang.execute, copyIn: f, clean: () => Promise.resolve(null), time: lang.time_limit_rate || 1, + execute: lang.execute, copyIn: { ...copyIn, ...f }, clean: () => Promise.resolve(null), time: lang.time_limit_rate || 1, }; }; diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index e51f3ec9f..02a35928b 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -130,16 +130,14 @@ export const judge = async (ctx) => { ctx.time_limit_rate = info.time_limit_rate || 1; ctx.next({ status: STATUS.STATUS_COMPILING }); [ctx.execute, ctx.checker] = await Promise.all([ - (async () => { + (() => { const copyIn = {}; for (const file of ctx.config.user_extra_files) { copyIn[parseFilename(file)] = { src: file }; } - const execute = await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next); - execute.copyIn = { ...copyIn, ...execute.copyIn }; - return execute; + return compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next); })(), - (async () => { + (() => { if (!ctx.config.checker_type || ctx.config.checker_type === 'default') { return { execute: '', copyIn: {}, clean: () => Promise.resolve(null) }; } @@ -147,7 +145,7 @@ export const judge = async (ctx) => { for (const file of ctx.config.judge_extra_files) { copyIn[parseFilename(file)] = { src: file }; } - return await compileChecker( + return compileChecker( ctx.getLang, ctx.config.checker_type, ctx.config.checker, diff --git a/packages/hydrojudge/src/judge/hack.ts b/packages/hydrojudge/src/judge/hack.ts index fadb87fbf..b818e587a 100644 --- a/packages/hydrojudge/src/judge/hack.ts +++ b/packages/hydrojudge/src/judge/hack.ts @@ -20,14 +20,12 @@ export const judge = async (ctx) => { if (!ctx.config.validator || !ctx.config.std) throw new CompileError('config.validator or config.std is missing.'); const [execute, executeValidator, executeStd, executeChecker] = await Promise.all([ // UserProgram - (async () => { + (() => { const copyIn = {}; for (const file of ctx.config.user_extra_files) { copyIn[parseFilename(file)] = { src: file }; } - const exec = await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next); - exec.copyIn = { ...copyIn, ...exec.copyIn }; - return exec; + return await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next); })(), // Validator (async () => { @@ -45,18 +43,16 @@ export const judge = async (ctx) => { copyIn[parseFilename(file)] = { src: file }; } const file = await fs.readFile(ctx.config.std); - const exec = await compile(ctx.getLang(parseFilename(ctx.config.std).split('.')[1]), file.toString(), 'std', copyIn); - exec.copyIn = { ...copyIn, ...exec.copyIn }; - return exec; + return await compile(ctx.getLang(parseFilename(ctx.config.std).split('.')[1]), file.toString(), 'std', copyIn); })(), // Checker - (async () => { + (() => { if (!ctx.config.checker_type || ctx.config.checker_type === 'default') return null; const copyIn = {}; for (const file of ctx.config.judge_extra_files) { copyIn[parseFilename(file)] = { src: file }; } - return await compileChecker( + return compileChecker( ctx.getLang, ctx.config.checker_type, ctx.config.checker, diff --git a/packages/hydrojudge/src/judge/interactive.ts b/packages/hydrojudge/src/judge/interactive.ts index 2007ed5e5..9819b03fb 100644 --- a/packages/hydrojudge/src/judge/interactive.ts +++ b/packages/hydrojudge/src/judge/interactive.ts @@ -92,21 +92,19 @@ export const judge = async (ctx) => { ctx.next({ status: STATUS.STATUS_COMPILING }); ctx.time_limit_rate = ctx.getLang(ctx.lang).time_limit_rate; [ctx.executeUser, ctx.executeInteractor] = await Promise.all([ - (async () => { + (() => { const copyIn = {}; for (const file of ctx.config.user_extra_files) { copyIn[parseFilename(file)] = { src: file }; } - const execute = await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next); - execute.copyIn = { ...copyIn, ...execute.copyIn }; - return execute; + return compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next); })(), - (async () => { + (() => { const copyIn = { 'testlib.h': { src: testlibSrc } }; for (const file of ctx.config.judge_extra_files) { copyIn[parseFilename(file)] = { src: file }; } - return await compile( + return compile( ctx.getLang(parseFilename(ctx.config.interactor).split('.')[1]), fs.readFileSync(ctx.config.interactor).toString(), 'interactor',