@@ -262,19 +262,23 @@ func checkDirsNested(dirs []string) bool {
262
262
return true
263
263
}
264
264
265
- func findGoModFiles (emitDiagnostics bool ) (string , bool ) {
265
+ // Returns the directory to run the go build in and whether a go.mod file was
266
+ // found.
267
+ func findGoModFiles (emitDiagnostics bool ) (baseDir string , goModFound bool ) {
266
268
goModPaths := util .FindAllFilesWithName ("." , "go.mod" , "vendor" )
267
269
if len (goModPaths ) == 0 {
268
- // preserve current behaviour
269
- return "." , false
270
+ baseDir = "."
271
+ goModFound = false
272
+ return
270
273
}
271
274
goModDirs := getDirs (goModPaths )
272
275
if util .AnyGoFilesOutsideDirs ("." , goModDirs ... ) {
273
276
if emitDiagnostics {
274
277
diagnostics .EmitGoFilesOutsideGoModules (goModPaths )
275
278
}
276
- // preserve current behaviour
277
- return "." , true
279
+ baseDir = "."
280
+ goModFound = true
281
+ return
278
282
}
279
283
if len (goModPaths ) > 1 {
280
284
// currently not supported
@@ -285,8 +289,9 @@ func findGoModFiles(emitDiagnostics bool) (string, bool) {
285
289
diagnostics .EmitMultipleGoModFoundNotNested (goModPaths )
286
290
}
287
291
}
288
- // preserve current behaviour
289
- return "." , true
292
+ baseDir = "."
293
+ goModFound = true
294
+ return
290
295
}
291
296
if emitDiagnostics {
292
297
if goModDirs [0 ] == "." {
@@ -295,15 +300,19 @@ func findGoModFiles(emitDiagnostics bool) (string, bool) {
295
300
diagnostics .EmitSingleNonRootGoModFound (goModPaths [0 ])
296
301
}
297
302
}
298
- return goModDirs [0 ], true
303
+ baseDir = goModDirs [0 ]
304
+ goModFound = true
305
+ return
299
306
}
300
307
301
308
// Returns the appropriate DependencyInstallerMode for the current project
302
309
func getDepMode (emitDiagnostics bool ) (DependencyInstallerMode , string ) {
303
- if util .FileExists ("BUILD" ) {
310
+ bazelPaths := util .FindAllFilesWithName ("." , "BUILD" , "vendor" )
311
+ bazelPaths = append (bazelPaths , util .FindAllFilesWithName ("." , "BUILD.bazel" , "vendor" )... )
312
+ if len (bazelPaths ) > 0 {
304
313
// currently not supported
305
314
if emitDiagnostics {
306
- diagnostics .EmitBazelBuildFileFound ( )
315
+ diagnostics .EmitBazelBuildFilesFound ( bazelPaths )
307
316
}
308
317
}
309
318
@@ -740,7 +749,7 @@ func installDependenciesAndBuild() {
740
749
741
750
goModVersion , goModVersionFound := tryReadGoDirective (depMode , baseDir )
742
751
743
- if semver .Compare ("v" + goModVersion , getEnvGoSemVer ()) >= 0 {
752
+ if goModVersionFound && semver .Compare ("v" + goModVersion , getEnvGoSemVer ()) >= 0 {
744
753
diagnostics .EmitNewerGoVersionNeeded ()
745
754
}
746
755
0 commit comments