@@ -262,19 +262,23 @@ func checkDirsNested(dirs []string) bool {
262262 return true
263263}
264264
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 ) {
266268 goModPaths := util .FindAllFilesWithName ("." , "go.mod" , "vendor" )
267269 if len (goModPaths ) == 0 {
268- // preserve current behaviour
269- return "." , false
270+ baseDir = "."
271+ goModFound = false
272+ return
270273 }
271274 goModDirs := getDirs (goModPaths )
272275 if util .AnyGoFilesOutsideDirs ("." , goModDirs ... ) {
273276 if emitDiagnostics {
274277 diagnostics .EmitGoFilesOutsideGoModules (goModPaths )
275278 }
276- // preserve current behaviour
277- return "." , true
279+ baseDir = "."
280+ goModFound = true
281+ return
278282 }
279283 if len (goModPaths ) > 1 {
280284 // currently not supported
@@ -285,8 +289,9 @@ func findGoModFiles(emitDiagnostics bool) (string, bool) {
285289 diagnostics .EmitMultipleGoModFoundNotNested (goModPaths )
286290 }
287291 }
288- // preserve current behaviour
289- return "." , true
292+ baseDir = "."
293+ goModFound = true
294+ return
290295 }
291296 if emitDiagnostics {
292297 if goModDirs [0 ] == "." {
@@ -295,15 +300,19 @@ func findGoModFiles(emitDiagnostics bool) (string, bool) {
295300 diagnostics .EmitSingleNonRootGoModFound (goModPaths [0 ])
296301 }
297302 }
298- return goModDirs [0 ], true
303+ baseDir = goModDirs [0 ]
304+ goModFound = true
305+ return
299306}
300307
301308// Returns the appropriate DependencyInstallerMode for the current project
302309func 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 {
304313 // currently not supported
305314 if emitDiagnostics {
306- diagnostics .EmitBazelBuildFileFound ( )
315+ diagnostics .EmitBazelBuildFilesFound ( bazelPaths )
307316 }
308317 }
309318
@@ -740,7 +749,7 @@ func installDependenciesAndBuild() {
740749
741750 goModVersion , goModVersionFound := tryReadGoDirective (depMode , baseDir )
742751
743- if semver .Compare ("v" + goModVersion , getEnvGoSemVer ()) >= 0 {
752+ if goModVersionFound && semver .Compare ("v" + goModVersion , getEnvGoSemVer ()) >= 0 {
744753 diagnostics .EmitNewerGoVersionNeeded ()
745754 }
746755
0 commit comments