fix: parse config
This commit is contained in:
parent
5c15388882
commit
0e87ad8943
1
_example/simple/.gitignore
vendored
Normal file
1
_example/simple/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
!*.out
|
|
@ -1,10 +1,10 @@
|
|||
logLevel = 8
|
||||
logLevel = 0
|
||||
[[stages]]
|
||||
name = "compile"
|
||||
[stages.executor]
|
||||
name = "sandbox"
|
||||
[stages.executor.with.default]
|
||||
args = ["/usr/bin/g++", "a.cc", "-o", "a"]
|
||||
args = ["g++", "a.cc", "-o", "a"]
|
||||
env = ["PATH=/usr/bin:/bin"]
|
||||
cpuLimit = 10_000_000_000
|
||||
memoryLimit = 104_857_600
|
||||
|
@ -36,31 +36,25 @@ cpuLimit = 10_000_000_000
|
|||
memoryLimit = 104_857_600
|
||||
procLimit = 50
|
||||
copyOut = ["stdout", "stderr"]
|
||||
[stages.executor.with.default.stdout]
|
||||
name = "stdout"
|
||||
max = 4_096
|
||||
[stages.executor.with.default.stderr]
|
||||
name = "stderr"
|
||||
max = 4_096
|
||||
[stages.executor.with.default.copyInCached]
|
||||
a = "a"
|
||||
[[stages.executor.with.cases]]
|
||||
[stages.executor.with.cases.stdin]
|
||||
src = "1.stdin"
|
||||
[stages.executor.with.cases.stdout]
|
||||
name = "stdout"
|
||||
max = 4_096
|
||||
[stages.executor.with.cases.stderr]
|
||||
name = "stderr"
|
||||
max = 4_096
|
||||
src = "./cases/1.in"
|
||||
[[stages.executor.with.cases]]
|
||||
[stages.executor.with.cases.stdin]
|
||||
src = "2.stdin"
|
||||
[stages.executor.with.cases.stdout]
|
||||
name = "stdout"
|
||||
max = 4_096
|
||||
[stages.executor.with.cases.stderr]
|
||||
name = "stderr"
|
||||
max = 4_096
|
||||
src = "./cases/2.in"
|
||||
[stages.parser]
|
||||
name = "diff"
|
||||
[[stages.parser.with.cases]]
|
||||
score = 100
|
||||
stdoutPath = "1.stdout"
|
||||
stdoutPath = "./cases/1.out"
|
||||
[[stages.parser.with.cases]]
|
||||
score = 100
|
||||
stdoutPath = "2.stdout"
|
||||
stdoutPath = "./cases/2.out"
|
||||
|
|
|
@ -21,6 +21,13 @@ type Conf struct {
|
|||
}
|
||||
}
|
||||
|
||||
func DefaultConf() Conf {
|
||||
return Conf{
|
||||
LogLevel: 0,
|
||||
OutputPath: "joj3_result.json",
|
||||
}
|
||||
}
|
||||
|
||||
type OptionalCmd struct {
|
||||
Args *[]string
|
||||
Env *[]string
|
||||
|
|
|
@ -21,11 +21,7 @@ func parseConfFile(tomlPath *string) Conf {
|
|||
slog.Error("read toml config", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// fill in default value of config file
|
||||
conf := Conf{
|
||||
LogLevel: 0,
|
||||
OutputPath: "joj3_result.json",
|
||||
}
|
||||
conf := DefaultConf()
|
||||
err = toml.Unmarshal(tomlConfig, &conf)
|
||||
if err != nil {
|
||||
slog.Error("parse stages config", "error", err)
|
||||
|
@ -47,6 +43,7 @@ func generateStages(conf Conf) []stage.Stage {
|
|||
stages := []stage.Stage{}
|
||||
for _, s := range conf.Stages {
|
||||
var cmds []stage.Cmd
|
||||
defaultCmd := s.Executor.With.Default
|
||||
for _, optionalCmd := range s.Executor.With.Cases {
|
||||
cmd := s.Executor.With.Default
|
||||
err := copier.Copy(&cmd, &optionalCmd)
|
||||
|
@ -54,10 +51,21 @@ func generateStages(conf Conf) []stage.Stage {
|
|||
slog.Error("generate stages", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// since these 3 values are pointers, copier will always copy
|
||||
// them, so we need to check them manually
|
||||
if defaultCmd.Stdin != nil && optionalCmd.Stdin == nil {
|
||||
cmd.Stdin = defaultCmd.Stdin
|
||||
}
|
||||
if defaultCmd.Stdout != nil && optionalCmd.Stdout == nil {
|
||||
cmd.Stdout = defaultCmd.Stdout
|
||||
}
|
||||
if defaultCmd.Stderr != nil && optionalCmd.Stderr == nil {
|
||||
cmd.Stderr = defaultCmd.Stderr
|
||||
}
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
if len(s.Executor.With.Cases) == 0 {
|
||||
cmds = append(cmds, s.Executor.With.Default)
|
||||
cmds = []stage.Cmd{defaultCmd}
|
||||
}
|
||||
slog.Info("parse stages config", "cmds", cmds)
|
||||
stages = append(stages, stage.Stage{
|
||||
|
|
Loading…
Reference in New Issue
Block a user