judge: fix custom lang

This commit is contained in:
undefined committed 2025-08-10 01:37:22 +08:00
1 parent 4fa00f5bc9
commit 2c9b3a1fde
1 file changed
+13 -6
+13 -6
View File
@@ -8,21 +8,28 @@ export async function readYamlCases(cfg: ProblemConfigFile = {}, checkFile = (s:
judge_extra_files: [],
user_extra_files: [],
};
const checkFileWithLang = (s: CompilableSource, errMsg: string) => {
if (typeof s === 'string') return { lang: 'auto', file: checkFile(s, errMsg) };
return { lang: s.lang, file: checkFile(s.file, errMsg) };
};
if (cfg.type === 'objective') {
if (cfg.checker || cfg.interactor || cfg.validator) {
throw new Error('You cannot use checker, interactor or validator for objective questions');
}
} else {
if (cfg.checker) {
const name = typeof cfg.checker === 'string' ? cfg.checker : cfg.checker.file;
const [name, lang] = typeof cfg.checker === 'string' ? [cfg.checker, 'auto'] : [cfg.checker.file, cfg.checker.lang || 'auto'];
if (!name.includes('.')) {
config.checker = findFileSync(`@hydrooj/hydrojudge/vendor/testlib/checkers/${name}.cpp`, false);
config.checker = {
lang,
file: findFileSync(`@hydrooj/hydrojudge/vendor/testlib/checkers/${name}.cpp`, false),
};
}
config.checker ||= checkFile(cfg.checker, 'Cannot find checker {0}.');
config.checker ||= checkFileWithLang(name, 'Cannot find checker {0}.');
}
if (cfg.interactor) config.interactor = checkFile(cfg.interactor, 'Cannot find interactor {0}.');
if (cfg.manager) config.manager = checkFile(cfg.manager, 'Cannot find Manager {0}.');
if (cfg.validator) config.validator = checkFile(cfg.validator, 'Cannot find validator {0}.');
if (cfg.interactor) config.interactor = checkFileWithLang(cfg.interactor, 'Cannot find interactor {0}.');
if (cfg.manager) config.manager = checkFileWithLang(cfg.manager, 'Cannot find Manager {0}.');
if (cfg.validator) config.validator = checkFileWithLang(cfg.validator, 'Cannot find validator {0}.');
for (const n of ['judge', 'user']) {
const conf = cfg[`${n}_extra_files`];
if (!conf) continue;