clang-tidy parser and executor #26

Merged
张泊明518370910136 merged 26 commits from clang-tidy into master 2024-05-18 02:50:13 +08:00
9 changed files with 2079 additions and 48 deletions
Showing only changes of commit ecb2f02182 - Show all commits

View File

@ -53,9 +53,12 @@ func TestMain(t *testing.T) {
{Score: 100, Comment: "executor status: run time: \\d+ ns, memory: \\d+ bytes"}, {Score: 100, Comment: "executor status: run time: \\d+ ns, memory: \\d+ bytes"},
}}, }},
}}, }},
{"clang_tidy", []stage.StageResult{ {"clang-tidy", []stage.StageResult{
zjc_he marked this conversation as resolved Outdated

ditto

ditto
{Name: "prepare", Results: []stage.ParserResult{
{Score: 0, Comment: ""},
}},
{Name: "clang-tidy", Results: []stage.ParserResult{ {Name: "clang-tidy", Results: []stage.ParserResult{
{Score: -200, Comment: ""}, {Score: 10, Comment: ""},
}}, }},
}}, }},
{"compile_error", []stage.StageResult{ {"compile_error", []stage.StageResult{

View File

@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(MyProject)
add_executable(main sillycode.cpp)

View File

@ -0,0 +1,62 @@
skipGitea = true
[[stages]]
name = "prepare"
[stages.executor]
name = "sandbox"
[stages.executor.with.default]
args = ["cmake", "-S", ".", "-DDRONE=ON", "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", "-B", "build"]
env = ["PATH=/usr/bin:/bin"]
cpuLimit = 10_000_000_000
memoryLimit = 104_857_600
procLimit = 50
copyInCwd = true
copyOut = ["stdout"]
copyOutCached = ["build/compile_commands.json"]
[stages.executor.with.default.stdin]
content = ""
[stages.executor.with.default.stdout]
name = "stdout"
max = 65_536
[stages.executor.with.default.stderr]
name = "stderr"
max = 65_536
[stages.parser]
name = "dummy"
[stages.parser.with]
score = 0
comment = ""
[[stages]]
name = "clang-tidy"
[stages.executor]
name = "sandbox"
[stages.executor.with.default]
args = ["clang-tidy", "--header-filter=.*", "--quiet", "-checks=*", "sillycode.cpp", "-p", "build"]
env = ["PATH=/usr/bin:/bin"]
cpuLimit = 10_000_000_000
memoryLimit = 104_857_600
procLimit = 50
copyInCwd = true
copyOut = ["stdout"]
[stages.executor.with.default.stdin]
content = ""
[stages.executor.with.default.stdout]
name = "stdout"
max = 65_536
[stages.executor.with.default.stderr]
name = "stderr"
max = 65_536
[stages.executor.with.default.copyInCached]
"build/compile_commands.json" = "build/compile_commands.json"
[stages.parser]
name = "clang-tidy"
[stages.parser.with]
score = 100
[[stages.parser.with.matches]]
keyword = ["cppcoreguidelines-avoid-non-const-global-variables"]
score = 5
[[stages.parser.with.matches]]
keyword = ["readability-identifier-length","misc-use-anonymous-namespace"]
score = 2
[[stages.parser.with.matches]]
keyword = ["llvmlibc-implementation-in-namespace"]
score = 0

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
skipGitea = true
[[stages]]
name = "clang-tidy"
[stages.executor]
name = "clang-tidy"
[stages.executor.with.default]
args = ["clang-tidy", "--header-filter=.*", "--quiet", "-checks=*", "sillycode.cpp"]
env = ["PATH=/usr/bin:/bin"]
[stages.executor.with.default.copyIn.dummy]
src = "./../../build/dummy"
copyOut = ["stdout", "stderr"]
[stages.executor.with.default.stdin]
content = ""
[stages.executor.with.default.stdout]
name = "stdout"
max = 65_536
[stages.executor.with.default.stderr]
name = "stderr"
max = 65_536
[stages.parser]
name = "clang-tidy"
[stages.parser.with]
score = 100
[[stages.parser.with.matches]]
keyword = ["cppcoreguidelines-avoid-non-const-global-variables"]
score = 5
[[stages.parser.with.matches]]
keyword = ["readability-identifier-length","misc-use-anonymous-namespace"]
score = 2
[[stages.parser.with.matches]]
keyword = ["llvmlibc-implementation-in-namespace"]
score = 0

View File

@ -2,7 +2,6 @@
package clang_tidy package clang_tidy
import ( import (
"os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -111,7 +110,8 @@ func group_messages(messages []ClangMessage) []ClangMessage {
} }
func convert_paths_to_relative(messages *[]ClangMessage) { func convert_paths_to_relative(messages *[]ClangMessage) {
currentDir, _ := os.Getwd() // currentDir, _ := os.Getwd()
zjc_he marked this conversation as resolved Outdated

I think it should be part of the config file with default value "/w". Since the work dir in the sandbox can also be changed, it should not be hardcoded.

I think it should be part of the config file with default value `"/w"`. Since the work dir in the sandbox can also be changed, it should not be hardcoded.
currentDir := "/w"
for i := range *messages { for i := range *messages {
(*messages)[i].filepath, _ = filepath.Rel(currentDir, (*messages)[i].filepath) (*messages)[i].filepath, _ = filepath.Rel(currentDir, (*messages)[i].filepath)
} }

View File

@ -2,12 +2,10 @@ package clang_tidy
import ( import (
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"strings" "strings"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
"github.com/criyle/go-judge/envexec"
) )
type Match struct { type Match struct {
@ -24,7 +22,6 @@ type ClangTidy struct{}
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
stdout := executorResult.Files["stdout"] stdout := executorResult.Files["stdout"]
stderr := executorResult.Files["stderr"]
lines := strings.SplitAfter(stdout, "\n") lines := strings.SplitAfter(stdout, "\n")
messages := parse_lines(lines) messages := parse_lines(lines)
@ -39,15 +36,15 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
encoder.SetIndent("", " ") encoder.SetIndent("", " ")
_ = encoder.Encode(formatted_messages) _ = encoder.Encode(formatted_messages)
if executorResult.Status != stage.Status(envexec.StatusAccepted) { // if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{ // return stage.ParserResult{
Score: 0, // Score: 0,
Comment: fmt.Sprintf( // Comment: fmt.Sprintf(
"Unexpected executor status: %s.\nStderr: %s", // "Unexpected executor status: %s.\nStderr: %s",
executorResult.Status, stderr, // executorResult.Status, stderr,
), // ),
} // }
} // }
return stage.ParserResult{ return stage.ParserResult{
Score: get_score(formatted_messages, conf), Score: get_score(formatted_messages, conf),
Comment: "", Comment: "",