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]]
|
[[stages]]
|
||||||
name = "compile"
|
name = "compile"
|
||||||
[stages.executor]
|
[stages.executor]
|
||||||
name = "sandbox"
|
name = "sandbox"
|
||||||
[stages.executor.with.default]
|
[stages.executor.with.default]
|
||||||
args = ["/usr/bin/g++", "a.cc", "-o", "a"]
|
args = ["g++", "a.cc", "-o", "a"]
|
||||||
env = ["PATH=/usr/bin:/bin"]
|
env = ["PATH=/usr/bin:/bin"]
|
||||||
cpuLimit = 10_000_000_000
|
cpuLimit = 10_000_000_000
|
||||||
memoryLimit = 104_857_600
|
memoryLimit = 104_857_600
|
||||||
|
@ -36,31 +36,25 @@ cpuLimit = 10_000_000_000
|
||||||
memoryLimit = 104_857_600
|
memoryLimit = 104_857_600
|
||||||
procLimit = 50
|
procLimit = 50
|
||||||
copyOut = ["stdout", "stderr"]
|
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]
|
[stages.executor.with.default.copyInCached]
|
||||||
a = "a"
|
a = "a"
|
||||||
[[stages.executor.with.cases]]
|
[[stages.executor.with.cases]]
|
||||||
[stages.executor.with.cases.stdin]
|
[stages.executor.with.cases.stdin]
|
||||||
src = "1.stdin"
|
src = "./cases/1.in"
|
||||||
[stages.executor.with.cases.stdout]
|
|
||||||
name = "stdout"
|
|
||||||
max = 4_096
|
|
||||||
[stages.executor.with.cases.stderr]
|
|
||||||
name = "stderr"
|
|
||||||
max = 4_096
|
|
||||||
[[stages.executor.with.cases]]
|
[[stages.executor.with.cases]]
|
||||||
[stages.executor.with.cases.stdin]
|
[stages.executor.with.cases.stdin]
|
||||||
src = "2.stdin"
|
src = "./cases/2.in"
|
||||||
[stages.executor.with.cases.stdout]
|
|
||||||
name = "stdout"
|
|
||||||
max = 4_096
|
|
||||||
[stages.executor.with.cases.stderr]
|
|
||||||
name = "stderr"
|
|
||||||
max = 4_096
|
|
||||||
[stages.parser]
|
[stages.parser]
|
||||||
name = "diff"
|
name = "diff"
|
||||||
[[stages.parser.with.cases]]
|
[[stages.parser.with.cases]]
|
||||||
score = 100
|
score = 100
|
||||||
stdoutPath = "1.stdout"
|
stdoutPath = "./cases/1.out"
|
||||||
[[stages.parser.with.cases]]
|
[[stages.parser.with.cases]]
|
||||||
score = 100
|
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 {
|
type OptionalCmd struct {
|
||||||
Args *[]string
|
Args *[]string
|
||||||
Env *[]string
|
Env *[]string
|
||||||
|
|
|
@ -21,11 +21,7 @@ func parseConfFile(tomlPath *string) Conf {
|
||||||
slog.Error("read toml config", "error", err)
|
slog.Error("read toml config", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
// fill in default value of config file
|
conf := DefaultConf()
|
||||||
conf := Conf{
|
|
||||||
LogLevel: 0,
|
|
||||||
OutputPath: "joj3_result.json",
|
|
||||||
}
|
|
||||||
err = toml.Unmarshal(tomlConfig, &conf)
|
err = toml.Unmarshal(tomlConfig, &conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("parse stages config", "error", err)
|
slog.Error("parse stages config", "error", err)
|
||||||
|
@ -47,6 +43,7 @@ func generateStages(conf Conf) []stage.Stage {
|
||||||
stages := []stage.Stage{}
|
stages := []stage.Stage{}
|
||||||
for _, s := range conf.Stages {
|
for _, s := range conf.Stages {
|
||||||
var cmds []stage.Cmd
|
var cmds []stage.Cmd
|
||||||
|
defaultCmd := s.Executor.With.Default
|
||||||
for _, optionalCmd := range s.Executor.With.Cases {
|
for _, optionalCmd := range s.Executor.With.Cases {
|
||||||
cmd := s.Executor.With.Default
|
cmd := s.Executor.With.Default
|
||||||
err := copier.Copy(&cmd, &optionalCmd)
|
err := copier.Copy(&cmd, &optionalCmd)
|
||||||
|
@ -54,10 +51,21 @@ func generateStages(conf Conf) []stage.Stage {
|
||||||
slog.Error("generate stages", "error", err)
|
slog.Error("generate stages", "error", err)
|
||||||
os.Exit(1)
|
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)
|
cmds = append(cmds, cmd)
|
||||||
}
|
}
|
||||||
if len(s.Executor.With.Cases) == 0 {
|
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)
|
slog.Info("parse stages config", "cmds", cmds)
|
||||||
stages = append(stages, stage.Stage{
|
stages = append(stages, stage.Stage{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user