go: Introduce environment variable GO_NO_VENDOR_CHECKS to relax go vendor checks

This is used in https://github.com/tweag/gomod2nix to reconstruct a
vendor metadata file.

With the vendor checks we need a lot more metadata which isn't
relevant for building packages, especially since we've already locked
the dependency graph ahead of time

This has been ported from FreeBSD: https://reviews.freebsd.org/D24122
This commit is contained in:
adisbladis 2021-01-12 18:04:59 +01:00
parent 39fbff44a8
commit 7be71af02a
No known key found for this signature in database
GPG key ID: 110BFAD44C6249B7
4 changed files with 48 additions and 0 deletions

View file

@ -143,6 +143,7 @@ stdenv.mkDerivation rec {
./go-1.9-skip-flaky-20072.patch
./skip-external-network-tests.patch
./skip-nohup-tests.patch
./go_no_vendor_checks-1_14.patch
# fix rare TestDontCacheBrokenHTTP2Conn failure
(fetchpatch {

View file

@ -152,6 +152,7 @@ stdenv.mkDerivation rec {
./skip-external-network-tests-1.15.patch
./skip-nohup-tests.patch
./skip-cgo-tests-1.15.patch
./go_no_vendor_checks.patch
] ++ [
# breaks under load: https://github.com/golang/go/issues/25628
(if stdenv.isAarch32

View file

@ -0,0 +1,23 @@
Starting from go1.14, go verifes that vendor/modules.txt matches the requirements
and replacements listed in the main module go.mod file, and it is a hard failure if
vendor/modules.txt is missing.
Relax module consistency checks and switch back to pre go1.14 behaviour if
vendor/modules.txt is missing regardless of go version requirement in go.mod.
This has been ported from FreeBSD: https://reviews.freebsd.org/D24122
See https://github.com/golang/go/issues/37948 for discussion.
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 71f68efbcc..3c566d04dd 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -133,7 +133,7 @@ func checkVendorConsistency() {
readVendorList()
pre114 := false
- if modFile.Go == nil || semver.Compare("v"+modFile.Go.Version, "v1.14") < 0 {
+ if modFile.Go == nil || semver.Compare("v"+modFile.Go.Version, "v1.14") < 0 || (os.Getenv("GO_NO_VENDOR_CHECKS") == "1" && len(vendorMeta) == 0) {
// Go versions before 1.14 did not include enough information in
// vendor/modules.txt to check for consistency.
// If we know that we're on an earlier version, relax the consistency check.

View file

@ -0,0 +1,23 @@
Starting from go1.14, go verifes that vendor/modules.txt matches the requirements
and replacements listed in the main module go.mod file, and it is a hard failure if
vendor/modules.txt is missing.
Relax module consistency checks and switch back to pre go1.14 behaviour if
vendor/modules.txt is missing regardless of go version requirement in go.mod.
This has been ported from FreeBSD: https://reviews.freebsd.org/D24122
See https://github.com/golang/go/issues/37948 for discussion.
diff --git a/src/cmd/go/internal/modload/vendor.go b/src/cmd/go/internal/modload/vendor.go
index 71f68efbcc..3c566d04dd 100644
--- a/src/cmd/go/internal/modload/vendor.go
+++ b/src/cmd/go/internal/modload/vendor.go
@@ -133,7 +133,7 @@ func checkVendorConsistency() {
readVendorList()
pre114 := false
- if modFile.Go == nil || semver.Compare("v"+modFile.Go.Version, "v1.14") < 0 {
+ if modFile.Go == nil || semver.Compare("v"+modFile.Go.Version, "v1.14") < 0 || (os.Getenv("GO_NO_VENDOR_CHECKS") == "1" && len(vendorMeta) == 0) {
// Go versions before 1.14 did not include enough information in
// vendor/modules.txt to check for consistency.
// If we know that we're on an earlier version, relax the consistency check.