code-intelligence.com/cifuzz@v0.40.0/internal/cmdutils/bazel.go (about) 1 package cmdutils 2 3 import ( 4 "fmt" 5 "os/exec" 6 "strings" 7 8 "github.com/pkg/errors" 9 10 "code-intelligence.com/cifuzz/pkg/log" 11 ) 12 13 func EvaluateBazelTargetPatterns(patterns []string) ([]string, error) { 14 var fuzzTestLabels []string 15 16 multiPattern := patterns[0] 17 for _, pattern := range patterns[1:] { 18 if strings.HasPrefix(pattern, "-") { 19 multiPattern += " " + pattern 20 } else { 21 multiPattern += " +" + pattern 22 } 23 } 24 25 args := []string{ 26 "query", 27 fmt.Sprintf("kind(fuzzing_regression_test, attr(generator_function, cc_fuzz_test, %s))", multiPattern), 28 } 29 cmd := exec.Command("bazel", args...) 30 log.Debugf("Command: %s", cmd.String()) 31 out, err := cmd.Output() 32 if err != nil { 33 return nil, WrapExecError(errors.WithStack(err), cmd) 34 } 35 lines := strings.Split(strings.ReplaceAll(strings.TrimSpace(string(out)), "\r\n", "\n"), "\n") 36 for _, line := range lines { 37 label := strings.TrimSpace(line) 38 if label != "" { 39 fuzzTestLabels = append(fuzzTestLabels, label) 40 } 41 } 42 43 return fuzzTestLabels, nil 44 }