@@ -545,6 +545,31 @@ func installDependenciesAndBuild() {
545
545
// Remove temporary extractor files (e.g. auto-generated go.mod files) when we are done
546
546
defer project .RemoveTemporaryExtractorFiles ()
547
547
548
+ // If there is only one workspace and it needs a GOPATH set up, which may be the case if
549
+ // we don't use Go modules, then we move the repository to a temporary directory and set
550
+ // the GOPATH to it.
551
+ if len (workspaces ) == 1 {
552
+ workspace := workspaces [0 ]
553
+
554
+ importpath := getImportPath ()
555
+ needGopath := getNeedGopath (workspace , importpath )
556
+
557
+ inLGTM := os .Getenv ("LGTM_SRC" ) != "" || os .Getenv ("LGTM_INDEX_NEED_GOPATH" ) != ""
558
+
559
+ if inLGTM && needGopath {
560
+ paths := moveToTemporaryGopath (srcdir , importpath )
561
+
562
+ // schedule restoring the contents of newdir to their original location after this function completes:
563
+ defer restoreRepoLayout (paths .newdir , paths .files , filepath .Base (paths .scratch ), srcdir )
564
+
565
+ pt := createPathTransformerFile (paths .newdir )
566
+ defer os .Remove (pt .Name ())
567
+
568
+ writePathTransformerFile (pt , paths .realSrc , paths .root , paths .newdir )
569
+ setGopath (paths .root )
570
+ }
571
+ }
572
+
548
573
// Attempt to extract all workspaces; we will tolerate individual extraction failures here
549
574
for i , workspace := range workspaces {
550
575
goVersionInfo := workspace .RequiredGoVersion ()
@@ -565,24 +590,6 @@ func installDependenciesAndBuild() {
565
590
566
591
tryUpdateGoModAndGoSum (workspace )
567
592
568
- importpath := getImportPath ()
569
- needGopath := getNeedGopath (workspace , importpath )
570
-
571
- inLGTM := os .Getenv ("LGTM_SRC" ) != "" || os .Getenv ("LGTM_INDEX_NEED_GOPATH" ) != ""
572
-
573
- if inLGTM && needGopath {
574
- paths := moveToTemporaryGopath (srcdir , importpath )
575
-
576
- // schedule restoring the contents of newdir to their original location after this function completes:
577
- defer restoreRepoLayout (paths .newdir , paths .files , filepath .Base (paths .scratch ), srcdir )
578
-
579
- pt := createPathTransformerFile (paths .newdir )
580
- defer os .Remove (pt .Name ())
581
-
582
- writePathTransformerFile (pt , paths .realSrc , paths .root , paths .newdir )
583
- setGopath (paths .root )
584
- }
585
-
586
593
// check whether an explicit dependency installation command was provided
587
594
inst := util .Getenv ("CODEQL_EXTRACTOR_GO_BUILD_COMMAND" , "LGTM_INDEX_BUILD_COMMAND" )
588
595
shouldInstallDependencies := false
0 commit comments