mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.8.3",
|
"version": "2.8.4",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { compilerText } from './utils';
|
|||||||
import { Execute } from './interface';
|
import { Execute } from './interface';
|
||||||
|
|
||||||
export = async function compile(
|
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> {
|
): Promise<Execute> {
|
||||||
target = lang.target || target;
|
target = lang.target || target;
|
||||||
const f = {};
|
const f = {};
|
||||||
@@ -23,11 +23,11 @@ export = async function compile(
|
|||||||
if (next) next({ compiler_text: compilerText(stdout, stderr) });
|
if (next) next({ compiler_text: compilerText(stdout, stderr) });
|
||||||
f[target] = { fileId: fileIds[target] };
|
f[target] = { fileId: fileIds[target] };
|
||||||
return {
|
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 };
|
f[target] = { content: code };
|
||||||
return {
|
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.time_limit_rate = info.time_limit_rate || 1;
|
||||||
ctx.next({ status: STATUS.STATUS_COMPILING });
|
ctx.next({ status: STATUS.STATUS_COMPILING });
|
||||||
[ctx.execute, ctx.checker] = await Promise.all([
|
[ctx.execute, ctx.checker] = await Promise.all([
|
||||||
(async () => {
|
(() => {
|
||||||
const copyIn = {};
|
const copyIn = {};
|
||||||
for (const file of ctx.config.user_extra_files) {
|
for (const file of ctx.config.user_extra_files) {
|
||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
const execute = await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next);
|
return compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next);
|
||||||
execute.copyIn = { ...copyIn, ...execute.copyIn };
|
|
||||||
return execute;
|
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(() => {
|
||||||
if (!ctx.config.checker_type || ctx.config.checker_type === 'default') {
|
if (!ctx.config.checker_type || ctx.config.checker_type === 'default') {
|
||||||
return { execute: '', copyIn: {}, clean: () => Promise.resolve(null) };
|
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) {
|
for (const file of ctx.config.judge_extra_files) {
|
||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
return await compileChecker(
|
return compileChecker(
|
||||||
ctx.getLang,
|
ctx.getLang,
|
||||||
ctx.config.checker_type,
|
ctx.config.checker_type,
|
||||||
ctx.config.checker,
|
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.');
|
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([
|
const [execute, executeValidator, executeStd, executeChecker] = await Promise.all([
|
||||||
// UserProgram
|
// UserProgram
|
||||||
(async () => {
|
(() => {
|
||||||
const copyIn = {};
|
const copyIn = {};
|
||||||
for (const file of ctx.config.user_extra_files) {
|
for (const file of ctx.config.user_extra_files) {
|
||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
const exec = await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next);
|
return await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next);
|
||||||
exec.copyIn = { ...copyIn, ...exec.copyIn };
|
|
||||||
return exec;
|
|
||||||
})(),
|
})(),
|
||||||
// Validator
|
// Validator
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -45,18 +43,16 @@ export const judge = async (ctx) => {
|
|||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
const file = await fs.readFile(ctx.config.std);
|
const file = await fs.readFile(ctx.config.std);
|
||||||
const exec = await compile(ctx.getLang(parseFilename(ctx.config.std).split('.')[1]), file.toString(), 'std', copyIn);
|
return await compile(ctx.getLang(parseFilename(ctx.config.std).split('.')[1]), file.toString(), 'std', copyIn);
|
||||||
exec.copyIn = { ...copyIn, ...exec.copyIn };
|
|
||||||
return exec;
|
|
||||||
})(),
|
})(),
|
||||||
// Checker
|
// Checker
|
||||||
(async () => {
|
(() => {
|
||||||
if (!ctx.config.checker_type || ctx.config.checker_type === 'default') return null;
|
if (!ctx.config.checker_type || ctx.config.checker_type === 'default') return null;
|
||||||
const copyIn = {};
|
const copyIn = {};
|
||||||
for (const file of ctx.config.judge_extra_files) {
|
for (const file of ctx.config.judge_extra_files) {
|
||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
return await compileChecker(
|
return compileChecker(
|
||||||
ctx.getLang,
|
ctx.getLang,
|
||||||
ctx.config.checker_type,
|
ctx.config.checker_type,
|
||||||
ctx.config.checker,
|
ctx.config.checker,
|
||||||
|
|||||||
@@ -92,21 +92,19 @@ export const judge = async (ctx) => {
|
|||||||
ctx.next({ status: STATUS.STATUS_COMPILING });
|
ctx.next({ status: STATUS.STATUS_COMPILING });
|
||||||
ctx.time_limit_rate = ctx.getLang(ctx.lang).time_limit_rate;
|
ctx.time_limit_rate = ctx.getLang(ctx.lang).time_limit_rate;
|
||||||
[ctx.executeUser, ctx.executeInteractor] = await Promise.all([
|
[ctx.executeUser, ctx.executeInteractor] = await Promise.all([
|
||||||
(async () => {
|
(() => {
|
||||||
const copyIn = {};
|
const copyIn = {};
|
||||||
for (const file of ctx.config.user_extra_files) {
|
for (const file of ctx.config.user_extra_files) {
|
||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
const execute = await compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next);
|
return compile(ctx.getLang(ctx.lang), ctx.code, 'code', copyIn, ctx.next);
|
||||||
execute.copyIn = { ...copyIn, ...execute.copyIn };
|
|
||||||
return execute;
|
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(() => {
|
||||||
const copyIn = { 'testlib.h': { src: testlibSrc } };
|
const copyIn = { 'testlib.h': { src: testlibSrc } };
|
||||||
for (const file of ctx.config.judge_extra_files) {
|
for (const file of ctx.config.judge_extra_files) {
|
||||||
copyIn[parseFilename(file)] = { src: file };
|
copyIn[parseFilename(file)] = { src: file };
|
||||||
}
|
}
|
||||||
return await compile(
|
return compile(
|
||||||
ctx.getLang(parseFilename(ctx.config.interactor).split('.')[1]),
|
ctx.getLang(parseFilename(ctx.config.interactor).split('.')[1]),
|
||||||
fs.readFileSync(ctx.config.interactor).toString(),
|
fs.readFileSync(ctx.config.interactor).toString(),
|
||||||
'interactor',
|
'interactor',
|
||||||
|
|||||||
Reference in new issue
Block a user