Skip to content

Commit

Permalink
Share vendor-dir extraction logic between extractor and configure-bas…
Browse files Browse the repository at this point in the history
…eline script
  • Loading branch information
smowton committed Aug 19, 2024
1 parent ff50906 commit bcd6f0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion go/extractor/configurebaseline/configurebaseline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"path"
"path/filepath"

"github.com/github/codeql-go/extractor/util"
)

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

if os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" {
if util.IsVendorDirExtractionEnabled() {
// The user wants vendor directories scanned; emit an empty report.
} else {
filepath.WalkDir(rootDir, func(dirPath string, d fs.DirEntry, err error) error {
Expand Down
2 changes: 1 addition & 1 deletion go/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {

// If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories;
// otherwise (the default) is to exclude them from extraction
includeVendor := os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
includeVendor := util.IsVendorDirExtractionEnabled()
if !includeVendor {
excludedDirs = append(excludedDirs, "vendor")
}
Expand Down
9 changes: 9 additions & 0 deletions go/extractor/util/extractvendordirs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package util

import (
"os"
)

func IsVendorDirExtractionEnabled() bool {
return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
}

0 comments on commit bcd6f0b

Please sign in to comment.