@@ -187,6 +187,18 @@ func addVersionToMod(goMod []byte, version string) bool {
187
187
return run (cmd )
188
188
}
189
189
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
+
190
202
func main () {
191
203
if len (os .Args ) > 1 {
192
204
usage ()
@@ -379,6 +391,15 @@ func main() {
379
391
tryBuild ("build.sh" , "./build.sh" )
380
392
381
393
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
+
382
403
if modMode == ModVendor {
383
404
log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
384
405
} else {
@@ -459,26 +480,21 @@ func main() {
459
480
os .Chmod (script .Name (), 0700 )
460
481
install = exec .Command (script .Name ())
461
482
log .Println ("Installing dependencies using custom build command." )
462
- }
463
483
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 () {
476
488
modMode = modModIfSupported ()
477
489
log .Println ("The vendor directory is not consistent with the go.mod; not using vendored dependencies." )
478
490
}
479
491
}
480
492
}
481
493
494
+ if install != nil {
495
+ run (install )
496
+ }
497
+
482
498
// extract
483
499
mypath , err := os .Executable ()
484
500
if err != nil {
0 commit comments