Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perillo/59f3be87dd2b64d7d734c74d1f344cd5 to your computer and use it in GitHub Desktop.
Save perillo/59f3be87dd2b64d7d734c74d1f344cd5 to your computer and use it in GitHub Desktop.
Go trust module build mode
From ad7ce9d1923cc8afefeecf9a6166d447b080e271 Mon Sep 17 00:00:00 2001
From: Manlio Perillo <manlio.perillo@gmail.com>
Date: Mon, 11 Mar 2019 17:33:41 +0100
Subject: [PATCH] cmd/go: add trust module build mode
Add the trust module build mode for interoperability with operating
systems package managers.
---
src/cmd/go/internal/modfetch/fetch.go | 4 ++++
src/cmd/go/internal/work/build.go | 2 +-
src/cmd/go/internal/work/init.go | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go
index 1d6969ea3e..6dd437f92c 100644
--- a/src/cmd/go/internal/modfetch/fetch.go
+++ b/src/cmd/go/internal/modfetch/fetch.go
@@ -386,6 +386,10 @@ func goModSum(data []byte) (string, error) {
// checkGoMod checks the given module's go.mod checksum;
// data is the go.mod content.
func checkGoMod(path, version string, data []byte) {
+ if cfg.BuildMod == "trust" {
+ // Trust me!
+ return
+ }
h, err := goModSum(data)
if err != nil {
base.Fatalf("verifying %s %s go.mod: %v", path, version, err)
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 145b87513a..ab8d31832c 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -99,7 +99,7 @@ and test commands:
link against shared libraries previously created with
-buildmode=shared.
-mod mode
- module download mode to use: readonly or vendor.
+ module download mode to use: readonly, trust or vendor.
See 'go help modules' for more.
-pkgdir dir
install and load all packages from dir instead of the usual locations.
diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go
index 3381ab544c..ef7c15a9c2 100644
--- a/src/cmd/go/internal/work/init.go
+++ b/src/cmd/go/internal/work/init.go
@@ -240,7 +240,7 @@ func buildModeInit() {
switch cfg.BuildMod {
case "":
// ok
- case "readonly", "vendor":
+ case "readonly", "trust", "vendor":
if load.ModLookup == nil && !inGOFLAGS("-mod") {
base.Fatalf("build flag -mod=%s only valid when using modules", cfg.BuildMod)
}
--
2.21.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment