Skip to content

Commit f1f6f9b

Browse files
committed
Share vendor-dir extraction logic between extractor and configure-baseline script
1 parent 22802fd commit f1f6f9b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

go/extractor/configurebaseline/configurebaseline.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os"
77
"path"
88
"path/filepath"
9+
10+
"github.com/github/codeql-go/extractor/util"
911
)
1012

1113
func fileExists(path string) bool {
@@ -26,7 +28,7 @@ type BaselineConfig struct {
2628
func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) {
2729
vendorDirs := make([]string, 0)
2830

29-
if os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" {
31+
if util.IsVendorDirExtractionEnabled() {
3032
// The user wants vendor directories scanned; emit an empty report.
3133
} else {
3234
filepath.WalkDir(rootDir, func(dirPath string, d fs.DirEntry, err error) error {

go/extractor/extractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
199199

200200
// If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories;
201201
// otherwise (the default) is to exclude them from extraction
202-
includeVendor := os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
202+
includeVendor := util.IsVendorDirExtractionEnabled()
203203
if !includeVendor {
204204
excludedDirs = append(excludedDirs, "vendor")
205205
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package util
2+
3+
import (
4+
"os"
5+
)
6+
7+
func IsVendorDirExtractionEnabled() bool {
8+
return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
9+
}

0 commit comments

Comments
 (0)