Skip to content

Commit 684aedf

Browse files
committed
Golang vendor dir extraction: add extractor option
1 parent 70b4ecf commit 684aedf

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

go/codeql-extractor.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ options:
2727
The default is 'false'.
2828
type: string
2929
pattern: "^(false|true)$"
30+
extract_vendor_dirs:
31+
title: Whether to include Go vendor directories in the CodeQL database.
32+
description: >
33+
A value indicating whether Go vendor directories should be included in the CodeQL database.
34+
The default is 'false'.
35+
type: string
36+
pattern: "^(false|true)$"

go/extractor/extractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
233233
// Construct a list of directory segments to exclude from extraction, starting with ".."
234234
excludedDirs := []string{`\.\.`}
235235

236-
// If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories;
236+
// If CODEQL_EXTRACTOR_GO_[OPTION_]EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories;
237237
// otherwise (the default) is to exclude them from extraction
238238
includeVendor := util.IsVendorDirExtractionEnabled()
239239
if !includeVendor {

go/extractor/util/extractvendordirs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import (
55
)
66

77
func IsVendorDirExtractionEnabled() bool {
8-
return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true"
8+
return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" ||
9+
os.Getenv("CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_VENDOR_DIRS") == "true"
910
}

go/ql/integration-tests/extract-vendor/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
def test(codeql, go):
55
os.environ["CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS"] = "true"
66
codeql.database.create(source_root="src")
7+
8+
def test_extractor_option(codeql, go):
9+
codeql.database.create(source_root="src", extractor_option = "extract_vendor_dirs=true")

0 commit comments

Comments
 (0)