clang-tidy parser and executor #26
|  | @ -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" | ||||
| ) | ||||
|  |  | |||
							
								
								
									
										29
									
								
								internal/executors/clang_tidy/executor.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								internal/executors/clang_tidy/executor.go
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
							
								
								
									
										9
									
								
								internal/executors/clang_tidy/meta.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								internal/executors/clang_tidy/meta.go
									
									
									
									
									
										Normal 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{}) | ||||
| } | ||||
|  | @ -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" | ||||
|  |  | |||
							
								
								
									
										9
									
								
								internal/parsers/clang_tidy/meta.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								internal/parsers/clang_tidy/meta.go
									
									
									
									
									
										Normal 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{}) | ||||
| } | ||||
							
								
								
									
										57
									
								
								internal/parsers/clang_tidy/parser.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								internal/parsers/clang_tidy/parser.go
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user