judge: auto apply compile.sh and execute.sh

This commit is contained in:
undefined committed 2022-03-11 12:43:23 +08:00
1 parent b13bf24031
commit 7acaf00e78
2 files changed
+11 -7

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.14.2", "version": "2.14.3",
"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",
+10 -6
View File
@@ -10,25 +10,29 @@ export = async function compile(
lang: LangConfig, code: string, copyIn: Record<string, CopyInFile> = {}, next?: Function, lang: LangConfig, code: string, copyIn: Record<string, CopyInFile> = {}, next?: Function,
): Promise<Execute> { ): Promise<Execute> {
const target = lang.target || 'foo'; const target = lang.target || 'foo';
copyIn[lang.code_file] = { content: code }; const execute = copyIn['execute.sh'] ? '/bin/bash execute.sh' : lang.execute;
const time = lang.time_limit_rate || 1;
if (lang.compile) { if (lang.compile) {
const { const {
status, stdout, stderr, fileIds, status, stdout, stderr, fileIds,
} = await run( } = await run(
lang.compile, copyIn['compile.sh'] ? '/bin/bash compile.sh' : lang.compile,
{ copyIn, copyOutCached: [target] }, { copyIn: { ...copyIn, [lang.code_file]: { content: code } }, copyOutCached: [target] },
); );
if (status !== STATUS.STATUS_ACCEPTED) throw new CompileError({ status, stdout, stderr }); if (status !== STATUS.STATUS_ACCEPTED) throw new CompileError({ status, stdout, stderr });
if (!fileIds[target]) throw new CompileError({ stderr: 'Executable file not found.' }); if (!fileIds[target]) throw new CompileError({ stderr: 'Executable file not found.' });
if (next) next({ compiler_text: compilerText(stdout, stderr) }); if (next) next({ compiler_text: compilerText(stdout, stderr) });
return { return {
execute: lang.execute, execute,
copyIn: { ...copyIn, [target]: { fileId: fileIds[target] } }, copyIn: { ...copyIn, [target]: { fileId: fileIds[target] } },
clean: () => del(fileIds[target]), clean: () => del(fileIds[target]),
time: lang.time_limit_rate || 1, time,
}; };
} }
return { return {
execute: lang.execute, copyIn, clean: () => Promise.resolve(null), time: lang.time_limit_rate || 1, execute,
copyIn: { ...copyIn, [lang.code_file]: { content: code } },
clean: () => Promise.resolve(null),
time,
}; };
}; };