feat(ClangTidy-struct): Setup of ClangTidy struct, copied from Dummy
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
张佳澈520370910044 2024-03-29 15:08:37 +08:00
parent fb61ad33e3
commit be21a16293
6 changed files with 106 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package executors
import (
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/clang_tidy"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/dummy"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox"
)

View File

@ -0,0 +1,29 @@
package clang_tidy
import (
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
"github.com/criyle/go-judge/envexec"
)
type ClangTidy struct{}
func (e *ClangTidy) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
var res []stage.ExecutorResult
for range cmds {
res = append(res, stage.ExecutorResult{
Status: stage.Status(envexec.StatusInvalid),
ExitStatus: 0,
Error: "I'm a dummy",
Time: 0,
Memory: 0,
RunTime: 0,
Files: map[string]string{},
FileIDs: map[string]string{},
})
}
return res, nil
}
func (e *ClangTidy) Cleanup() error {
return nil
}

View File

@ -0,0 +1,9 @@
package clang_tidy
import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
var name = "clang-tidy"
func init() {
stage.RegisterExecutor(name, &ClangTidy{})
}

View File

@ -1,6 +1,7 @@
package parsers
import (
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/clang_tidy"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/diff"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/dummy"
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/resultstatus"

View File

@ -0,0 +1,9 @@
package clang_tidy
import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
var name = "clang-tidy"
func init() {
stage.RegisterParser(name, &ClangTidy{})
}

View File

@ -0,0 +1,57 @@
package clang_tidy
import (
"encoding/json"
"fmt"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/pkg/dummy"
"github.com/criyle/go-judge/envexec"
)
type Conf struct {
Score int
Comment string
}
type ClangTidy struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf(
"Unexpected executor status: %s.\nStderr: %s",
executorResult.Status, stderr,
),
}
}
var dummyResult dummy.Result
err := json.Unmarshal([]byte(stdout), &dummyResult)
if err != nil {
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf("Failed to parse result: %s", err),
}
}
return stage.ParserResult{
Score: dummyResult.Score + conf.Score,
Comment: dummyResult.Comment + conf.Comment,
}
}
func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
var res []stage.ParserResult
for _, result := range results {
res = append(res, Parse(result, *conf))
}
return res, false, nil
}