mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 01:38:19 +08:00
judge: allow runtimeErrorAnalysis hook
This commit is contained in:
1 parent
cdc6ba8453
commit
d225be35c9
5 files changed
+34
-1
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"bin": "bin/hydrojudge.js",
|
||||
"version": "2.14.10",
|
||||
"version": "2.15.0",
|
||||
"main": "package.json",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -82,6 +82,22 @@ function judgeCase(c: Case, sid: string) {
|
||||
} else if (status === STATUS.STATUS_RUNTIME_ERROR && code) {
|
||||
if (code < 32) message = signals[code];
|
||||
else message = { message: 'Your program returned {0}.', params: [code] };
|
||||
const langConfig = ctx.getLang(ctx.lang);
|
||||
if (langConfig.runtimeErrorAnalysis && !this.runtimeErrorAnalysis) {
|
||||
this.runtimeErrorAnalysis = true;
|
||||
run(langConfig.runtimeErrorAnalysis, {
|
||||
copyIn: {
|
||||
input: { src: stdin },
|
||||
[langConfig.code_file || 'foo']: { content: ctx.code },
|
||||
compile: { content: langConfig.compile },
|
||||
execute: { content: langConfig.execute },
|
||||
},
|
||||
time: 5000,
|
||||
memory: 256,
|
||||
})
|
||||
.then((r) => ctx.next({ compiler_text: r.stdout.toString().substring(0, 1024) }))
|
||||
.catch((e) => console.error(e));
|
||||
}
|
||||
}
|
||||
await Promise.all(
|
||||
Object.values(res.fileIds).map((id) => del(id)),
|
||||
|
||||
@@ -6,6 +6,7 @@ export type Context = JudgeTaskInterface & RuntimeContext;
|
||||
|
||||
export interface JudgeTaskInterface {
|
||||
next(arg0: {
|
||||
compiler_text?: string;
|
||||
status?: number;
|
||||
message?: string;
|
||||
progress?: number;
|
||||
|
||||
@@ -79,6 +79,21 @@ export const judge = async (ctx: Context) => {
|
||||
status = STATUS.STATUS_RUNTIME_ERROR;
|
||||
if (code < 32) message.push(`ExitCode: ${code} (${signals[code]})`);
|
||||
else message.push(`ExitCode: ${code}`);
|
||||
const langConfig = ctx.getLang(ctx.lang);
|
||||
if (langConfig.runtimeErrorAnalysis) {
|
||||
run(langConfig.runtimeErrorAnalysis, {
|
||||
copyIn: {
|
||||
input: { src: stdin },
|
||||
[langConfig.code_file || 'foo']: { content: ctx.code },
|
||||
compile: { content: langConfig.compile },
|
||||
execute: { content: langConfig.execute },
|
||||
},
|
||||
time: 5000,
|
||||
memory: 256,
|
||||
})
|
||||
.then((r) => ctx.next({ compiler_text: r.stdout.toString().substring(0, 1024) }))
|
||||
.catch((e) => console.error(e));
|
||||
}
|
||||
}
|
||||
message.push(fs.readFileSync(stdout).toString());
|
||||
message.push(fs.readFileSync(stderr).toString());
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface LangConfig {
|
||||
target?: string;
|
||||
key: string;
|
||||
hidden: boolean;
|
||||
runtimeErrorAnalysis?: string;
|
||||
}
|
||||
|
||||
export function parseLang(config: string): Record<string, LangConfig> {
|
||||
|
||||
Reference in new issue
Block a user