@@ -168,7 +168,7 @@ func tryUpdateGoModAndGoSum(workspace project.GoWorkspace) {
168
168
beforeGoSumFileInfo , beforeGoSumErr := os .Stat (goSumPath )
169
169
170
170
// run `go mod tidy -e`
171
- cmd := toolchain . TidyModule ( goModDir )
171
+ cmd := goMod . Tidy ( )
172
172
res := util .RunCmd (cmd )
173
173
174
174
if ! res {
@@ -320,8 +320,7 @@ func setGopath(root string) {
320
320
321
321
// Try to build the project with a build script. If that fails, return a boolean indicating
322
322
// that we should install dependencies in the normal way.
323
- func buildWithoutCustomCommands (modMode project.ModMode ) bool {
324
- shouldInstallDependencies := false
323
+ func buildWithoutCustomCommands (workspaces []project.GoWorkspace ) {
325
324
// try to run a build script
326
325
scriptSucceeded , scriptsExecuted := autobuilder .Autobuild ()
327
326
scriptCount := len (scriptsExecuted )
@@ -335,13 +334,19 @@ func buildWithoutCustomCommands(modMode project.ModMode) bool {
335
334
log .Println ("Unable to find any build scripts, continuing to install dependencies in the normal way." )
336
335
}
337
336
338
- shouldInstallDependencies = true
339
- } else if toolchain .DepErrors ("./..." , modMode .ArgsForGoVersion (toolchain .GetEnvGoSemVer ())... ) {
340
- log .Printf ("Dependencies are still not resolving after executing %d build script(s), continuing to install dependencies in the normal way.\n " , scriptCount )
337
+ // Install dependencies for all workspaces.
338
+ for i , _ := range workspaces {
339
+ workspaces [i ].ShouldInstallDependencies = true
340
+ }
341
+ } else {
342
+ for i , workspace := range workspaces {
343
+ if toolchain .DepErrors ("./..." , workspace .ModMode .ArgsForGoVersion (toolchain .GetEnvGoSemVer ())... ) {
344
+ log .Printf ("Dependencies are still not resolving for `%s` after executing %d build script(s), continuing to install dependencies in the normal way.\n " , workspace .BaseDir , scriptCount )
341
345
342
- shouldInstallDependencies = true
346
+ workspaces [i ].ShouldInstallDependencies = true
347
+ }
348
+ }
343
349
}
344
- return shouldInstallDependencies
345
350
}
346
351
347
352
// Build the project with custom commands.
@@ -428,7 +433,7 @@ func installDependencies(workspace project.GoWorkspace) {
428
433
path := filepath .Dir (module .Path )
429
434
430
435
if util .DirExists (filepath .Join (path , "vendor" )) {
431
- vendor := toolchain . VendorModule ( path )
436
+ vendor := module . Vendor ( )
432
437
log .Printf ("Synchronizing vendor file using `go mod vendor` in %s.\n " , path )
433
438
util .RunCmd (vendor )
434
439
}
@@ -553,23 +558,25 @@ func installDependenciesAndBuild() {
553
558
// Track all projects which could not be extracted successfully
554
559
var unsuccessfulProjects = []string {}
555
560
556
- // Attempt to extract all workspaces; we will tolerate individual extraction failures here
557
- for i , workspace := range workspaces {
561
+ // Attempt to automatically fix issues with each workspace
562
+ for _ , workspace := range workspaces {
558
563
goVersionInfo := workspace .RequiredGoVersion ()
559
564
560
565
fixGoVendorIssues (& workspace , goVersionInfo != nil )
561
566
562
567
tryUpdateGoModAndGoSum (workspace )
568
+ }
563
569
564
- // check whether an explicit dependency installation command was provided
565
- inst := util .Getenv ("CODEQL_EXTRACTOR_GO_BUILD_COMMAND" , "LGTM_INDEX_BUILD_COMMAND" )
566
- shouldInstallDependencies := false
567
- if inst == "" {
568
- shouldInstallDependencies = buildWithoutCustomCommands (workspace .ModMode )
569
- } else {
570
- buildWithCustomCommands (inst )
571
- }
570
+ // check whether an explicit dependency installation command was provided
571
+ inst := util .Getenv ("CODEQL_EXTRACTOR_GO_BUILD_COMMAND" , "LGTM_INDEX_BUILD_COMMAND" )
572
+ if inst == "" {
573
+ buildWithoutCustomCommands (workspaces )
574
+ } else {
575
+ buildWithCustomCommands (inst )
576
+ }
572
577
578
+ // Attempt to extract all workspaces; we will tolerate individual extraction failures here
579
+ for i , workspace := range workspaces {
573
580
if workspace .ModMode == project .ModVendor {
574
581
// test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
575
582
// or not set if the go version < 1.14. Note we check this post-build in case the build brings
@@ -580,7 +587,7 @@ func installDependenciesAndBuild() {
580
587
}
581
588
}
582
589
583
- if shouldInstallDependencies {
590
+ if workspace . ShouldInstallDependencies {
584
591
if workspace .ModMode == project .ModVendor {
585
592
log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
586
593
} else {
0 commit comments