@@ -81,7 +81,14 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
8181 }
8282 }
8383
84- log .Println ("Running packages.Load." )
84+ testMessage := ""
85+ if extractTests {
86+ testMessage = " (test extraction enabled)"
87+ }
88+ log .Printf ("Running packages.Load%s." , testMessage )
89+
90+ // This includes test packages if either we're tracing a `go test` command,
91+ // or if CODEQL_EXTRACTOR_GO_EXTRACT_TESTS is set to "true".
8592 cfg := & packages.Config {
8693 Mode : packages .NeedName | packages .NeedFiles |
8794 packages .NeedCompiledGoFiles |
@@ -141,8 +148,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
141148 // version seems to be a superset of it.
142149 longestPackageIds := make (map [string ]string )
143150 packages .Visit (pkgs , nil , func (pkg * packages.Package ) {
144- if shortestID , present := longestPackageIds [pkg .PkgPath ]; present {
145- if len (pkg .ID ) > len (shortestID ) {
151+ if longestIDSoFar , present := longestPackageIds [pkg .PkgPath ]; present {
152+ if len (pkg .ID ) > len (longestIDSoFar ) {
146153 longestPackageIds [pkg .PkgPath ] = pkg .ID
147154 }
148155 } else {
@@ -154,7 +161,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
154161 packages .Visit (pkgs , nil , func (pkg * packages.Package ) {
155162 log .Printf ("Processing package %s." , pkg .PkgPath )
156163
157- // If this is a variant of a package that also occurs with a longer ID, skip it.
164+ // If this is a variant of a package that also occurs with a shorter ID, skip it.
158165 if pkg .ID != longestPackageIds [pkg .PkgPath ] {
159166 log .Printf ("Skipping variant of package %s with ID %s." , pkg .PkgPath , pkg .ID )
160167 return
0 commit comments