Convert extract-tests option to an official extractor option

This commit is contained in:
Chris Smowton
2024-08-21 16:04:39 +01:00
parent 94cb99e51d
commit f5ff822681
4 changed files with 11 additions and 4 deletions

View File

@@ -19,3 +19,11 @@ file_types:
extensions:
- .go
legacy_qltest_extraction: true
options:
extract_tests:
title: Whether to include Go test files and functions in the CodeQL database.
description: >
A value indicating whether Go test files and functions should be included in the CodeQL database.
The default is 'false'.
type: string
pattern: "^(false|true)$"

View File

@@ -94,7 +94,7 @@ func parseFlags(args []string, mimic bool, extractTests bool) ([]string, []strin
}
func main() {
extractTestsDefault := os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_TESTS") == "true"
extractTestsDefault := os.Getenv("CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS") == "true"
buildFlags, patterns, extractTests := parseFlags(os.Args[1:], false, extractTestsDefault)
if cpuprofile != "" {

View File

@@ -88,7 +88,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
log.Printf("Running packages.Load%s.", testMessage)
// This includes test packages if either we're tracing a `go test` command,
// or if CODEQL_EXTRACTOR_GO_EXTRACT_TESTS is set to "true".
// or if CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS is set to "true".
cfg := &packages.Config{
Mode: packages.NeedName | packages.NeedFiles |
packages.NeedCompiledGoFiles |

View File

@@ -1,5 +1,4 @@
import os
def test(codeql, go):
os.environ["CODEQL_EXTRACTOR_GO_EXTRACT_TESTS"] = "true"
codeql.database.create(source_root="src")
codeql.database.create(source_root="src", extractor_option = ["extract_tests=true"])