Skip to content

Commit 3cf1d77

Browse files
committed
cmd/go: implement Go checksum database support
This CL adds support for consulting the Go checksum database when downloading a module that is not already listed in go.sum. The overall system is described at golang.org/design/25530-sumdb, and this CL implements the functionality described specifically in golang.org/design/25530-sumdb#command-client. Although the eventual plan is to set GOPROXY and GOSUMDB to default to a Google-run proxy serving the public Go ecosystem, this CL leaves them off by default. Fixes #30601. Change-Id: Ie46140f93c6cc2d85573fbce0878a258819ff44d Reviewed-on: https://go-review.googlesource.com/c/go/+/173951 Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 203b80a commit 3cf1d77

29 files changed

+772
-3881
lines changed

src/cmd/go/alldocs.go

Lines changed: 31 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/cfg/cfg.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,14 @@ var knownEnv = `
265265
GOHOSTOS
266266
GOMIPS
267267
GOMIPS64
268-
GONOVERIFY
268+
GONOPROXY
269+
GONOSUMDB
269270
GOOS
270271
GOPATH
271272
GOPPC64
272273
GOPROXY
273274
GOROOT
275+
GOSUMDB
274276
GOTMPDIR
275277
GOTOOLDIR
276278
GOWASM
@@ -293,8 +295,45 @@ var (
293295
GOMIPS64 = envOr("GOMIPS64", objabi.GOMIPS64)
294296
GOPPC64 = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", objabi.GOPPC64))
295297
GOWASM = envOr("GOWASM", fmt.Sprint(objabi.GOWASM))
298+
299+
GOPROXY = goproxy()
300+
GOSUMDB = gosumdb()
301+
GONOPROXY = Getenv("GONOPROXY")
302+
GONOSUMDB = Getenv("GONOSUMDB")
296303
)
297304

305+
func goproxy() string {
306+
v := Getenv("GOPROXY")
307+
if v != "" {
308+
return v
309+
}
310+
311+
// Proxy is off by default for now.
312+
// TODO(rsc): Remove this condition, turning it on always.
313+
// (But do NOT do this without approval from rsc.)
314+
if true {
315+
return "direct"
316+
}
317+
318+
return "https://proxy.golang.org"
319+
}
320+
321+
func gosumdb() string {
322+
v := Getenv("GOSUMDB")
323+
if v != "" {
324+
return v
325+
}
326+
327+
// Checksum database is off by default except when GOPROXY is proxy.golang.org.
328+
// TODO(rsc): Remove this condition, turning it on always.
329+
// (But do NOT do this without approval from rsc.)
330+
if !strings.HasPrefix(GOPROXY, "https://proxy.golang.org") {
331+
return "off"
332+
}
333+
334+
return "sum.golang.org"
335+
}
336+
298337
// GetArchEnv returns the name and setting of the
299338
// GOARCH-specific architecture environment variable.
300339
// If the current architecture has no GOARCH-specific variable,

src/cmd/go/internal/envcmd/env.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ package envcmd
88
import (
99
"encoding/json"
1010
"fmt"
11+
"io/ioutil"
1112
"os"
1213
"path/filepath"
13-
"unicode/utf8"
14-
"io/ioutil"
15-
"sort"
1614
"runtime"
15+
"sort"
1716
"strings"
17+
"unicode/utf8"
1818

1919
"cmd/go/internal/base"
2020
"cmd/go/internal/cache"
@@ -56,7 +56,7 @@ func init() {
5656

5757
var (
5858
envJson = CmdEnv.Flag.Bool("json", false, "")
59-
envU = CmdEnv.Flag.Bool("u", false, "")
59+
envU = CmdEnv.Flag.Bool("u", false, "")
6060
envW = CmdEnv.Flag.Bool("w", false, "")
6161
)
6262

@@ -74,10 +74,13 @@ func MkEnv() []cfg.EnvVar {
7474
{Name: "GOFLAGS", Value: cfg.Getenv("GOFLAGS")},
7575
{Name: "GOHOSTARCH", Value: runtime.GOARCH},
7676
{Name: "GOHOSTOS", Value: runtime.GOOS},
77+
{Name: "GONOPROXY", Value: cfg.GONOPROXY},
78+
{Name: "GONOSUMDB", Value: cfg.GONOSUMDB},
7779
{Name: "GOOS", Value: cfg.Goos},
7880
{Name: "GOPATH", Value: cfg.BuildContext.GOPATH},
79-
{Name: "GOPROXY", Value: cfg.Getenv("GOPROXY")},
81+
{Name: "GOPROXY", Value: cfg.GOPROXY},
8082
{Name: "GOROOT", Value: cfg.GOROOT},
83+
{Name: "GOSUMDB", Value: cfg.GOSUMDB},
8184
{Name: "GOTMPDIR", Value: cfg.Getenv("GOTMPDIR")},
8285
{Name: "GOTOOLDIR", Value: base.ToolDir},
8386
}
@@ -387,7 +390,7 @@ func updateEnvFile(add map[string]string, del map[string]bool) {
387390
}
388391
}
389392
for key, val := range add {
390-
lines = append(lines, key + "=" + val + "\n")
393+
lines = append(lines, key+"="+val+"\n")
391394
}
392395

393396
// Delete requested variables (go env -u).
@@ -404,7 +407,7 @@ func updateEnvFile(add map[string]string, del map[string]bool) {
404407
for i := 0; i <= len(lines); i++ {
405408
if i == len(lines) || lineToKey(lines[i]) == "" {
406409
sortKeyValues(lines[start:i])
407-
start = i+1
410+
start = i + 1
408411
}
409412
}
410413

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build cmd_go_bootstrap
6+
7+
package modfetch
8+
9+
import "cmd/go/internal/module"
10+
11+
func useSumDB(mod module.Version) bool {
12+
return false
13+
}
14+
15+
func lookupSumDB(mod module.Version) (string, []string, error) {
16+
panic("bootstrap")
17+
}

0 commit comments

Comments
 (0)