mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
judge: add next function to checker compile
This commit is contained in:
2 files changed
+6
-4
No files matched your search
@@ -28,6 +28,7 @@ export default async function compile(
|
|||||||
},
|
},
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
|
// TODO: distinguish user program and checker
|
||||||
if (status === STATUS.STATUS_TIME_LIMIT_EXCEEDED) next?.({ message: 'Compile timeout.' });
|
if (status === STATUS.STATUS_TIME_LIMIT_EXCEEDED) next?.({ message: 'Compile timeout.' });
|
||||||
if (status === STATUS.STATUS_MEMORY_LIMIT_EXCEEDED) next?.({ message: 'Compile memory limit exceeded.' });
|
if (status === STATUS.STATUS_MEMORY_LIMIT_EXCEEDED) next?.({ message: 'Compile memory limit exceeded.' });
|
||||||
if (status !== STATUS.STATUS_ACCEPTED) throw new CompileError({ status, stdout, stderr });
|
if (status !== STATUS.STATUS_ACCEPTED) throw new CompileError({ status, stdout, stderr });
|
||||||
@@ -50,7 +51,7 @@ const testlibFile = {
|
|||||||
src: findFileSync('@hydrooj/hydrojudge/vendor/testlib/testlib.h'),
|
src: findFileSync('@hydrooj/hydrojudge/vendor/testlib/testlib.h'),
|
||||||
};
|
};
|
||||||
|
|
||||||
async function _compile(src: string, type: 'checker' | 'validator' | 'interactor', getLang, copyIn, withTestlib = true) {
|
async function _compile(src: string, type: 'checker' | 'validator' | 'interactor', getLang, copyIn, withTestlib = true, next?: any) {
|
||||||
const s = src.replace('@', '.').split('.');
|
const s = src.replace('@', '.').split('.');
|
||||||
let lang;
|
let lang;
|
||||||
let langId = s.pop();
|
let langId = s.pop();
|
||||||
@@ -62,15 +63,15 @@ async function _compile(src: string, type: 'checker' | 'validator' | 'interactor
|
|||||||
if (!lang) throw new FormatError(`Unknown ${type} language.`);
|
if (!lang) throw new FormatError(`Unknown ${type} language.`);
|
||||||
if (withTestlib) copyIn = { ...copyIn, 'testlib.h': testlibFile };
|
if (withTestlib) copyIn = { ...copyIn, 'testlib.h': testlibFile };
|
||||||
// TODO cache compiled binary
|
// TODO cache compiled binary
|
||||||
return await compile(lang, { src }, copyIn);
|
return await compile(lang, { src }, copyIn, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function compileChecker(getLang: Function, checkerType: string, checker: string, copyIn: CopyIn) {
|
export async function compileChecker(getLang: Function, checkerType: string, checker: string, copyIn: CopyIn, next?: any) {
|
||||||
if (['default', 'strict'].includes(checkerType)) {
|
if (['default', 'strict'].includes(checkerType)) {
|
||||||
return { execute: '', copyIn: {}, clean: () => Promise.resolve(null) };
|
return { execute: '', copyIn: {}, clean: () => Promise.resolve(null) };
|
||||||
}
|
}
|
||||||
if (!checkers[checkerType]) throw new FormatError('Unknown checker type {0}.', [checkerType]);
|
if (!checkers[checkerType]) throw new FormatError('Unknown checker type {0}.', [checkerType]);
|
||||||
return _compile(checker, 'checker', getLang, copyIn, checkerType === 'testlib');
|
return _compile(checker, 'checker', getLang, copyIn, checkerType === 'testlib', next);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function compileInteractor(getLang: Function, interactor: string, copyIn: CopyIn) {
|
export async function compileInteractor(getLang: Function, interactor: string, copyIn: CopyIn) {
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ export const judge = async (ctx: Context) => await runFlow(ctx, {
|
|||||||
(ctx.config.judge_extra_files || []).map((i) => [basename(i), { src: i }]),
|
(ctx.config.judge_extra_files || []).map((i) => [basename(i), { src: i }]),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
ctx.next,
|
||||||
).then(markCleanup),
|
).then(markCleanup),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user