woj-server/resource/runner/scripts/problem.sh

76 lines
1.8 KiB
Bash
Raw Normal View History

2022-10-20 18:21:11 +08:00
#!/usr/bin/env bash
. common.sh
# get_problem_info
# extract language info and limits
# $1: workspace
# $2: problem name
# $3: language
# exports: Info_Script, Info_Cmp, Info_Num, Info_Limit_Time, Info_Limit_Memory, Info_Limit_NProc
function get_problem_info() {
2023-08-11 18:54:00 +08:00
local err
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
if [ ! -f "$1/problem/$2/config.json" ]; then
log_error "problem $2 not found"
return 1
fi
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
parse_language_info "$1" "$2" "$3"
err=$?
if [ "$err" -ne 0 ]; then
return "$err"
fi
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
parse_limits "$1" "$2"
err=$?
if [ "$err" -ne 0 ]; then
return "$err"
fi
2022-10-20 18:21:11 +08:00
}
function parse_language_info() {
2023-08-11 18:54:00 +08:00
export Info_Script
export Info_Cmp
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
local lang_config
local lang_type
local lang_script
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
lang_config=$(jq ".Languages[] | select(.Lang == \"$3\")" "$1/problem/$2/config.json")
if [ -z "$lang_config" ]; then
log_error "language $3 is not supported"
return 1
fi
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
Info_Cmp=$(echo "$lang_config" | jq -r ".Cmp")
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
lang_type=$(echo "$lang_config" | jq -r ".Type")
lang_script=$(echo "$lang_config" | jq -r ".Script")
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
if [ "$lang_type" == "custom" ]; then
Info_Script="/woj/problem/judge/$lang_script"
elif [ "$lang_type" == "default" ]; then
Info_Script="/woj/framework/template/default/$3.Makefile"
else
log_warn "Config file might be corrupted!"
log_error "Unknown language type: $lang_type"
return 1
fi
2022-10-20 18:21:11 +08:00
}
function parse_limits() {
2023-08-11 18:54:00 +08:00
export Info_Limit_Time
export Info_Limit_Memory
export Info_Limit_NProc
export Info_Num
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
local cfg
cfg="$1/problem/$2/config.json"
2022-10-20 18:21:11 +08:00
2023-08-11 18:54:00 +08:00
Info_Limit_Time=$(jq ".Runtime.TimeLimit" "$cfg")
Info_Limit_Memory=$(jq ".Runtime.MemoryLimit" "$cfg")
Info_Limit_NProc=$(jq ".Runtime.NProcLimit" "$cfg")
Info_Num=$(jq ".Tasks | length" "$1/problem/$2/config.json")
2022-10-20 18:21:11 +08:00
}