@@ -81,7 +81,14 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
81
81
}
82
82
}
83
83
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".
85
92
cfg := & packages.Config {
86
93
Mode : packages .NeedName | packages .NeedFiles |
87
94
packages .NeedCompiledGoFiles |
@@ -141,8 +148,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
141
148
// version seems to be a superset of it.
142
149
longestPackageIds := make (map [string ]string )
143
150
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 ) {
146
153
longestPackageIds [pkg .PkgPath ] = pkg .ID
147
154
}
148
155
} else {
@@ -154,7 +161,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool)
154
161
packages .Visit (pkgs , nil , func (pkg * packages.Package ) {
155
162
log .Printf ("Processing package %s." , pkg .PkgPath )
156
163
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.
158
165
if pkg .ID != longestPackageIds [pkg .PkgPath ] {
159
166
log .Printf ("Skipping variant of package %s with ID %s." , pkg .PkgPath , pkg .ID )
160
167
return
0 commit comments