@@ -224,11 +224,11 @@ func discoverWorkspaces(emitDiagnostics bool) []GoWorkspace {
224224
225225// Returns the directory to run the go build in and whether to use a go.mod
226226// file.
227- func getBuildRoot (emitDiagnostics bool ) (baseDirs []string , useGoMod bool ) {
228- goWorkspaces : = discoverWorkspaces (emitDiagnostics )
227+ func getBuildRoots (emitDiagnostics bool ) (goWorkspaces []GoWorkspace , totalModuleFiles int ) {
228+ goWorkspaces = discoverWorkspaces (emitDiagnostics )
229229
230230 // Determine the total number of `go.mod` files that we discovered.
231- totalModuleFiles : = 0
231+ totalModuleFiles = 0
232232
233233 for _ , goWorkspace := range goWorkspaces {
234234 totalModuleFiles += len (goWorkspace .Modules )
@@ -239,8 +239,12 @@ func getBuildRoot(emitDiagnostics bool) (baseDirs []string, useGoMod bool) {
239239 // If we have no `go.mod` files, then the project appears to be a legacy project without
240240 // a `go.mod` file. Try to initialize one automatically.
241241 initGoModForLegacyProject ("." )
242- baseDirs = []string {"." }
243- useGoMod = true
242+
243+ goWorkspaces = []GoWorkspace {{
244+ BaseDir : "." ,
245+ DepMode : GoGetWithModules ,
246+ }}
247+ totalModuleFiles = 1
244248 return
245249 }
246250
@@ -260,8 +264,12 @@ func getBuildRoot(emitDiagnostics bool) (baseDirs []string, useGoMod bool) {
260264 if emitDiagnostics {
261265 diagnostics .EmitGoFilesOutsideGoModules (goModPaths )
262266 }
263- baseDirs = []string {"." }
264- useGoMod = false
267+
268+ goWorkspaces = []GoWorkspace {{
269+ BaseDir : "." ,
270+ DepMode : GoGetNoModules ,
271+ }}
272+ totalModuleFiles = 0
265273 return
266274 }
267275
@@ -284,13 +292,11 @@ func getBuildRoot(emitDiagnostics bool) (baseDirs []string, useGoMod bool) {
284292 }
285293 }
286294
287- baseDirs = goModDirs
288- useGoMod = true
289295 return
290296}
291297
292298// Returns the appropriate DependencyInstallerMode for the current project
293- func getDepMode (emitDiagnostics bool ) ( DependencyInstallerMode , [] string ) {
299+ func getDepMode (emitDiagnostics bool ) [] GoWorkspace {
294300 bazelPaths := util .FindAllFilesWithName ("." , "BUILD" , "vendor" )
295301 bazelPaths = append (bazelPaths , util .FindAllFilesWithName ("." , "BUILD.bazel" , "vendor" )... )
296302 if len (bazelPaths ) > 0 {
@@ -300,28 +306,34 @@ func getDepMode(emitDiagnostics bool) (DependencyInstallerMode, []string) {
300306 }
301307 }
302308
303- baseDirs , useGoMod := getBuildRoot (emitDiagnostics )
304- if useGoMod {
305- log .Printf ("Found go.mod files in %s : enabling go modules.\n " , strings . Join ( baseDirs , ", " ) )
306- return GoGetWithModules , baseDirs
309+ goWorkspaces , totalModuleFiles := getBuildRoots (emitDiagnostics )
310+ if totalModuleFiles > 0 {
311+ log .Printf ("Found %d go.mod file(s) : enabling go modules.\n " , totalModuleFiles )
312+ return goWorkspaces
307313 }
308314
309315 if util .FileExists ("Gopkg.toml" ) {
310316 if emitDiagnostics {
311317 diagnostics .EmitGopkgTomlFound ()
312318 }
313319 log .Println ("Found Gopkg.toml, using dep instead of go get" )
314- return Dep , []string {"." }
320+ return []GoWorkspace {{
321+ BaseDir : "." ,
322+ DepMode : Dep ,
323+ }}
315324 }
316325
317326 if util .FileExists ("glide.yaml" ) {
318327 if emitDiagnostics {
319328 diagnostics .EmitGlideYamlFound ()
320329 }
321330 log .Println ("Found glide.yaml, using Glide instead of go get" )
322- return Glide , []string {"." }
331+ return []GoWorkspace {{
332+ BaseDir : "." ,
333+ DepMode : Glide ,
334+ }}
323335 }
324- return GoGetNoModules , [] string { "." }
336+ return goWorkspaces
325337}
326338
327339// ModMode corresponds to the possible values of the -mod flag for the Go compiler
@@ -378,12 +390,12 @@ type BuildInfo struct {
378390}
379391
380392func GetBuildInfo (emitDiagnostics bool ) []BuildInfo {
381- depMode , baseDirs := getDepMode (true )
382- results := make ([]BuildInfo , len (baseDirs ))
393+ goWorkspaces := getDepMode (true )
394+ results := make ([]BuildInfo , len (goWorkspaces ))
383395
384- for i , baseDir := range baseDirs {
385- modMode := getModMode (depMode , baseDir )
386- results [i ] = BuildInfo {depMode , modMode , baseDir }
396+ for i , workspace := range goWorkspaces {
397+ modMode := getModMode (workspace . DepMode , workspace . BaseDir )
398+ results [i ] = BuildInfo {workspace . DepMode , modMode , workspace . BaseDir }
387399 }
388400
389401 return results
0 commit comments