@@ -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.
@@ -562,17 +567,16 @@ func installDependenciesAndBuild() {
562567 tryUpdateGoModAndGoSum (workspace )
563568 }
564569
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+ }
577+
565578 // Attempt to extract all workspaces; we will tolerate individual extraction failures here
566579 for i , workspace := range workspaces {
567- // check whether an explicit dependency installation command was provided
568- inst := util .Getenv ("CODEQL_EXTRACTOR_GO_BUILD_COMMAND" , "LGTM_INDEX_BUILD_COMMAND" )
569- shouldInstallDependencies := false
570- if inst == "" {
571- shouldInstallDependencies = buildWithoutCustomCommands (workspace .ModMode )
572- } else {
573- buildWithCustomCommands (inst )
574- }
575-
576580 if workspace .ModMode == project .ModVendor {
577581 // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
578582 // or not set if the go version < 1.14. Note we check this post-build in case the build brings
@@ -583,7 +587,7 @@ func installDependenciesAndBuild() {
583587 }
584588 }
585589
586- if shouldInstallDependencies {
590+ if workspace . ShouldInstallDependencies {
587591 if workspace .ModMode == project .ModVendor {
588592 log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
589593 } else {
0 commit comments