@@ -187,6 +187,18 @@ func addVersionToMod(goMod []byte, version string) bool {
187187 return run (cmd )
188188}
189189
190+ // checkVendor tests to see whether a vendor directory is inconsistent according to the go frontend
191+ func checkVendor () bool {
192+ vendorCheckCmd := exec .Command ("go" , "list" , "-mod=vendor" , "./..." )
193+ outp , err := vendorCheckCmd .CombinedOutput ()
194+ if err != nil {
195+ badVendorRe := regexp .MustCompile (`(?m)^go: inconsistent vendoring in .*:$` )
196+ return ! badVendorRe .Match (outp )
197+ }
198+
199+ return true
200+ }
201+
190202func main () {
191203 if len (os .Args ) > 1 {
192204 usage ()
@@ -379,6 +391,15 @@ func main() {
379391 tryBuild ("build.sh" , "./build.sh" )
380392
381393 if ! buildSucceeded {
394+ if modMode == ModVendor {
395+ // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
396+ // or not set if the go version < 1.14.
397+ if ! checkVendor () {
398+ modMode = modModIfSupported ()
399+ log .Println ("The vendor directory is not consistent with the go.mod; not using vendored dependencies." )
400+ }
401+ }
402+
382403 if modMode == ModVendor {
383404 log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
384405 } else {
@@ -459,26 +480,21 @@ func main() {
459480 os .Chmod (script .Name (), 0700 )
460481 install = exec .Command (script .Name ())
461482 log .Println ("Installing dependencies using custom build command." )
462- }
463483
464- if install != nil {
465- run (install )
466- }
467-
468- if modMode == ModVendor {
469- // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
470- // or not set if the go version < 1.14.
471- vendorCheckCmd := exec .Command ("go" , "list" , "-mod=vendor" , "./..." )
472- outp , err := vendorCheckCmd .CombinedOutput ()
473- if err != nil {
474- badVendorRe := regexp .MustCompile (`(?m)^go: inconsistent vendoring in .*:$` )
475- if badVendorRe .Match (outp ) {
484+ if modMode == ModVendor {
485+ // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
486+ // or not set if the go version < 1.14.
487+ if ! checkVendor () {
476488 modMode = modModIfSupported ()
477489 log .Println ("The vendor directory is not consistent with the go.mod; not using vendored dependencies." )
478490 }
479491 }
480492 }
481493
494+ if install != nil {
495+ run (install )
496+ }
497+
482498 // extract
483499 mypath , err := os .Executable ()
484500 if err != nil {
0 commit comments