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"},
}},
}},
{"clang_tidy", []stage.StageResult{
{"clang-tidy", []stage.StageResult{
{Name: "prepare", Results: []stage.ParserResult{
{Score: 0, Comment: ""},
}},
{Name: "clang-tidy", Results: []stage.ParserResult{
{Score: -200, Comment: ""},
{Score: 10, Comment: ""},
}},
}},
{"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
import (
"os"
"path/filepath"
"regexp"
"strconv"
@ -111,7 +110,8 @@ func group_messages(messages []ClangMessage) []ClangMessage {
}
func convert_paths_to_relative(messages *[]ClangMessage) {
currentDir, _ := os.Getwd()
// currentDir, _ := os.Getwd()
currentDir := "/w"
for i := range *messages {
(*messages)[i].filepath, _ = filepath.Rel(currentDir, (*messages)[i].filepath)
}

View File

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