diff --git a/go/codeql-extractor.yml b/go/codeql-extractor.yml index f21c0ed7466..49c8c75232f 100644 --- a/go/codeql-extractor.yml +++ b/go/codeql-extractor.yml @@ -27,3 +27,10 @@ options: The default is 'false'. type: string pattern: "^(false|true)$" + extract_vendor_dirs: + title: Whether to include Go vendor directories in the CodeQL database. + description: > + A value indicating whether Go vendor directories should be included in the CodeQL database. + The default is 'false'. + type: string + pattern: "^(false|true)$" diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index f372cc16180..eeb1513e724 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -233,7 +233,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool) // Construct a list of directory segments to exclude from extraction, starting with ".." excludedDirs := []string{`\.\.`} - // If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories; + // If CODEQL_EXTRACTOR_GO_[OPTION_]EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories; // otherwise (the default) is to exclude them from extraction includeVendor := util.IsVendorDirExtractionEnabled() if !includeVendor { diff --git a/go/extractor/util/extractvendordirs.go b/go/extractor/util/extractvendordirs.go index 778d5120cf2..eadf5d24740 100644 --- a/go/extractor/util/extractvendordirs.go +++ b/go/extractor/util/extractvendordirs.go @@ -5,5 +5,6 @@ import ( ) func IsVendorDirExtractionEnabled() bool { - return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" + return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" || + os.Getenv("CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_VENDOR_DIRS") == "true" } diff --git a/go/ql/integration-tests/extract-vendor/test.py b/go/ql/integration-tests/extract-vendor/test.py index 04dfd61c38f..ff28cc6fe9a 100644 --- a/go/ql/integration-tests/extract-vendor/test.py +++ b/go/ql/integration-tests/extract-vendor/test.py @@ -4,3 +4,6 @@ import os def test(codeql, go): os.environ["CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS"] = "true" codeql.database.create(source_root="src") + +def test_extractor_option(codeql, go): + codeql.database.create(source_root="src", extractor_option = "extract_vendor_dirs=true")