mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
judge: fix copyIn
This commit is contained in:
1 parent
167c70c2b1
commit
e6927bcc49
5 files changed
+17
-25
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"bin": "bin/hydrojudge.js",
|
||||
"version": "2.8.3",
|
||||
"version": "2.8.4",
|
||||
"main": "package.json",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -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<Execute> {
|
||||
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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user