@@ -168,7 +168,7 @@ func tryUpdateGoModAndGoSum(workspace project.GoWorkspace) {
168168 beforeGoSumFileInfo , beforeGoSumErr := os .Stat (goSumPath )
169169
170170 // run `go mod tidy -e`
171- cmd := toolchain . TidyModule ( goModDir )
171+ cmd := goMod . Tidy ( )
172172 res := util .RunCmd (cmd )
173173
174174 if ! res {
@@ -320,8 +320,7 @@ func setGopath(root string) {
320320
321321// Try to build the project with a build script. If that fails, return a boolean indicating
322322// 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 ) {
325324 // try to run a build script
326325 scriptSucceeded , scriptsExecuted := autobuilder .Autobuild ()
327326 scriptCount := len (scriptsExecuted )
@@ -335,13 +334,19 @@ func buildWithoutCustomCommands(modMode project.ModMode) bool {
335334 log .Println ("Unable to find any build scripts, continuing to install dependencies in the normal way." )
336335 }
337336
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 )
341345
342- shouldInstallDependencies = true
346+ workspaces [i ].ShouldInstallDependencies = true
347+ }
348+ }
343349 }
344- return shouldInstallDependencies
345350}
346351
347352// Build the project with custom commands.
@@ -428,7 +433,7 @@ func installDependencies(workspace project.GoWorkspace) {
428433 path := filepath .Dir (module .Path )
429434
430435 if util .DirExists (filepath .Join (path , "vendor" )) {
431- vendor := toolchain . VendorModule ( path )
436+ vendor := module . Vendor ( )
432437 log .Printf ("Synchronizing vendor file using `go mod vendor` in %s.\n " , path )
433438 util .RunCmd (vendor )
434439 }
@@ -553,23 +558,25 @@ func installDependenciesAndBuild() {
553558 // Track all projects which could not be extracted successfully
554559 var unsuccessfulProjects = []string {}
555560
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 {
558563 goVersionInfo := workspace .RequiredGoVersion ()
559564
560565 fixGoVendorIssues (& workspace , goVersionInfo != nil )
561566
562567 tryUpdateGoModAndGoSum (workspace )
568+ }
563569
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+ }
572577
578+ // Attempt to extract all workspaces; we will tolerate individual extraction failures here
579+ for i , workspace := range workspaces {
573580 if workspace .ModMode == project .ModVendor {
574581 // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
575582 // 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() {
580587 }
581588 }
582589
583- if shouldInstallDependencies {
590+ if workspace . ShouldInstallDependencies {
584591 if workspace .ModMode == project .ModVendor {
585592 log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
586593 } else {
0 commit comments