diff --git a/Makefile b/Makefile index 1ea1b08..94be716 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ .PHONY: all clean test BUILD_DIR = ./build -APP_NAME = joj3 +APPS := $(notdir $(wildcard ./cmd/*)) all: - go build -o $(BUILD_DIR)/$(APP_NAME) ./cmd/$(APP_NAME) + $(foreach APP,$(APPS), go build -o $(BUILD_DIR)/$(APP) ./cmd/$(APP);) clean: rm -rf $(BUILD_DIR)/* diff --git a/README.md b/README.md index 0753039..cc86608 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Each stage contains a executor and parser. Executor takes a `Cmd` and returns a `ExecutorResult`. -Parser takes a `ExecutorResult` and its config and returns a `ParserResult` and `bool` to indicate whether we should skip the rest stages. +Parser takes a `ExecutorResult` and its conf and returns a `ParserResult` and `bool` to indicate whether we should skip the rest stages. ### `Cmd` diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 1de41d9..1b67274 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -68,7 +68,7 @@ func parseConfFile(path string) Conf { conf := Conf{} err := m.Load(&conf) if err != nil { - slog.Error("parse stages config", "error", err) + slog.Error("parse stages conf", "error", err) os.Exit(1) } return conf diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index af4275b..9cd2837 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -51,13 +51,13 @@ func generateStages(conf Conf) []stage.Stage { if len(s.Executor.With.Cases) == 0 { cmds = []stage.Cmd{defaultCmd} } - slog.Debug("parse stages config", "cmds", cmds) + slog.Debug("parse stages conf", "cmds", cmds) stages = append(stages, stage.Stage{ Name: s.Name, ExecutorName: s.Executor.Name, ExecutorCmds: cmds, ParserName: s.Parser.Name, - ParserConfig: s.Parser.With, + ParserConf: s.Parser.With, }) } return stages diff --git a/internal/executors/sandbox/meta.go b/internal/executors/sandbox/meta.go index c78ee7c..c22b750 100644 --- a/internal/executors/sandbox/meta.go +++ b/internal/executors/sandbox/meta.go @@ -8,7 +8,7 @@ var name = "sandbox" func init() { stage.RegisterExecutor(name, &Sandbox{ - // TODO: read from config + // TODO: read from conf execClient: createExecClient("localhost:5051", ""), cachedMap: make(map[string]string), }) diff --git a/internal/parsers/diff/parser.go b/internal/parsers/diff/parser.go index c93e780..7c70d9f 100644 --- a/internal/parsers/diff/parser.go +++ b/internal/parsers/diff/parser.go @@ -7,7 +7,7 @@ import ( "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" ) -type Config struct { +type Conf struct { Cases []struct { Score int StdoutPath string @@ -16,27 +16,27 @@ type Config struct { type Diff struct{} -func (*Diff) Run(results []stage.ExecutorResult, configAny any) ( +func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { - config, err := stage.DecodeConfig[Config](configAny) + conf, err := stage.DecodeConf[Conf](confAny) if err != nil { return nil, true, err } - if len(config.Cases) != len(results) { + if len(conf.Cases) != len(results) { return nil, true, fmt.Errorf("cases number not match") } var res []stage.ParserResult - for i, caseConfig := range config.Cases { + for i, caseConf := range conf.Cases { result := results[i] score := 0 - stdout, err := os.ReadFile(caseConfig.StdoutPath) + stdout, err := os.ReadFile(caseConf.StdoutPath) if err != nil { return nil, true, err } // TODO: more compare strategies if string(stdout) == result.Files["stdout"] { - score = caseConfig.Score + score = caseConf.Score } res = append(res, stage.ParserResult{ Score: score, diff --git a/internal/parsers/dummy/parser.go b/internal/parsers/dummy/parser.go index a572eb5..34abf28 100644 --- a/internal/parsers/dummy/parser.go +++ b/internal/parsers/dummy/parser.go @@ -6,27 +6,27 @@ import ( "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" ) -type Config struct { +type Conf struct { Score int Comment string } type Dummy struct{} -func (*Dummy) Run(results []stage.ExecutorResult, configAny any) ( +func (*Dummy) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { - config, err := stage.DecodeConfig[Config](configAny) + conf, err := stage.DecodeConf[Conf](confAny) if err != nil { return nil, true, err } var res []stage.ParserResult for _, result := range results { res = append(res, stage.ParserResult{ - Score: config.Score, + Score: conf.Score, Comment: fmt.Sprintf( "%s, executor status: run time: %d ns, memory: %d bytes", - config.Comment, result.RunTime, result.Memory, + conf.Comment, result.RunTime, result.Memory, ), }) } diff --git a/internal/parsers/resultstatus/parser.go b/internal/parsers/resultstatus/parser.go index f38a5c9..b023a76 100644 --- a/internal/parsers/resultstatus/parser.go +++ b/internal/parsers/resultstatus/parser.go @@ -7,15 +7,15 @@ import ( "github.com/criyle/go-judge/envexec" ) -type Config struct{} +type Conf struct{} type ResultStatus struct{} -func (*ResultStatus) Run(results []stage.ExecutorResult, configAny any) ( +func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { - // TODO: more config options - _, err := stage.DecodeConfig[Config](configAny) + // TODO: more conf options + _, err := stage.DecodeConf[Conf](confAny) if err != nil { return nil, true, err } diff --git a/internal/stage/model.go b/internal/stage/model.go index 61eda07..848e4ec 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -155,7 +155,7 @@ type Stage struct { ExecutorName string ExecutorCmds []Cmd ParserName string - ParserConfig any + ParserConf any } type ParserResult struct { diff --git a/internal/stage/run.go b/internal/stage/run.go index b77ac5f..da81992 100644 --- a/internal/stage/run.go +++ b/internal/stage/run.go @@ -19,9 +19,9 @@ func Run(stages []Stage) []StageResult { break } slog.Debug("executor run done", "results", executorResults) - slog.Debug("parser run start", "config", stage.ParserConfig) + slog.Debug("parser run start", "conf", stage.ParserConf) parser := parserMap[stage.ParserName] - parserResults, end, err := parser.Run(executorResults, stage.ParserConfig) + parserResults, end, err := parser.Run(executorResults, stage.ParserConf) if err != nil { slog.Error("parser run error", "name", stage.ExecutorName, "error", err) break diff --git a/internal/stage/util.go b/internal/stage/util.go index 0825f8f..4c9f084 100644 --- a/internal/stage/util.go +++ b/internal/stage/util.go @@ -2,11 +2,11 @@ package stage import "github.com/mitchellh/mapstructure" -func DecodeConfig[T any](configAny any) (*T, error) { - var config T - err := mapstructure.Decode(configAny, &config) +func DecodeConf[T any](confAny any) (*T, error) { + var conf T + err := mapstructure.Decode(confAny, &conf) if err != nil { return nil, err } - return &config, nil + return &conf, nil }