Golang vendor dir extraction: add extractor option

This commit is contained in:
Chris Smowton
2024-09-30 18:24:49 +01:00
parent 70b4ecf0a5
commit 684aedf6aa
4 changed files with 13 additions and 2 deletions

View File

@@ -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)$"

View File

@@ -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 {

View File

@@ -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"
}

View File

@@ -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")