mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
hydrojudge intergration
This commit is contained in:
1 parent
2a09213f5d
commit
6b88570bd6
24 files changed
+1719
-9
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import yaml from 'js-yaml';
|
||||
import { STATUS } from 'hydrooj/dist/model/builtin';
|
||||
import { run, del } from './sandbox';
|
||||
import { CompileError, SystemError } from './error';
|
||||
import { compilerText } from './utils';
|
||||
|
||||
export = async function compile(
|
||||
lang: string, code: string, target: string, copyIn: any, next?: Function,
|
||||
) {
|
||||
const LANGS = yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs'));
|
||||
if (!LANGS[lang]) throw new SystemError(`不支持的语言:${lang}`);
|
||||
const info = LANGS[lang];
|
||||
const f = {};
|
||||
if (info.type === 'compiler') {
|
||||
copyIn[info.code_file] = { content: code };
|
||||
const {
|
||||
status, stdout, stderr, fileIds,
|
||||
} = await run(
|
||||
info.compile.replace(/\$\{name\}/g, target),
|
||||
{ copyIn, copyOutCached: [target] },
|
||||
);
|
||||
if (status !== STATUS.STATUS_ACCEPTED) throw new CompileError({ status, stdout, stderr });
|
||||
if (!fileIds[target]) throw new CompileError({ stderr: '没有找到可执行文件' });
|
||||
if (next) next({ compiler_text: compilerText(stdout, stderr) });
|
||||
f[target] = { fileId: fileIds[target] };
|
||||
return { execute: info.execute, copyIn: f, clean: () => del(fileIds[target]) };
|
||||
} if (info.type === 'interpreter') {
|
||||
f[target] = { content: code };
|
||||
return { execute: info.execute, copyIn: f, clean: () => Promise.resolve() };
|
||||
}
|
||||
throw new SystemError('Unknown language type');
|
||||
}
|
||||
Reference in new issue
Block a user