@@ -279,6 +279,28 @@ func fixGoVendorIssues(modMode ModMode, depMode DependencyInstallerMode, goDirec
279
279
return modMode
280
280
}
281
281
282
+ func getNeedGopath (depMode DependencyInstallerMode , importpath string ) bool {
283
+ needGopath := true
284
+ if depMode == GoGetWithModules {
285
+ needGopath = false
286
+ }
287
+ // if `LGTM_INDEX_NEED_GOPATH` is set, it overrides the value for `needGopath` inferred above
288
+ if needGopathOverride := os .Getenv ("LGTM_INDEX_NEED_GOPATH" ); needGopathOverride != "" {
289
+ if needGopathOverride == "true" {
290
+ needGopath = true
291
+ } else if needGopathOverride == "false" {
292
+ needGopath = false
293
+ } else {
294
+ log .Fatalf ("Unexpected value for Boolean environment variable LGTM_NEED_GOPATH: %v.\n " , needGopathOverride )
295
+ }
296
+ }
297
+ if needGopath && importpath == "" {
298
+ log .Printf ("Failed to determine import path, not setting up GOPATH" )
299
+ needGopath = false
300
+ }
301
+ return needGopath
302
+ }
303
+
282
304
func main () {
283
305
if len (os .Args ) > 1 {
284
306
usage ()
@@ -306,13 +328,11 @@ func main() {
306
328
// determine how to install dependencies and whether a GOPATH needs to be set up before
307
329
// extraction
308
330
depMode := getDepMode ()
309
- needGopath := true
310
331
goDirectiveFound := false
311
332
if _ , present := os .LookupEnv ("GO111MODULE" ); ! present {
312
333
os .Setenv ("GO111MODULE" , "auto" )
313
334
}
314
335
if depMode == GoGetWithModules {
315
- needGopath = false
316
336
versionRe := regexp .MustCompile (`(?m)^go[ \t\r]+([0-9]+\.[0-9]+)$` )
317
337
goMod , err := ioutil .ReadFile ("go.mod" )
318
338
if err != nil {
@@ -372,22 +392,11 @@ func main() {
372
392
}
373
393
}
374
394
375
- // if `LGTM_INDEX_NEED_GOPATH` is set, it overrides the value for `needGopath` inferred above
376
- if needGopathOverride := os .Getenv ("LGTM_INDEX_NEED_GOPATH" ); needGopathOverride != "" {
377
- inLGTM = true
378
- if needGopathOverride == "true" {
379
- needGopath = true
380
- } else if needGopathOverride == "false" {
381
- needGopath = false
382
- } else {
383
- log .Fatalf ("Unexpected value for Boolean environment variable LGTM_NEED_GOPATH: %v.\n " , needGopathOverride )
384
- }
385
- }
386
-
387
395
importpath := getImportPath ()
388
- if needGopath && importpath == "" {
389
- log .Printf ("Failed to determine import path, not setting up GOPATH" )
390
- needGopath = false
396
+ needGopath := getNeedGopath (depMode , importpath )
397
+
398
+ if os .Getenv ("LGTM_INDEX_NEED_GOPATH" ) != "" {
399
+ inLGTM = true
391
400
}
392
401
393
402
if inLGTM && needGopath {
0 commit comments