summaryrefslogtreecommitdiffstats
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-01-27 17:55:50 -0800
committerIan Lance Taylor <iant@golang.org>2021-01-29 11:04:55 -0800
commit726b7aa004d6885388a76521222602b8552a41ee (patch)
tree5179037ef840a43dcea0f3be4e07dbcbcfcb2c4a /libgo
parent[PATCH, rs6000] improve vec_ctf invalid parameter handling. (diff)
downloadgcc-726b7aa004d6885388a76521222602b8552a41ee.tar.gz
gcc-726b7aa004d6885388a76521222602b8552a41ee.tar.bz2
gcc-726b7aa004d6885388a76521222602b8552a41ee.tar.xz
libgo: update to Go1.16rc1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/287493
Diffstat (limited to 'libgo')
-rw-r--r--libgo/MERGE2
-rw-r--r--libgo/Makefile.am2
-rw-r--r--libgo/Makefile.in2
-rw-r--r--libgo/VERSION2
-rw-r--r--libgo/check-packages.txt2
-rw-r--r--libgo/go/archive/tar/strconv.go2
-rw-r--r--libgo/go/cmd/cgo/gcc.go7
-rw-r--r--libgo/go/cmd/cgo/out.go6
-rw-r--r--libgo/go/cmd/cgo/util.go6
-rw-r--r--libgo/go/cmd/go.mod4
-rw-r--r--libgo/go/cmd/go/alldocs.go863
-rw-r--r--libgo/go/cmd/go/go_test.go5
-rw-r--r--libgo/go/cmd/go/internal/base/base.go2
-rw-r--r--libgo/go/cmd/go/internal/bug/bug.go2
-rw-r--r--libgo/go/cmd/go/internal/fmtcmd/fmt.go3
-rw-r--r--libgo/go/cmd/go/internal/generate/generate.go20
-rw-r--r--libgo/go/cmd/go/internal/get/get.go2
-rw-r--r--libgo/go/cmd/go/internal/help/helpdoc.go19
-rw-r--r--libgo/go/cmd/go/internal/list/list.go12
-rw-r--r--libgo/go/cmd/go/internal/load/pkg.go134
-rw-r--r--libgo/go/cmd/go/internal/load/test.go8
-rw-r--r--libgo/go/cmd/go/internal/modcmd/download.go4
-rw-r--r--libgo/go/cmd/go/internal/modcmd/edit.go5
-rw-r--r--libgo/go/cmd/go/internal/modcmd/graph.go2
-rw-r--r--libgo/go/cmd/go/internal/modcmd/init.go2
-rw-r--r--libgo/go/cmd/go/internal/modcmd/tidy.go2
-rw-r--r--libgo/go/cmd/go/internal/modcmd/vendor.go78
-rw-r--r--libgo/go/cmd/go/internal/modcmd/verify.go2
-rw-r--r--libgo/go/cmd/go/internal/modcmd/why.go2
-rw-r--r--libgo/go/cmd/go/internal/modfetch/codehost/codehost.go2
-rw-r--r--libgo/go/cmd/go/internal/modfetch/codehost/git.go2
-rw-r--r--libgo/go/cmd/go/internal/modfetch/fetch.go108
-rw-r--r--libgo/go/cmd/go/internal/modfetch/proxy.go61
-rw-r--r--libgo/go/cmd/go/internal/modget/get.go127
-rw-r--r--libgo/go/cmd/go/internal/modget/query.go4
-rw-r--r--libgo/go/cmd/go/internal/modload/buildlist.go11
-rw-r--r--libgo/go/cmd/go/internal/modload/help.go484
-rw-r--r--libgo/go/cmd/go/internal/modload/import.go82
-rw-r--r--libgo/go/cmd/go/internal/modload/import_test.go13
-rw-r--r--libgo/go/cmd/go/internal/modload/init.go81
-rw-r--r--libgo/go/cmd/go/internal/modload/load.go21
-rw-r--r--libgo/go/cmd/go/internal/modload/modfile.go4
-rw-r--r--libgo/go/cmd/go/internal/modload/mvs.go16
-rw-r--r--libgo/go/cmd/go/internal/modload/query.go10
-rw-r--r--libgo/go/cmd/go/internal/modload/vendor.go2
-rw-r--r--libgo/go/cmd/go/internal/str/str.go14
-rw-r--r--libgo/go/cmd/go/internal/test/genflags.go2
-rw-r--r--libgo/go/cmd/go/internal/test/test.go2
-rw-r--r--libgo/go/cmd/go/internal/test/testflag.go2
-rw-r--r--libgo/go/cmd/go/internal/tool/tool.go17
-rw-r--r--libgo/go/cmd/go/internal/vcs/vcs.go4
-rw-r--r--libgo/go/cmd/go/internal/vet/vetflag.go2
-rw-r--r--libgo/go/cmd/go/internal/work/build.go7
-rw-r--r--libgo/go/cmd/go/internal/work/buildid.go2
-rw-r--r--libgo/go/cmd/go/internal/work/exec.go17
-rw-r--r--libgo/go/cmd/go/internal/work/gccgo.go8
-rw-r--r--libgo/go/cmd/go/testdata/addmod.go2
-rw-r--r--libgo/go/cmd/go/testdata/script/link_syso_issue33139.txt2
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_bad_domain.txt2
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_edit.txt6
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_get_fallback.txt2
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_gobuild_import.txt2
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_list_bad_import.txt2
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_readonly.txt10
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_vendor_auto.txt6
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_versions.txt6
-rw-r--r--libgo/go/cmd/internal/browser/browser.go2
-rw-r--r--libgo/go/cmd/test2json/main.go8
-rw-r--r--libgo/go/cmd/vendor/modules.txt4
-rw-r--r--libgo/go/crypto/elliptic/p224.go41
-rw-r--r--libgo/go/crypto/elliptic/p224_test.go277
-rw-r--r--libgo/go/crypto/rand/rand_windows.go4
-rw-r--r--libgo/go/crypto/tls/common.go21
-rw-r--r--libgo/go/crypto/tls/conn.go62
-rw-r--r--libgo/go/crypto/tls/handshake_client.go11
-rw-r--r--libgo/go/crypto/tls/handshake_client_test.go36
-rw-r--r--libgo/go/crypto/tls/handshake_client_tls13.go3
-rw-r--r--libgo/go/crypto/tls/handshake_server.go17
-rw-r--r--libgo/go/crypto/tls/handshake_server_test.go50
-rw-r--r--libgo/go/crypto/tls/handshake_server_tls13.go4
-rw-r--r--libgo/go/crypto/tls/tls.go55
-rw-r--r--libgo/go/crypto/x509/root.go6
-rw-r--r--libgo/go/crypto/x509/root_ios.go280
-rw-r--r--libgo/go/crypto/x509/x509.go108
-rw-r--r--libgo/go/crypto/x509/x509_test.go54
-rw-r--r--libgo/go/embed/embed.go6
-rw-r--r--libgo/go/embed/internal/embedtest/embed_test.go49
-rw-r--r--libgo/go/embed/internal/embedtest/embedx_test.go14
-rw-r--r--libgo/go/encoding/asn1/asn1.go9
-rw-r--r--libgo/go/go/build/build.go70
-rw-r--r--libgo/go/go/build/build_test.go3
-rw-r--r--libgo/go/go/build/constraint/expr.go574
-rw-r--r--libgo/go/go/build/constraint/expr_test.go317
-rw-r--r--libgo/go/go/build/deps_test.go47
-rw-r--r--libgo/go/go/build/read.go109
-rw-r--r--libgo/go/go/build/read_test.go69
-rw-r--r--libgo/go/go/build/testdata/withvendor/src/a/vendor/c/d/d.go (renamed from libgo/go/go/build/testdata/withvendor/src/a/c/d/d.go)0
-rw-r--r--libgo/go/go/internal/gccgoimporter/gccgoinstallation.go2
-rw-r--r--libgo/go/go/internal/srcimporter/srcimporter.go2
-rw-r--r--libgo/go/go/types/stdlib_test.go2
-rw-r--r--libgo/go/golang.org/x/mod/modfile/rule.go30
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/analysis.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/diagnostic.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/doc.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/internal/analysisflags/help.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/passes/printf/types.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/passes/structtag/structtag.go94
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/analysis/validate.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/ast/astutil/util.go4
-rw-r--r--libgo/go/golang.org/x/tools/go/ast/inspector/typeof.go4
-rw-r--r--libgo/go/html/template/exec_test.go55
-rw-r--r--libgo/go/html/template/template.go90
-rw-r--r--libgo/go/internal/execabs/execabs.go70
-rw-r--r--libgo/go/internal/execabs/execabs_test.go104
-rw-r--r--libgo/go/internal/goroot/gc.go2
-rw-r--r--libgo/go/internal/syscall/windows/syscall_windows.go2
-rw-r--r--libgo/go/internal/syscall/windows/zsyscall_windows.go13
-rw-r--r--libgo/go/io/fs/glob.go4
-rw-r--r--libgo/go/io/fs/glob_test.go2
-rw-r--r--libgo/go/io/fs/walk.go15
-rw-r--r--libgo/go/io/fs/walk_test.go26
-rw-r--r--libgo/go/io/ioutil/example_test.go2
-rw-r--r--libgo/go/math/rand/gen_cooked.go2
-rw-r--r--libgo/go/math/sqrt.go2
-rw-r--r--libgo/go/net/http/fcgi/child.go3
-rw-r--r--libgo/go/net/http/fcgi/fcgi_test.go12
-rw-r--r--libgo/go/net/http/httputil/dump.go15
-rw-r--r--libgo/go/net/http/httputil/dump_test.go80
-rw-r--r--libgo/go/net/http/serve_test.go6
-rw-r--r--libgo/go/net/http/server.go2
-rw-r--r--libgo/go/net/http/transport.go10
-rw-r--r--libgo/go/net/http/transport_test.go2
-rw-r--r--libgo/go/net/mail/message_test.go8
-rw-r--r--libgo/go/os/file_plan9.go10
-rw-r--r--libgo/go/os/file_unix.go8
-rw-r--r--libgo/go/os/os_test.go45
-rw-r--r--libgo/go/os/os_windows_test.go11
-rw-r--r--libgo/go/os/signal/signal_linux_test.go42
-rw-r--r--libgo/go/os/signal/signal_test.go102
-rw-r--r--libgo/go/os/tempfile.go21
-rw-r--r--libgo/go/os/testdata/dirfs/a0
-rw-r--r--libgo/go/os/testdata/dirfs/b0
-rw-r--r--libgo/go/os/testdata/dirfs/dir/x0
-rw-r--r--libgo/go/reflect/all_test.go170
-rw-r--r--libgo/go/reflect/type.go43
-rw-r--r--libgo/go/runtime/crash_test.go12
-rw-r--r--libgo/go/runtime/defer_test.go28
-rw-r--r--libgo/go/runtime/export_test.go4
-rw-r--r--libgo/go/runtime/histogram.go60
-rw-r--r--libgo/go/runtime/histogram_test.go22
-rw-r--r--libgo/go/runtime/metrics.go53
-rw-r--r--libgo/go/runtime/metrics/description.go16
-rw-r--r--libgo/go/runtime/metrics/doc.go4
-rw-r--r--libgo/go/runtime/metrics/example_test.go96
-rw-r--r--libgo/go/runtime/metrics/histogram.go29
-rw-r--r--libgo/go/runtime/metrics/value.go2
-rw-r--r--libgo/go/runtime/metrics_test.go38
-rw-r--r--libgo/go/runtime/mgcmark.go4
-rw-r--r--libgo/go/runtime/mgcscavenge.go2
-rw-r--r--libgo/go/runtime/msan0.go9
-rw-r--r--libgo/go/runtime/os_freebsd.go2
-rw-r--r--libgo/go/runtime/os_gccgo.go5
-rw-r--r--libgo/go/runtime/os_js.go7
-rw-r--r--libgo/go/runtime/os_openbsd.go1
-rw-r--r--libgo/go/runtime/proc.go79
-rw-r--r--libgo/go/runtime/runtime2.go1
-rw-r--r--libgo/go/runtime/signal_unix.go9
-rw-r--r--libgo/go/runtime/signal_windows_test.go64
-rw-r--r--libgo/go/runtime/sigqueue.go34
-rw-r--r--libgo/go/runtime/stubs2.go2
-rw-r--r--libgo/go/runtime/testdata/testprog/deadlock.go39
-rw-r--r--libgo/go/runtime/testdata/testwinsignal/main.go19
-rw-r--r--libgo/go/runtime/time.go6
-rw-r--r--libgo/go/runtime/timestub2.go4
-rw-r--r--libgo/go/syscall/exec_darwin.go259
-rw-r--r--libgo/go/syscall/exec_unix.go4
-rw-r--r--libgo/go/syscall/mkasm.go (renamed from libgo/go/syscall/mkasm_darwin.go)31
-rw-r--r--libgo/go/syscall/syscall_linux_test.go13
-rw-r--r--libgo/go/testing/fstest/testfs.go3
-rw-r--r--libgo/go/time/sleep.go13
-rw-r--r--libgo/go/time/tzdata/zipdata.go13652
-rw-r--r--libgo/libgo-packages.txt2
-rwxr-xr-xlibgo/merge.sh2
-rw-r--r--libgo/misc/cgo/test/pkg_test.go2
-rw-r--r--libgo/misc/cgo/testcarchive/carchive_test.go5
187 files changed, 10352 insertions, 10091 deletions
diff --git a/libgo/MERGE b/libgo/MERGE
index c5546950b8b..b2fc633f06c 100644
--- a/libgo/MERGE
+++ b/libgo/MERGE
@@ -1,4 +1,4 @@
12ff33f5e443165e55a080f3a649e4c070c4096d1 13e06467282c6d5678a6273747658c04314e013ef
2 2
3The first line of this file holds the git revision number of the 3The first line of this file holds the git revision number of the
4last merge done from the master library sources. 4last merge done from the master library sources.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 6188725f73b..7be90a564fe 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -656,7 +656,7 @@ noinst_DATA += zdefaultcc.go
656 656
657# Generate the list of go std packages that were included in libgo 657# Generate the list of go std packages that were included in libgo
658zstdpkglist.go: s-zstdpkglist; @true 658zstdpkglist.go: s-zstdpkglist; @true
659s-zstdpkglist: Makefile 659s-zstdpkglist: Makefile libgo-packages.txt
660 rm -f zstdpkglist.go.tmp 660 rm -f zstdpkglist.go.tmp
661 echo 'package goroot' > zstdpkglist.go.tmp 661 echo 'package goroot' > zstdpkglist.go.tmp
662 echo "" >> zstdpkglist.go.tmp 662 echo "" >> zstdpkglist.go.tmp
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index daae4f842d7..c52723b6d88 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -2828,7 +2828,7 @@ s-runtime-inc: runtime.lo mkruntimeinc.sh Makefile
2828 2828
2829# Generate the list of go std packages that were included in libgo 2829# Generate the list of go std packages that were included in libgo
2830zstdpkglist.go: s-zstdpkglist; @true 2830zstdpkglist.go: s-zstdpkglist; @true
2831s-zstdpkglist: Makefile 2831s-zstdpkglist: Makefile libgo-packages.txt
2832 rm -f zstdpkglist.go.tmp 2832 rm -f zstdpkglist.go.tmp
2833 echo 'package goroot' > zstdpkglist.go.tmp 2833 echo 'package goroot' > zstdpkglist.go.tmp
2834 echo "" >> zstdpkglist.go.tmp 2834 echo "" >> zstdpkglist.go.tmp
diff --git a/libgo/VERSION b/libgo/VERSION
index 257f7ce59ec..a19294250b3 100644
--- a/libgo/VERSION
+++ b/libgo/VERSION
@@ -1 +1 @@
go1.16beta1 go1.16rc1
diff --git a/libgo/check-packages.txt b/libgo/check-packages.txt
index a0148cfccc4..1e549cae4b0 100644
--- a/libgo/check-packages.txt
+++ b/libgo/check-packages.txt
@@ -80,6 +80,7 @@ flag
80fmt 80fmt
81go/ast 81go/ast
82go/build 82go/build
83go/build/constraint
83go/constant 84go/constant
84go/doc 85go/doc
85go/format 86go/format
@@ -107,6 +108,7 @@ image/jpeg
107image/png 108image/png
108index/suffixarray 109index/suffixarray
109internal/cpu 110internal/cpu
111internal/execabs
110internal/fmtsort 112internal/fmtsort
111internal/poll 113internal/poll
112internal/profile 114internal/profile
diff --git a/libgo/go/archive/tar/strconv.go b/libgo/go/archive/tar/strconv.go
index 0a910f33b9d..6d0a4038082 100644
--- a/libgo/go/archive/tar/strconv.go
+++ b/libgo/go/archive/tar/strconv.go
@@ -28,7 +28,7 @@ func isASCII(s string) bool {
28} 28}
29 29
30// toASCII converts the input to an ASCII C-style string. 30// toASCII converts the input to an ASCII C-style string.
31// This a best effort conversion, so invalid characters are dropped. 31// This is a best effort conversion, so invalid characters are dropped.
32func toASCII(s string) string { 32func toASCII(s string) string {
33 if isASCII(s) { 33 if isASCII(s) {
34 return s 34 return s
diff --git a/libgo/go/cmd/cgo/gcc.go b/libgo/go/cmd/cgo/gcc.go
index 796ff8ac520..fa24567d9bc 100644
--- a/libgo/go/cmd/cgo/gcc.go
+++ b/libgo/go/cmd/cgo/gcc.go
@@ -1567,7 +1567,14 @@ func (p *Package) gccBaseCmd() []string {
1567func (p *Package) gccMachine() []string { 1567func (p *Package) gccMachine() []string {
1568 switch goarch { 1568 switch goarch {
1569 case "amd64": 1569 case "amd64":
1570 if goos == "darwin" {
1571 return []string{"-arch", "x86_64", "-m64"}
1572 }
1570 return []string{"-m64"} 1573 return []string{"-m64"}
1574 case "arm64":
1575 if goos == "darwin" {
1576 return []string{"-arch", "arm64"}
1577 }
1571 case "386": 1578 case "386":
1572 return []string{"-m32"} 1579 return []string{"-m32"}
1573 case "arm": 1580 case "arm":
diff --git a/libgo/go/cmd/cgo/out.go b/libgo/go/cmd/cgo/out.go
index 6cdebac5e2b..b469b5fe06a 100644
--- a/libgo/go/cmd/cgo/out.go
+++ b/libgo/go/cmd/cgo/out.go
@@ -14,10 +14,10 @@ import (
14 "go/ast" 14 "go/ast"
15 "go/printer" 15 "go/printer"
16 "go/token" 16 "go/token"
17 exec "internal/execabs"
17 "internal/xcoff" 18 "internal/xcoff"
18 "io" 19 "io"
19 "os" 20 "os"
20 "os/exec"
21 "path/filepath" 21 "path/filepath"
22 "regexp" 22 "regexp"
23 "sort" 23 "sort"
@@ -958,9 +958,9 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
958 // Build the wrapper function compiled by gcc. 958 // Build the wrapper function compiled by gcc.
959 gccExport := "" 959 gccExport := ""
960 if goos == "windows" { 960 if goos == "windows" {
961 gccExport = "__declspec(dllexport)" 961 gccExport = "__declspec(dllexport) "
962 } 962 }
963 s := fmt.Sprintf("%s %s %s(", gccExport, gccResult, exp.ExpName) 963 s := fmt.Sprintf("%s%s %s(", gccExport, gccResult, exp.ExpName)
964 if fn.Recv != nil { 964 if fn.Recv != nil {
965 s += p.cgoType(fn.Recv.List[0].Type).C.String() 965 s += p.cgoType(fn.Recv.List[0].Type).C.String()
966 s += " recv" 966 s += " recv"
diff --git a/libgo/go/cmd/cgo/util.go b/libgo/go/cmd/cgo/util.go
index 921306b7aab..00d931b98a0 100644
--- a/libgo/go/cmd/cgo/util.go
+++ b/libgo/go/cmd/cgo/util.go
@@ -8,9 +8,9 @@ import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "go/token" 10 "go/token"
11 exec "internal/execabs"
11 "io/ioutil" 12 "io/ioutil"
12 "os" 13 "os"
13 "os/exec"
14) 14)
15 15
16// run runs the command argv, feeding in stdin on standard input. 16// run runs the command argv, feeding in stdin on standard input.
@@ -63,7 +63,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
63 p.Env = append(os.Environ(), "TERM=dumb") 63 p.Env = append(os.Environ(), "TERM=dumb")
64 err := p.Run() 64 err := p.Run()
65 if _, ok := err.(*exec.ExitError); err != nil && !ok { 65 if _, ok := err.(*exec.ExitError); err != nil && !ok {
66 fatalf("%s", err) 66 fatalf("exec %s: %s", argv[0], err)
67 } 67 }
68 ok = p.ProcessState.Success() 68 ok = p.ProcessState.Success()
69 stdout, stderr = bout.Bytes(), berr.Bytes() 69 stdout, stderr = bout.Bytes(), berr.Bytes()
@@ -88,7 +88,7 @@ func fatalf(msg string, args ...interface{}) {
88 // If we've already printed other errors, they might have 88 // If we've already printed other errors, they might have
89 // caused the fatal condition. Assume they're enough. 89 // caused the fatal condition. Assume they're enough.
90 if nerrors == 0 { 90 if nerrors == 0 {
91 fmt.Fprintf(os.Stderr, msg+"\n", args...) 91 fmt.Fprintf(os.Stderr, "cgo: "+msg+"\n", args...)
92 } 92 }
93 os.Exit(2) 93 os.Exit(2)
94} 94}
diff --git a/libgo/go/cmd/go.mod b/libgo/go/cmd/go.mod
index 031b8d4ab75..235e28f64f3 100644
--- a/libgo/go/cmd/go.mod
+++ b/libgo/go/cmd/go.mod
@@ -6,7 +6,7 @@ require (
6 github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2 6 github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2
7 golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff 7 golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff
8 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 8 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
9 golang.org/x/mod v0.4.0 9 golang.org/x/mod v0.4.1
10 golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect 10 golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
11 golang.org/x/tools v0.0.0-20201211025543-abf6a1d87e11 11 golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff
12) 12)
diff --git a/libgo/go/cmd/go/alldocs.go b/libgo/go/cmd/go/alldocs.go
index c4913ce6954..49d390297cd 100644
--- a/libgo/go/cmd/go/alldocs.go
+++ b/libgo/go/cmd/go/alldocs.go
@@ -153,7 +153,10 @@
153// created with -buildmode=shared. 153// created with -buildmode=shared.
154// -mod mode 154// -mod mode
155// module download mode to use: readonly, vendor, or mod. 155// module download mode to use: readonly, vendor, or mod.
156// See 'go help modules' for more. 156// By default, if a vendor directory is present and the go version in go.mod
157// is 1.14 or higher, the go command acts as if -mod=vendor were set.
158// Otherwise, the go command acts as if -mod=readonly were set.
159// See https://golang.org/ref/mod#build-commands for details.
157// -modcacherw 160// -modcacherw
158// leave newly-created directories in the module cache read-write 161// leave newly-created directories in the module cache read-write
159// instead of making them read-only. 162// instead of making them read-only.
@@ -492,15 +495,6 @@
492// (gofmt), a fully qualified path (/usr/you/bin/mytool), or a 495// (gofmt), a fully qualified path (/usr/you/bin/mytool), or a
493// command alias, described below. 496// command alias, described below.
494// 497//
495// To convey to humans and machine tools that code is generated,
496// generated source should have a line that matches the following
497// regular expression (in Go syntax):
498//
499// ^// Code generated .* DO NOT EDIT\.$
500//
501// The line may appear anywhere in the file, but is typically
502// placed near the beginning so it is easy to find.
503//
504// Note that go generate does not parse the file, so lines that look 498// Note that go generate does not parse the file, so lines that look
505// like directives in comments or multiline strings will be treated 499// like directives in comments or multiline strings will be treated
506// as directives. 500// as directives.
@@ -512,6 +506,15 @@
512// Quoted strings use Go syntax and are evaluated before execution; a 506// Quoted strings use Go syntax and are evaluated before execution; a
513// quoted string appears as a single argument to the generator. 507// quoted string appears as a single argument to the generator.
514// 508//
509// To convey to humans and machine tools that code is generated,
510// generated source should have a line that matches the following
511// regular expression (in Go syntax):
512//
513// ^// Code generated .* DO NOT EDIT\.$
514//
515// This line must appear before the first non-comment, non-blank
516// text in the file.
517//
515// Go generate sets several variables when it runs the generator: 518// Go generate sets several variables when it runs the generator:
516// 519//
517// $GOARCH 520// $GOARCH
@@ -595,85 +598,49 @@
595// 598//
596// go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages] 599// go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]
597// 600//
598// Get resolves and adds dependencies to the current development module 601// Get resolves its command-line arguments to packages at specific module versions,
599// and then builds and installs them. 602// updates go.mod to require those versions, downloads source code into the
600// 603// module cache, then builds and installs the named packages.
601// The first step is to resolve which dependencies to add. 604//
602// 605// To add a dependency for a package or upgrade it to its latest version:
603// For each named package or package pattern, get must decide which version of 606//
604// the corresponding module to use. By default, get looks up the latest tagged 607// go get example.com/pkg
605// release version, such as v0.4.5 or v1.2.3. If there are no tagged release 608//
606// versions, get looks up the latest tagged pre-release version, such as 609// To upgrade or downgrade a package to a specific version:
607// v0.0.1-pre1. If there are no tagged versions at all, get looks up the latest 610//
608// known commit. If the module is not already required at a later version 611// go get example.com/pkg@v1.2.3
609// (for example, a pre-release newer than the latest release), get will use 612//
610// the version it looked up. Otherwise, get will use the currently 613// To remove a dependency on a module and downgrade modules that require it:
611// required version. 614//
612// 615// go get example.com/mod@none
613// This default version selection can be overridden by adding an @version 616//
614// suffix to the package argument, as in 'go get golang.org/x/text@v0.3.0'. 617// See https://golang.org/ref/mod#go-get for details.
615// The version may be a prefix: @v1 denotes the latest available version starting 618//
616// with v1. See 'go help modules' under the heading 'Module queries' for the 619// The 'go install' command may be used to build and install packages. When a
617// full query syntax. 620// version is specified, 'go install' runs in module-aware mode and ignores
618// 621// the go.mod file in the current directory. For example:
619// For modules stored in source control repositories, the version suffix can 622//
620// also be a commit hash, branch identifier, or other syntax known to the 623// go install example.com/pkg@v1.2.3
621// source control system, as in 'go get golang.org/x/text@master'. Note that 624// go install example.com/pkg@latest
622// branches with names that overlap with other module query syntax cannot be 625//
623// selected explicitly. For example, the suffix @v2 means the latest version 626// See 'go help install' or https://golang.org/ref/mod#go-install for details.
624// starting with v2, not the branch named v2. 627//
625// 628// In addition to build flags (listed in 'go help build') 'go get' accepts the
626// If a module under consideration is already a dependency of the current 629// following flags.
627// development module, then get will update the required version.
628// Specifying a version earlier than the current required version is valid and
629// downgrades the dependency. The version suffix @none indicates that the
630// dependency should be removed entirely, downgrading or removing modules
631// depending on it as needed.
632//
633// The version suffix @latest explicitly requests the latest minor release of
634// the module named by the given path. The suffix @upgrade is like @latest but
635// will not downgrade a module if it is already required at a revision or
636// pre-release version newer than the latest released version. The suffix
637// @patch requests the latest patch release: the latest released version
638// with the same major and minor version numbers as the currently required
639// version. Like @upgrade, @patch will not downgrade a module already required
640// at a newer version. If the path is not already required, @upgrade is
641// equivalent to @latest, and @patch is disallowed.
642//
643// Although get defaults to using the latest version of the module containing
644// a named package, it does not use the latest version of that module's
645// dependencies. Instead it prefers to use the specific dependency versions
646// requested by that module. For example, if the latest A requires module
647// B v1.2.3, while B v1.2.4 and v1.3.1 are also available, then 'go get A'
648// will use the latest A but then use B v1.2.3, as requested by A. (If there
649// are competing requirements for a particular module, then 'go get' resolves
650// those requirements by taking the maximum requested version.)
651// 630//
652// The -t flag instructs get to consider modules needed to build tests of 631// The -t flag instructs get to consider modules needed to build tests of
653// packages specified on the command line. 632// packages specified on the command line.
654// 633//
655// The -u flag instructs get to update modules providing dependencies 634// The -u flag instructs get to update modules providing dependencies
656// of packages named on the command line to use newer minor or patch 635// of packages named on the command line to use newer minor or patch
657// releases when available. Continuing the previous example, 'go get -u A' 636// releases when available.
658// will use the latest A with B v1.3.1 (not B v1.2.3). If B requires module C,
659// but C does not provide any packages needed to build packages in A
660// (not including tests), then C will not be updated.
661// 637//
662// The -u=patch flag (not -u patch) also instructs get to update dependencies, 638// The -u=patch flag (not -u patch) also instructs get to update dependencies,
663// but changes the default to select patch releases. 639// but changes the default to select patch releases.
664// Continuing the previous example,
665// 'go get -u=patch A@latest' will use the latest A with B v1.2.4 (not B v1.2.3),
666// while 'go get -u=patch A' will use a patch release of A instead.
667// 640//
668// When the -t and -u flags are used together, get will update 641// When the -t and -u flags are used together, get will update
669// test dependencies as well. 642// test dependencies as well.
670// 643//
671// In general, adding a new dependency may require upgrading
672// existing dependencies to keep a working build, and 'go get' does
673// this automatically. Similarly, downgrading one dependency may
674// require downgrading other dependencies, and 'go get' does
675// this automatically as well.
676//
677// The -insecure flag permits fetching from repositories and resolving 644// The -insecure flag permits fetching from repositories and resolving
678// custom domains using insecure schemes such as HTTP, and also bypassess 645// custom domains using insecure schemes such as HTTP, and also bypassess
679// module sum validation using the checksum database. Use with caution. 646// module sum validation using the checksum database. Use with caution.
@@ -682,12 +649,8 @@
682// variable instead. To bypass module sum validation, use GOPRIVATE or 649// variable instead. To bypass module sum validation, use GOPRIVATE or
683// GONOSUMDB. See 'go help environment' for details. 650// GONOSUMDB. See 'go help environment' for details.
684// 651//
685// The second step is to download (if needed), build, and install 652// The -d flag instructs get not to build or install packages. get will only
686// the named packages. 653// update go.mod and download source code needed to build packages.
687//
688// The -d flag instructs get to skip this step, downloading source code
689// needed to build the named packages and their dependencies, but not
690// building or installing.
691// 654//
692// Building and installing packages with get is deprecated. In a future release, 655// Building and installing packages with get is deprecated. In a future release,
693// the -d flag will be enabled by default, and 'go get' will be only be used to 656// the -d flag will be enabled by default, and 'go get' will be only be used to
@@ -696,31 +659,14 @@
696// ignoring the current module, use 'go install' with an @version suffix like 659// ignoring the current module, use 'go install' with an @version suffix like
697// "@latest" after each argument. 660// "@latest" after each argument.
698// 661//
699// If an argument names a module but not a package (because there is no 662// For more about modules, see https://golang.org/ref/mod.
700// Go source code in the module's root directory), then the install step
701// is skipped for that argument, instead of causing a build failure.
702// For example 'go get golang.org/x/perf' succeeds even though there
703// is no code corresponding to that import path.
704//
705// Note that package patterns are allowed and are expanded after resolving
706// the module versions. For example, 'go get golang.org/x/perf/cmd/...'
707// adds the latest golang.org/x/perf and then installs the commands in that
708// latest version.
709//
710// With no package arguments, 'go get' applies to Go package in the
711// current directory, if any. In particular, 'go get -u' and
712// 'go get -u=patch' update all the dependencies of that package.
713// With no package arguments and also without -u, 'go get' is not much more
714// than 'go install', and 'go get -d' not much more than 'go list'.
715//
716// For more about modules, see 'go help modules'.
717// 663//
718// For more about specifying packages, see 'go help packages'. 664// For more about specifying packages, see 'go help packages'.
719// 665//
720// This text describes the behavior of get using modules to manage source 666// This text describes the behavior of get using modules to manage source
721// code and dependencies. If instead the go command is running in GOPATH 667// code and dependencies. If instead the go command is running in GOPATH
722// mode, the details of get's flags and effects change, as does 'go help get'. 668// mode, the details of get's flags and effects change, as does 'go help get'.
723// See 'go help modules' and 'go help gopath-get'. 669// See 'go help gopath-get'.
724// 670//
725// See also: go build, go install, go clean, go mod. 671// See also: go build, go install, go clean, go mod.
726// 672//
@@ -840,6 +786,14 @@
840// TestGoFiles []string // _test.go files in package 786// TestGoFiles []string // _test.go files in package
841// XTestGoFiles []string // _test.go files outside package 787// XTestGoFiles []string // _test.go files outside package
842// 788//
789// // Embedded files
790// EmbedPatterns []string // //go:embed patterns
791// EmbedFiles []string // files matched by EmbedPatterns
792// TestEmbedPatterns []string // //go:embed patterns in TestGoFiles
793// TestEmbedFiles []string // files matched by TestEmbedPatterns
794// XTestEmbedPatterns []string // //go:embed patterns in XTestGoFiles
795// XTestEmbedFiles []string // files matched by XTestEmbedPatterns
796//
843// // Cgo directives 797// // Cgo directives
844// CgoCFLAGS []string // cgo: flags for C compiler 798// CgoCFLAGS []string // cgo: flags for C compiler
845// CgoCPPFLAGS []string // cgo: flags for C preprocessor 799// CgoCPPFLAGS []string // cgo: flags for C preprocessor
@@ -1051,7 +1005,7 @@
1051// 1005//
1052// For more about specifying packages, see 'go help packages'. 1006// For more about specifying packages, see 'go help packages'.
1053// 1007//
1054// For more about modules, see 'go help modules'. 1008// For more about modules, see https://golang.org/ref/mod.
1055// 1009//
1056// 1010//
1057// Module maintenance 1011// Module maintenance
@@ -1116,7 +1070,9 @@
1116// 1070//
1117// The -x flag causes download to print the commands download executes. 1071// The -x flag causes download to print the commands download executes.
1118// 1072//
1119// See 'go help modules' for more about module queries. 1073// See https://golang.org/ref/mod#go-mod-download for more about 'go mod download'.
1074//
1075// See https://golang.org/ref/mod#version-queries for more about version queries.
1120// 1076//
1121// 1077//
1122// Edit go.mod from tools or scripts 1078// Edit go.mod from tools or scripts
@@ -1192,6 +1148,7 @@
1192// Require []Require 1148// Require []Require
1193// Exclude []Module 1149// Exclude []Module
1194// Replace []Replace 1150// Replace []Replace
1151// Retract []Retract
1195// } 1152// }
1196// 1153//
1197// type Require struct { 1154// type Require struct {
@@ -1218,9 +1175,7 @@
1218// referred to indirectly. For the full set of modules available to a build, 1175// referred to indirectly. For the full set of modules available to a build,
1219// use 'go list -m -json all'. 1176// use 'go list -m -json all'.
1220// 1177//
1221// For example, a tool can obtain the go.mod as a data structure by 1178// See https://golang.org/ref/mod#go-mod-edit for more about 'go mod edit'.
1222// parsing the output of 'go mod edit -json' and can then make changes
1223// by invoking 'go mod edit' with -require, -exclude, and so on.
1224// 1179//
1225// 1180//
1226// Print module requirement graph 1181// Print module requirement graph
@@ -1234,6 +1189,8 @@
1234// and one of its requirements. Each module is identified as a string of the form 1189// and one of its requirements. Each module is identified as a string of the form
1235// path@version, except for the main module, which has no @version suffix. 1190// path@version, except for the main module, which has no @version suffix.
1236// 1191//
1192// See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'.
1193//
1237// 1194//
1238// Initialize new module in current directory 1195// Initialize new module in current directory
1239// 1196//
@@ -1253,6 +1210,8 @@
1253// If a configuration file for a vendoring tool is present, init will attempt to 1210// If a configuration file for a vendoring tool is present, init will attempt to
1254// import module requirements from it. 1211// import module requirements from it.
1255// 1212//
1213// See https://golang.org/ref/mod#go-mod-init for more about 'go mod init'.
1214//
1256// 1215//
1257// Add missing and remove unused modules 1216// Add missing and remove unused modules
1258// 1217//
@@ -1272,6 +1231,8 @@
1272// The -e flag causes tidy to attempt to proceed despite errors 1231// The -e flag causes tidy to attempt to proceed despite errors
1273// encountered while loading packages. 1232// encountered while loading packages.
1274// 1233//
1234// See https://golang.org/ref/mod#go-mod-tidy for more about 'go mod tidy'.
1235//
1275// 1236//
1276// Make vendored copy of dependencies 1237// Make vendored copy of dependencies
1277// 1238//
@@ -1289,6 +1250,8 @@
1289// The -e flag causes vendor to attempt to proceed despite errors 1250// The -e flag causes vendor to attempt to proceed despite errors
1290// encountered while loading packages. 1251// encountered while loading packages.
1291// 1252//
1253// See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
1254//
1292// 1255//
1293// Verify dependencies have expected content 1256// Verify dependencies have expected content
1294// 1257//
@@ -1303,6 +1266,8 @@
1303// modules have been changed and causes 'go mod' to exit with a 1266// modules have been changed and causes 'go mod' to exit with a
1304// non-zero status. 1267// non-zero status.
1305// 1268//
1269// See https://golang.org/ref/mod#go-mod-verify for more about 'go mod verify'.
1270//
1306// 1271//
1307// Explain why packages or modules are needed 1272// Explain why packages or modules are needed
1308// 1273//
@@ -1339,6 +1304,8 @@
1339// (main module does not need package golang.org/x/text/encoding) 1304// (main module does not need package golang.org/x/text/encoding)
1340// $ 1305// $
1341// 1306//
1307// See https://golang.org/ref/mod#go-mod-why for more about 'go mod why'.
1308//
1342// 1309//
1343// Compile and run Go program 1310// Compile and run Go program
1344// 1311//
@@ -1783,6 +1750,10 @@
1783// 1750//
1784// General-purpose environment variables: 1751// General-purpose environment variables:
1785// 1752//
1753// GO111MODULE
1754// Controls whether the go command runs in module-aware mode or GOPATH mode.
1755// May be "off", "on", or "auto".
1756// See https://golang.org/ref/mod#mod-commands.
1786// GCCGO 1757// GCCGO
1787// The gccgo command to run for 'go build -compiler=gccgo'. 1758// The gccgo command to run for 'go build -compiler=gccgo'.
1788// GOARCH 1759// GOARCH
@@ -1821,20 +1792,24 @@
1821// GOPATH 1792// GOPATH
1822// For more details see: 'go help gopath'. 1793// For more details see: 'go help gopath'.
1823// GOPROXY 1794// GOPROXY
1824// URL of Go module proxy. See 'go help modules'. 1795// URL of Go module proxy. See https://golang.org/ref/mod#environment-variables
1796// and https://golang.org/ref/mod#module-proxy for details.
1825// GOPRIVATE, GONOPROXY, GONOSUMDB 1797// GOPRIVATE, GONOPROXY, GONOSUMDB
1826// Comma-separated list of glob patterns (in the syntax of Go's path.Match) 1798// Comma-separated list of glob patterns (in the syntax of Go's path.Match)
1827// of module path prefixes that should always be fetched directly 1799// of module path prefixes that should always be fetched directly
1828// or that should not be compared against the checksum database. 1800// or that should not be compared against the checksum database.
1829// See 'go help private'. 1801// See https://golang.org/ref/mod#private-modules.
1830// GOROOT 1802// GOROOT
1831// The root of the go tree. 1803// The root of the go tree.
1832// GOSUMDB 1804// GOSUMDB
1833// The name of checksum database to use and optionally its public key and 1805// The name of checksum database to use and optionally its public key and
1834// URL. See 'go help module-auth'. 1806// URL. See https://golang.org/ref/mod#authenticating.
1835// GOTMPDIR 1807// GOTMPDIR
1836// The directory where the go command will write 1808// The directory where the go command will write
1837// temporary source files, packages, and binaries. 1809// temporary source files, packages, and binaries.
1810// GOVCS
1811// Lists version control commands that may be used with matching servers.
1812// See 'go help vcs'.
1838// 1813//
1839// Environment variables for use with cgo: 1814// Environment variables for use with cgo:
1840// 1815//
@@ -1979,88 +1954,23 @@
1979// directory and then successive parent directories to find the go.mod 1954// directory and then successive parent directories to find the go.mod
1980// marking the root of the main (current) module. 1955// marking the root of the main (current) module.
1981// 1956//
1982// The go.mod file itself is line-oriented, with // comments but 1957// The go.mod file format is described in detail at
1983// no /* */ comments. Each line holds a single directive, made up of a 1958// https://golang.org/ref/mod#go-mod-file.
1984// verb followed by arguments. For example: 1959//
1985// 1960// To create a new go.mod file, use 'go help init'. For details see
1986// module my/thing 1961// 'go help mod init' or https://golang.org/ref/mod#go-mod-init.
1987// go 1.12 1962//
1988// require other/thing v1.0.2 1963// To add missing module requirements or remove unneeded requirements,
1989// require new/thing/v2 v2.3.4 1964// use 'go mod tidy'. For details, see 'go help mod tidy' or
1990// exclude old/thing v1.2.3 1965// https://golang.org/ref/mod#go-mod-tidy.
1991// replace bad/thing v1.4.5 => good/thing v1.4.5 1966//
1992// retract v1.5.6 1967// To add, upgrade, downgrade, or remove a specific module requirement, use
1993// 1968// 'go get'. For details, see 'go help module-get' or
1994// The verbs are 1969// https://golang.org/ref/mod#go-get.
1995// module, to define the module path; 1970//
1996// go, to set the expected language version; 1971// To make other changes or to parse go.mod as JSON for use by other tools,
1997// require, to require a particular module at a given version or later; 1972// use 'go mod edit'. See 'go help mod edit' or
1998// exclude, to exclude a particular module version from use; 1973// https://golang.org/ref/mod#go-mod-edit.
1999// replace, to replace a module version with a different module version; and
2000// retract, to indicate a previously released version should not be used.
2001// Exclude and replace apply only in the main module's go.mod and are ignored
2002// in dependencies. See https://golang.org/ref/mod for details.
2003//
2004// The leading verb can be factored out of adjacent lines to create a block,
2005// like in Go imports:
2006//
2007// require (
2008// new/thing/v2 v2.3.4
2009// old/thing v1.2.3
2010// )
2011//
2012// The go.mod file is designed both to be edited directly and to be
2013// easily updated by tools. The 'go mod edit' command can be used to
2014// parse and edit the go.mod file from programs and tools.
2015// See 'go help mod edit'.
2016//
2017// The go command automatically updates go.mod each time it uses the
2018// module graph, to make sure go.mod always accurately reflects reality
2019// and is properly formatted. For example, consider this go.mod file:
2020//
2021// module M
2022//
2023// require (
2024// A v1
2025// B v1.0.0
2026// C v1.0.0
2027// D v1.2.3
2028// E dev
2029// )
2030//
2031// exclude D v1.2.3
2032//
2033// The update rewrites non-canonical version identifiers to semver form,
2034// so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the
2035// latest commit on the dev branch, perhaps v0.0.0-20180523231146-b3f5c0f6e5f1.
2036//
2037// The update modifies requirements to respect exclusions, so the
2038// requirement on the excluded D v1.2.3 is updated to use the next
2039// available version of D, perhaps D v1.2.4 or D v1.3.0.
2040//
2041// The update removes redundant or misleading requirements.
2042// For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0,
2043// then go.mod's requirement of B v1.0.0 is misleading (superseded by
2044// A's need for v1.2.0), and its requirement of C v1.0.0 is redundant
2045// (implied by A's need for the same version), so both will be removed.
2046// If module M contains packages that directly import packages from B or
2047// C, then the requirements will be kept but updated to the actual
2048// versions being used.
2049//
2050// Finally, the update reformats the go.mod in a canonical formatting, so
2051// that future mechanical changes will result in minimal diffs.
2052//
2053// Because the module graph defines the meaning of import statements, any
2054// commands that load packages also use and therefore update go.mod,
2055// including go build, go get, go install, go list, go test, go mod graph,
2056// go mod tidy, and go mod why.
2057//
2058// The expected language version, set by the go directive, determines
2059// which language features are available when compiling the module.
2060// Language features available in that version will be available for use.
2061// Language features removed in earlier versions, or added in later versions,
2062// will not be available. Note that the language version does not affect
2063// build tags, which are determined by the Go release being used.
2064// 1974//
2065// 1975//
2066// GOPATH environment variable 1976// GOPATH environment variable
@@ -2295,65 +2205,8 @@
2295// a site serving from a fixed file system (including a file:/// URL) 2205// a site serving from a fixed file system (including a file:/// URL)
2296// can be a module proxy. 2206// can be a module proxy.
2297// 2207//
2298// The GET requests sent to a Go module proxy are: 2208// For details on the GOPROXY protocol, see
2299// 2209// https://golang.org/ref/mod#goproxy-protocol.
2300// GET $GOPROXY/<module>/@v/list returns a list of known versions of the given
2301// module, one per line.
2302//
2303// GET $GOPROXY/<module>/@v/<version>.info returns JSON-formatted metadata
2304// about that version of the given module.
2305//
2306// GET $GOPROXY/<module>/@v/<version>.mod returns the go.mod file
2307// for that version of the given module.
2308//
2309// GET $GOPROXY/<module>/@v/<version>.zip returns the zip archive
2310// for that version of the given module.
2311//
2312// GET $GOPROXY/<module>/@latest returns JSON-formatted metadata about the
2313// latest known version of the given module in the same format as
2314// <module>/@v/<version>.info. The latest version should be the version of
2315// the module the go command may use if <module>/@v/list is empty or no
2316// listed version is suitable. <module>/@latest is optional and may not
2317// be implemented by a module proxy.
2318//
2319// When resolving the latest version of a module, the go command will request
2320// <module>/@v/list, then, if no suitable versions are found, <module>/@latest.
2321// The go command prefers, in order: the semantically highest release version,
2322// the semantically highest pre-release version, and the chronologically
2323// most recent pseudo-version. In Go 1.12 and earlier, the go command considered
2324// pseudo-versions in <module>/@v/list to be pre-release versions, but this is
2325// no longer true since Go 1.13.
2326//
2327// To avoid problems when serving from case-sensitive file systems,
2328// the <module> and <version> elements are case-encoded, replacing every
2329// uppercase letter with an exclamation mark followed by the corresponding
2330// lower-case letter: github.com/Azure encodes as github.com/!azure.
2331//
2332// The JSON-formatted metadata about a given module corresponds to
2333// this Go data structure, which may be expanded in the future:
2334//
2335// type Info struct {
2336// Version string // version string
2337// Time time.Time // commit time
2338// }
2339//
2340// The zip archive for a specific version of a given module is a
2341// standard zip file that contains the file tree corresponding
2342// to the module's source code and related files. The archive uses
2343// slash-separated paths, and every file path in the archive must
2344// begin with <module>@<version>/, where the module and version are
2345// substituted directly, not case-encoded. The root of the module
2346// file tree corresponds to the <module>@<version>/ prefix in the
2347// archive.
2348//
2349// Even when downloading directly from version control systems,
2350// the go command synthesizes explicit info, mod, and zip files
2351// and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
2352// the same as if it had downloaded them directly from a proxy.
2353// The cache layout is the same as the proxy URL space, so
2354// serving $GOPATH/pkg/mod/cache/download at (or copying it to)
2355// https://example.com/proxy would let other users access those
2356// cached module versions with GOPROXY=https://example.com/proxy.
2357// 2210//
2358// 2211//
2359// Import path syntax 2212// Import path syntax
@@ -2504,7 +2357,7 @@
2504// (See 'go help gopath-get' and 'go help gopath'.) 2357// (See 'go help gopath-get' and 'go help gopath'.)
2505// 2358//
2506// When using modules, downloaded packages are stored in the module cache. 2359// When using modules, downloaded packages are stored in the module cache.
2507// (See 'go help module-get' and 'go help goproxy'.) 2360// See https://golang.org/ref/mod#module-cache.
2508// 2361//
2509// When using modules, an additional variant of the go-import meta tag is 2362// When using modules, an additional variant of the go-import meta tag is
2510// recognized and is preferred over those listing version control systems. 2363// recognized and is preferred over those listing version control systems.
@@ -2514,7 +2367,8 @@
2514// 2367//
2515// This tag means to fetch modules with paths beginning with example.org 2368// This tag means to fetch modules with paths beginning with example.org
2516// from the module proxy available at the URL https://code.org/moduleproxy. 2369// from the module proxy available at the URL https://code.org/moduleproxy.
2517// See 'go help goproxy' for details about the proxy protocol. 2370// See https://golang.org/ref/mod#goproxy-protocol for details about the
2371// proxy protocol.
2518// 2372//
2519// Import path checking 2373// Import path checking
2520// 2374//
@@ -2545,483 +2399,28 @@
2545// 2399//
2546// Modules, module versions, and more 2400// Modules, module versions, and more
2547// 2401//
2548// A module is a collection of related Go packages. 2402// Modules are how Go manages dependencies.
2549// Modules are the unit of source code interchange and versioning. 2403//
2550// The go command has direct support for working with modules, 2404// A module is a collection of packages that are released, versioned, and
2551// including recording and resolving dependencies on other modules. 2405// distributed together. Modules may be downloaded directly from version control
2552// Modules replace the old GOPATH-based approach to specifying 2406// repositories or from module proxy servers.
2553// which source files are used in a given build. 2407//
2554// 2408// For a series of tutorials on modules, see
2555// Module support 2409// https://golang.org/doc/tutorial/create-module.
2556// 2410//
2557// The go command includes support for Go modules. Module-aware mode is active 2411// For a detailed reference on modules, see https://golang.org/ref/mod.
2558// by default whenever a go.mod file is found in the current directory or in
2559// any parent directory.
2560//
2561// The quickest way to take advantage of module support is to check out your
2562// repository, create a go.mod file (described in the next section) there, and run
2563// go commands from within that file tree.
2564//
2565// For more fine-grained control, the go command continues to respect
2566// a temporary environment variable, GO111MODULE, which can be set to one
2567// of three string values: off, on, or auto (the default).
2568// If GO111MODULE=on, then the go command requires the use of modules,
2569// never consulting GOPATH. We refer to this as the command
2570// being module-aware or running in "module-aware mode".
2571// If GO111MODULE=off, then the go command never uses
2572// module support. Instead it looks in vendor directories and GOPATH
2573// to find dependencies; we now refer to this as "GOPATH mode."
2574// If GO111MODULE=auto or is unset, then the go command enables or disables
2575// module support based on the current directory.
2576// Module support is enabled only when the current directory contains a
2577// go.mod file or is below a directory containing a go.mod file.
2578//
2579// In module-aware mode, GOPATH no longer defines the meaning of imports
2580// during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
2581// and installed commands (in GOPATH/bin, unless GOBIN is set).
2582//
2583// Defining a module
2584//
2585// A module is defined by a tree of Go source files with a go.mod file
2586// in the tree's root directory. The directory containing the go.mod file
2587// is called the module root. Typically the module root will also correspond
2588// to a source code repository root (but in general it need not).
2589// The module is the set of all Go packages in the module root and its
2590// subdirectories, but excluding subtrees with their own go.mod files.
2591//
2592// The "module path" is the import path prefix corresponding to the module root.
2593// The go.mod file defines the module path and lists the specific versions
2594// of other modules that should be used when resolving imports during a build,
2595// by giving their module paths and versions.
2596//
2597// For example, this go.mod declares that the directory containing it is the root
2598// of the module with path example.com/m, and it also declares that the module
2599// depends on specific versions of golang.org/x/text and gopkg.in/yaml.v2:
2600//
2601// module example.com/m
2602//
2603// require (
2604// golang.org/x/text v0.3.0
2605// gopkg.in/yaml.v2 v2.1.0
2606// )
2607//
2608// The go.mod file can also specify replacements and excluded versions
2609// that only apply when building the module directly; they are ignored
2610// when the module is incorporated into a larger build.
2611// For more about the go.mod file, see 'go help go.mod'.
2612//
2613// To start a new module, simply create a go.mod file in the root of the
2614// module's directory tree, containing only a module statement.
2615// The 'go mod init' command can be used to do this:
2616//
2617// go mod init example.com/m
2618//
2619// In a project already using an existing dependency management tool like
2620// godep, glide, or dep, 'go mod init' will also add require statements
2621// matching the existing configuration.
2622//
2623// Once the go.mod file exists, no additional steps are required:
2624// go commands like 'go build', 'go test', or even 'go list' will automatically
2625// add new dependencies as needed to satisfy imports.
2626//
2627// The main module and the build list
2628//
2629// The "main module" is the module containing the directory where the go command
2630// is run. The go command finds the module root by looking for a go.mod in the
2631// current directory, or else the current directory's parent directory,
2632// or else the parent's parent directory, and so on.
2633//
2634// The main module's go.mod file defines the precise set of packages available
2635// for use by the go command, through require, replace, and exclude statements.
2636// Dependency modules, found by following require statements, also contribute
2637// to the definition of that set of packages, but only through their go.mod
2638// files' require statements: any replace and exclude statements in dependency
2639// modules are ignored. The replace and exclude statements therefore allow the
2640// main module complete control over its own build, without also being subject
2641// to complete control by dependencies.
2642//
2643// The set of modules providing packages to builds is called the "build list".
2644// The build list initially contains only the main module. Then the go command
2645// adds to the list the exact module versions required by modules already
2646// on the list, recursively, until there is nothing left to add to the list.
2647// If multiple versions of a particular module are added to the list,
2648// then at the end only the latest version (according to semantic version
2649// ordering) is kept for use in the build.
2650//
2651// The 'go list' command provides information about the main module
2652// and the build list. For example:
2653//
2654// go list -m # print path of main module
2655// go list -m -f={{.Dir}} # print root directory of main module
2656// go list -m all # print build list
2657//
2658// Maintaining module requirements
2659//
2660// The go.mod file is meant to be readable and editable by both programmers and
2661// tools. Most updates to dependencies can be performed using "go get" and
2662// "go mod tidy". Other module-aware build commands may be invoked using the
2663// -mod=mod flag to automatically add missing requirements and fix inconsistencies.
2664//
2665// The "go get" command updates go.mod to change the module versions used in a
2666// build. An upgrade of one module may imply upgrading others, and similarly a
2667// downgrade of one module may imply downgrading others. The "go get" command
2668// makes these implied changes as well. See "go help module-get".
2669//
2670// The "go mod" command provides other functionality for use in maintaining
2671// and understanding modules and go.mod files. See "go help mod", particularly
2672// "go help mod tidy" and "go help mod edit".
2673//
2674// As part of maintaining the require statements in go.mod, the go command
2675// tracks which ones provide packages imported directly by the current module
2676// and which ones provide packages only used indirectly by other module
2677// dependencies. Requirements needed only for indirect uses are marked with a
2678// "// indirect" comment in the go.mod file. Indirect requirements may be
2679// automatically removed from the go.mod file once they are implied by other
2680// direct requirements. Indirect requirements only arise when using modules
2681// that fail to state some of their own dependencies or when explicitly
2682// upgrading a module's dependencies ahead of its own stated requirements.
2683//
2684// The -mod build flag provides additional control over the updating and use of
2685// go.mod for commands that build packages like "go build" and "go test".
2686//
2687// If invoked with -mod=readonly (the default in most situations), the go command
2688// reports an error if a package named on the command line or an imported package
2689// is not provided by any module in the build list computed from the main module's
2690// requirements. The go command also reports an error if a module's checksum is
2691// missing from go.sum (see Module downloading and verification). Either go.mod or
2692// go.sum must be updated in these situations.
2693//
2694// If invoked with -mod=mod, the go command automatically updates go.mod and
2695// go.sum, fixing inconsistencies and adding missing requirements and checksums
2696// as needed. If the go command finds an unfamiliar import, it looks up the
2697// module containing that import and adds a requirement for the latest version
2698// of that module to go.mod. In most cases, therefore, one may add an import to
2699// source code and run "go build", "go test", or even "go list" with -mod=mod:
2700// as part of analyzing the package, the go command will resolve the import and
2701// update the go.mod file.
2702//
2703// If invoked with -mod=vendor, the go command loads packages from the main
2704// module's vendor directory instead of downloading modules to and loading packages
2705// from the module cache. The go command assumes the vendor directory holds
2706// correct copies of dependencies, and it does not compute the set of required
2707// module versions from go.mod files. However, the go command does check that
2708// vendor/modules.txt (generated by "go mod vendor") contains metadata consistent
2709// with go.mod.
2710//
2711// If the go command is not invoked with a -mod flag, and the vendor directory
2712// is present, and the "go" version in go.mod is 1.14 or higher, the go command
2713// will act as if it were invoked with -mod=vendor. Otherwise, the -mod flag
2714// defaults to -mod=readonly.
2715//
2716// Note that neither "go get" nor the "go mod" subcommands accept the -mod flag.
2717//
2718// Pseudo-versions
2719//
2720// The go.mod file and the go command more generally use semantic versions as
2721// the standard form for describing module versions, so that versions can be
2722// compared to determine which should be considered earlier or later than another.
2723// A module version like v1.2.3 is introduced by tagging a revision in the
2724// underlying source repository. Untagged revisions can be referred to
2725// using a "pseudo-version" like v0.0.0-yyyymmddhhmmss-abcdefabcdef,
2726// where the time is the commit time in UTC and the final suffix is the prefix
2727// of the commit hash. The time portion ensures that two pseudo-versions can
2728// be compared to determine which happened later, the commit hash identifes
2729// the underlying commit, and the prefix (v0.0.0- in this example) is derived from
2730// the most recent tagged version in the commit graph before this commit.
2731//
2732// There are three pseudo-version forms:
2733//
2734// vX.0.0-yyyymmddhhmmss-abcdefabcdef is used when there is no earlier
2735// versioned commit with an appropriate major version before the target commit.
2736// (This was originally the only form, so some older go.mod files use this form
2737// even for commits that do follow tags.)
2738//
2739// vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef is used when the most
2740// recent versioned commit before the target commit is vX.Y.Z-pre.
2741//
2742// vX.Y.(Z+1)-0.yyyymmddhhmmss-abcdefabcdef is used when the most
2743// recent versioned commit before the target commit is vX.Y.Z.
2744//
2745// Pseudo-versions never need to be typed by hand: the go command will accept
2746// the plain commit hash and translate it into a pseudo-version (or a tagged
2747// version if available) automatically. This conversion is an example of a
2748// module query.
2749//
2750// Module queries
2751//
2752// The go command accepts a "module query" in place of a module version
2753// both on the command line and in the main module's go.mod file.
2754// (After evaluating a query found in the main module's go.mod file,
2755// the go command updates the file to replace the query with its result.)
2756//
2757// A fully-specified semantic version, such as "v1.2.3",
2758// evaluates to that specific version.
2759//
2760// A semantic version prefix, such as "v1" or "v1.2",
2761// evaluates to the latest available tagged version with that prefix.
2762//
2763// A semantic version comparison, such as "<v1.2.3" or ">=v1.5.6",
2764// evaluates to the available tagged version nearest to the comparison target
2765// (the latest version for < and <=, the earliest version for > and >=).
2766//
2767// The string "latest" matches the latest available tagged version,
2768// or else the underlying source repository's latest untagged revision.
2769//
2770// The string "upgrade" is like "latest", but if the module is
2771// currently required at a later version than the version "latest"
2772// would select (for example, a newer pre-release version), "upgrade"
2773// will select the later version instead.
2774//
2775// The string "patch" matches the latest available tagged version
2776// of a module with the same major and minor version numbers as the
2777// currently required version. If no version is currently required,
2778// "patch" is equivalent to "latest".
2779//
2780// A revision identifier for the underlying source repository, such as
2781// a commit hash prefix, revision tag, or branch name, selects that
2782// specific code revision. If the revision is also tagged with a
2783// semantic version, the query evaluates to that semantic version.
2784// Otherwise the query evaluates to a pseudo-version for the commit.
2785// Note that branches and tags with names that are matched by other
2786// query syntax cannot be selected this way. For example, the query
2787// "v2" means the latest version starting with "v2", not the branch
2788// named "v2".
2789//
2790// All queries prefer release versions to pre-release versions.
2791// For example, "<v1.2.3" will prefer to return "v1.2.2"
2792// instead of "v1.2.3-pre1", even though "v1.2.3-pre1" is nearer
2793// to the comparison target.
2794//
2795// Module versions disallowed by exclude statements in the
2796// main module's go.mod are considered unavailable and cannot
2797// be returned by queries.
2798//
2799// For example, these commands are all valid:
2800//
2801// go get github.com/gorilla/mux@latest # same (@latest is default for 'go get')
2802// go get github.com/gorilla/mux@v1.6.2 # records v1.6.2
2803// go get github.com/gorilla/mux@e3702bed2 # records v1.6.2
2804// go get github.com/gorilla/mux@c856192 # records v0.0.0-20180517173623-c85619274f5d
2805// go get github.com/gorilla/mux@master # records current meaning of master
2806//
2807// Module compatibility and semantic versioning
2808//
2809// The go command requires that modules use semantic versions and expects that
2810// the versions accurately describe compatibility: it assumes that v1.5.4 is a
2811// backwards-compatible replacement for v1.5.3, v1.4.0, and even v1.0.0.
2812// More generally the go command expects that packages follow the
2813// "import compatibility rule", which says:
2814//
2815// "If an old package and a new package have the same import path,
2816// the new package must be backwards compatible with the old package."
2817//
2818// Because the go command assumes the import compatibility rule,
2819// a module definition can only set the minimum required version of one
2820// of its dependencies: it cannot set a maximum or exclude selected versions.
2821// Still, the import compatibility rule is not a guarantee: it may be that
2822// v1.5.4 is buggy and not a backwards-compatible replacement for v1.5.3.
2823// Because of this, the go command never updates from an older version
2824// to a newer version of a module unasked.
2825//
2826// In semantic versioning, changing the major version number indicates a lack
2827// of backwards compatibility with earlier versions. To preserve import
2828// compatibility, the go command requires that modules with major version v2
2829// or later use a module path with that major version as the final element.
2830// For example, version v2.0.0 of example.com/m must instead use module path
2831// example.com/m/v2, and packages in that module would use that path as
2832// their import path prefix, as in example.com/m/v2/sub/pkg. Including the
2833// major version number in the module path and import paths in this way is
2834// called "semantic import versioning". Pseudo-versions for modules with major
2835// version v2 and later begin with that major version instead of v0, as in
2836// v2.0.0-20180326061214-4fc5987536ef.
2837//
2838// As a special case, module paths beginning with gopkg.in/ continue to use the
2839// conventions established on that system: the major version is always present,
2840// and it is preceded by a dot instead of a slash: gopkg.in/yaml.v1
2841// and gopkg.in/yaml.v2, not gopkg.in/yaml and gopkg.in/yaml/v2.
2842//
2843// The go command treats modules with different module paths as unrelated:
2844// it makes no connection between example.com/m and example.com/m/v2.
2845// Modules with different major versions can be used together in a build
2846// and are kept separate by the fact that their packages use different
2847// import paths.
2848//
2849// In semantic versioning, major version v0 is for initial development,
2850// indicating no expectations of stability or backwards compatibility.
2851// Major version v0 does not appear in the module path, because those
2852// versions are preparation for v1.0.0, and v1 does not appear in the
2853// module path either.
2854//
2855// Code written before the semantic import versioning convention
2856// was introduced may use major versions v2 and later to describe
2857// the same set of unversioned import paths as used in v0 and v1.
2858// To accommodate such code, if a source code repository has a
2859// v2.0.0 or later tag for a file tree with no go.mod, the version is
2860// considered to be part of the v1 module's available versions
2861// and is given an +incompatible suffix when converted to a module
2862// version, as in v2.0.0+incompatible. The +incompatible tag is also
2863// applied to pseudo-versions derived from such versions, as in
2864// v2.0.1-0.yyyymmddhhmmss-abcdefabcdef+incompatible.
2865//
2866// In general, having a dependency in the build list (as reported by 'go list -m all')
2867// on a v0 version, pre-release version, pseudo-version, or +incompatible version
2868// is an indication that problems are more likely when upgrading that
2869// dependency, since there is no expectation of compatibility for those.
2870//
2871// See https://research.swtch.com/vgo-import for more information about
2872// semantic import versioning, and see https://semver.org/ for more about
2873// semantic versioning.
2874//
2875// Module code layout
2876//
2877// For now, see https://research.swtch.com/vgo-module for information
2878// about how source code in version control systems is mapped to
2879// module file trees.
2880//
2881// Module downloading and verification
2882//
2883// The go command can fetch modules from a proxy or connect to source control
2884// servers directly, according to the setting of the GOPROXY environment
2885// variable (see 'go help env'). The default setting for GOPROXY is
2886// "https://proxy.golang.org,direct", which means to try the
2887// Go module mirror run by Google and fall back to a direct connection
2888// if the proxy reports that it does not have the module (HTTP error 404 or 410).
2889// See https://proxy.golang.org/privacy for the service's privacy policy.
2890//
2891// If GOPROXY is set to the string "direct", downloads use a direct connection to
2892// source control servers. Setting GOPROXY to "off" disallows downloading modules
2893// from any source. Otherwise, GOPROXY is expected to be list of module proxy URLs
2894// separated by either comma (,) or pipe (|) characters, which control error
2895// fallback behavior. For each request, the go command tries each proxy in
2896// sequence. If there is an error, the go command will try the next proxy in the
2897// list if the error is a 404 or 410 HTTP response or if the current proxy is
2898// followed by a pipe character, indicating it is safe to fall back on any error.
2899//
2900// The GOPRIVATE and GONOPROXY environment variables allow bypassing
2901// the proxy for selected modules. See 'go help private' for details.
2902//
2903// No matter the source of the modules, the go command checks downloads against
2904// known checksums, to detect unexpected changes in the content of any specific
2905// module version from one day to the next. This check first consults the current
2906// module's go.sum file but falls back to the Go checksum database, controlled by
2907// the GOSUMDB and GONOSUMDB environment variables. See 'go help module-auth'
2908// for details.
2909//
2910// See 'go help goproxy' for details about the proxy protocol and also
2911// the format of the cached downloaded packages.
2912//
2913// Modules and vendoring
2914//
2915// When using modules, the go command typically satisfies dependencies by
2916// downloading modules from their sources and using those downloaded copies
2917// (after verification, as described in the previous section). Vendoring may
2918// be used to allow interoperation with older versions of Go, or to ensure
2919// that all files used for a build are stored together in a single file tree.
2920//
2921// The command 'go mod vendor' constructs a directory named vendor in the main
2922// module's root directory that contains copies of all packages needed to support
2923// builds and tests of packages in the main module. 'go mod vendor' also
2924// creates the file vendor/modules.txt that contains metadata about vendored
2925// packages and module versions. This file should be kept consistent with go.mod:
2926// when vendoring is used, 'go mod vendor' should be run after go.mod is updated.
2927//
2928// If the vendor directory is present in the main module's root directory, it will
2929// be used automatically if the "go" version in the main module's go.mod file is
2930// 1.14 or higher. Build commands like 'go build' and 'go test' will load packages
2931// from the vendor directory instead of accessing the network or the local module
2932// cache. To explicitly enable vendoring, invoke the go command with the flag
2933// -mod=vendor. To disable vendoring, use the flag -mod=mod.
2934//
2935// Unlike vendoring in GOPATH, the go command ignores vendor directories in
2936// locations other than the main module's root directory.
2937// 2412//
2938// 2413//
2939// Module authentication using go.sum 2414// Module authentication using go.sum
2940// 2415//
2941// The go command tries to authenticate every downloaded module, 2416// When the go command downloads a module zip file or go.mod file into the
2942// checking that the bits downloaded for a specific module version today 2417// module cache, it computes a cryptographic hash and compares it with a known
2943// match bits downloaded yesterday. This ensures repeatable builds 2418// value to verify the file hasn't changed since it was first downloaded. Known
2944// and detects introduction of unexpected changes, malicious or not. 2419// hashes are stored in a file in the module root directory named go.sum. Hashes
2945// 2420// may also be downloaded from the checksum database depending on the values of
2946// In each module's root, alongside go.mod, the go command maintains 2421// GOSUMDB, GOPRIVATE, and GONOSUMDB.
2947// a file named go.sum containing the cryptographic checksums of the
2948// module's dependencies.
2949//
2950// The form of each line in go.sum is three fields:
2951//
2952// <module> <version>[/go.mod] <hash>
2953//
2954// Each known module version results in two lines in the go.sum file.
2955// The first line gives the hash of the module version's file tree.
2956// The second line appends "/go.mod" to the version and gives the hash
2957// of only the module version's (possibly synthesized) go.mod file.
2958// The go.mod-only hash allows downloading and authenticating a
2959// module version's go.mod file, which is needed to compute the
2960// dependency graph, without also downloading all the module's source code.
2961//
2962// The hash begins with an algorithm prefix of the form "h<N>:".
2963// The only defined algorithm prefix is "h1:", which uses SHA-256.
2964//
2965// Module authentication failures
2966//
2967// The go command maintains a cache of downloaded packages and computes
2968// and records the cryptographic checksum of each package at download time.
2969// In normal operation, the go command checks the main module's go.sum file
2970// against these precomputed checksums instead of recomputing them on
2971// each command invocation. The 'go mod verify' command checks that
2972// the cached copies of module downloads still match both their recorded
2973// checksums and the entries in go.sum.
2974//
2975// In day-to-day development, the checksum of a given module version
2976// should never change. Each time a dependency is used by a given main
2977// module, the go command checks its local cached copy, freshly
2978// downloaded or not, against the main module's go.sum. If the checksums
2979// don't match, the go command reports the mismatch as a security error
2980// and refuses to run the build. When this happens, proceed with caution:
2981// code changing unexpectedly means today's build will not match
2982// yesterday's, and the unexpected change may not be beneficial.
2983//
2984// If the go command reports a mismatch in go.sum, the downloaded code
2985// for the reported module version does not match the one used in a
2986// previous build of the main module. It is important at that point
2987// to find out what the right checksum should be, to decide whether
2988// go.sum is wrong or the downloaded code is wrong. Usually go.sum is right:
2989// you want to use the same code you used yesterday.
2990//
2991// If a downloaded module is not yet included in go.sum and it is a publicly
2992// available module, the go command consults the Go checksum database to fetch
2993// the expected go.sum lines. If the downloaded code does not match those
2994// lines, the go command reports the mismatch and exits. Note that the
2995// database is not consulted for module versions already listed in go.sum.
2996//
2997// If a go.sum mismatch is reported, it is always worth investigating why
2998// the code downloaded today differs from what was downloaded yesterday.
2999//
3000// The GOSUMDB environment variable identifies the name of checksum database
3001// to use and optionally its public key and URL, as in:
3002//
3003// GOSUMDB="sum.golang.org"
3004// GOSUMDB="sum.golang.org+<publickey>"
3005// GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"
3006//
3007// The go command knows the public key of sum.golang.org, and also that the name
3008// sum.golang.google.cn (available inside mainland China) connects to the
3009// sum.golang.org checksum database; use of any other database requires giving
3010// the public key explicitly.
3011// The URL defaults to "https://" followed by the database name.
3012//
3013// GOSUMDB defaults to "sum.golang.org", the Go checksum database run by Google.
3014// See https://sum.golang.org/privacy for the service's privacy policy.
3015//
3016// If GOSUMDB is set to "off", or if "go get" is invoked with the -insecure flag,
3017// the checksum database is not consulted, and all unrecognized modules are
3018// accepted, at the cost of giving up the security guarantee of verified repeatable
3019// downloads for all modules. A better way to bypass the checksum database
3020// for specific modules is to use the GOPRIVATE or GONOSUMDB environment
3021// variables. See 'go help private' for details.
3022// 2422//
3023// The 'go env -w' command (see 'go help env') can be used to set these variables 2423// For details, see https://golang.org/ref/mod#authenticating.
3024// for future go command invocations.
3025// 2424//
3026// 2425//
3027// Package lists and patterns 2426// Package lists and patterns
@@ -3116,8 +2515,8 @@
3116// These defaults work well for publicly available source code. 2515// These defaults work well for publicly available source code.
3117// 2516//
3118// The GOPRIVATE environment variable controls which modules the go command 2517// The GOPRIVATE environment variable controls which modules the go command
3119// considers to be private (not available publicly) and should therefore not use the 2518// considers to be private (not available publicly) and should therefore not use
3120// proxy or checksum database. The variable is a comma-separated list of 2519// the proxy or checksum database. The variable is a comma-separated list of
3121// glob patterns (in the syntax of Go's path.Match) of module path prefixes. 2520// glob patterns (in the syntax of Go's path.Match) of module path prefixes.
3122// For example, 2521// For example,
3123// 2522//
@@ -3127,10 +2526,6 @@
3127// matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private, 2526// matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private,
3128// and rsc.io/private/quux. 2527// and rsc.io/private/quux.
3129// 2528//
3130// The GOPRIVATE environment variable may be used by other tools as well to
3131// identify non-public modules. For example, an editor could use GOPRIVATE
3132// to decide whether to hyperlink a package import to a godoc.org page.
3133//
3134// For fine-grained control over module download and validation, the GONOPROXY 2529// For fine-grained control over module download and validation, the GONOPROXY
3135// and GONOSUMDB environment variables accept the same kind of glob list 2530// and GONOSUMDB environment variables accept the same kind of glob list
3136// and override GOPRIVATE for the specific decision of whether to use the proxy 2531// and override GOPRIVATE for the specific decision of whether to use the proxy
@@ -3143,12 +2538,6 @@
3143// GOPROXY=proxy.example.com 2538// GOPROXY=proxy.example.com
3144// GONOPROXY=none 2539// GONOPROXY=none
3145// 2540//
3146// This would tell the go command and other tools that modules beginning with
3147// a corp.example.com subdomain are private but that the company proxy should
3148// be used for downloading both public and private modules, because
3149// GONOPROXY has been set to a pattern that won't match any modules,
3150// overriding GOPRIVATE.
3151//
3152// The GOPRIVATE variable is also used to define the "public" and "private" 2541// The GOPRIVATE variable is also used to define the "public" and "private"
3153// patterns for the GOVCS variable; see 'go help vcs'. For that usage, 2542// patterns for the GOVCS variable; see 'go help vcs'. For that usage,
3154// GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths 2543// GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
@@ -3157,6 +2546,8 @@
3157// The 'go env -w' command (see 'go help env') can be used to set these variables 2546// The 'go env -w' command (see 'go help env') can be used to set these variables
3158// for future go command invocations. 2547// for future go command invocations.
3159// 2548//
2549// For more details, see https://golang.org/ref/mod#private-modules.
2550//
3160// 2551//
3161// Testing flags 2552// Testing flags
3162// 2553//
diff --git a/libgo/go/cmd/go/go_test.go b/libgo/go/cmd/go/go_test.go
index c472620db29..3ce32388d05 100644
--- a/libgo/go/cmd/go/go_test.go
+++ b/libgo/go/cmd/go/go_test.go
@@ -216,6 +216,7 @@ func TestMain(m *testing.M) {
216 } 216 }
217 // Don't let these environment variables confuse the test. 217 // Don't let these environment variables confuse the test.
218 os.Setenv("GOENV", "off") 218 os.Setenv("GOENV", "off")
219 os.Unsetenv("GOFLAGS")
219 os.Unsetenv("GOBIN") 220 os.Unsetenv("GOBIN")
220 os.Unsetenv("GOPATH") 221 os.Unsetenv("GOPATH")
221 os.Unsetenv("GIT_ALLOW_PROTOCOL") 222 os.Unsetenv("GIT_ALLOW_PROTOCOL")
@@ -2655,12 +2656,12 @@ func TestBadCommandLines(t *testing.T) {
2655 tg.tempFile("src/@x/x.go", "package x\n") 2656 tg.tempFile("src/@x/x.go", "package x\n")
2656 tg.setenv("GOPATH", tg.path(".")) 2657 tg.setenv("GOPATH", tg.path("."))
2657 tg.runFail("build", "@x") 2658 tg.runFail("build", "@x")
2658 tg.grepStderr("invalid input directory name \"@x\"|cannot use path@version syntax", "did not reject @x directory") 2659 tg.grepStderr("invalid input directory name \"@x\"|can only use path@version syntax with 'go get' and 'go install' in module-aware mode", "did not reject @x directory")
2659 2660
2660 tg.tempFile("src/@x/y/y.go", "package y\n") 2661 tg.tempFile("src/@x/y/y.go", "package y\n")
2661 tg.setenv("GOPATH", tg.path(".")) 2662 tg.setenv("GOPATH", tg.path("."))
2662 tg.runFail("build", "@x/y") 2663 tg.runFail("build", "@x/y")
2663 tg.grepStderr("invalid import path \"@x/y\"|cannot use path@version syntax", "did not reject @x/y import path") 2664 tg.grepStderr("invalid import path \"@x/y\"|can only use path@version syntax with 'go get' and 'go install' in module-aware mode", "did not reject @x/y import path")
2664 2665
2665 tg.tempFile("src/-x/x.go", "package x\n") 2666 tg.tempFile("src/-x/x.go", "package x\n")
2666 tg.setenv("GOPATH", tg.path(".")) 2667 tg.setenv("GOPATH", tg.path("."))
diff --git a/libgo/go/cmd/go/internal/base/base.go b/libgo/go/cmd/go/internal/base/base.go
index 004588c7320..954ce47a989 100644
--- a/libgo/go/cmd/go/internal/base/base.go
+++ b/libgo/go/cmd/go/internal/base/base.go
@@ -10,9 +10,9 @@ import (
10 "context" 10 "context"
11 "flag" 11 "flag"
12 "fmt" 12 "fmt"
13 exec "internal/execabs"
13 "log" 14 "log"
14 "os" 15 "os"
15 "os/exec"
16 "strings" 16 "strings"
17 "sync" 17 "sync"
18 18
diff --git a/libgo/go/cmd/go/internal/bug/bug.go b/libgo/go/cmd/go/internal/bug/bug.go
index 1085feaaee8..4aa08b4ff6e 100644
--- a/libgo/go/cmd/go/internal/bug/bug.go
+++ b/libgo/go/cmd/go/internal/bug/bug.go
@@ -9,10 +9,10 @@ import (
9 "bytes" 9 "bytes"
10 "context" 10 "context"
11 "fmt" 11 "fmt"
12 exec "internal/execabs"
12 "io" 13 "io"
13 urlpkg "net/url" 14 urlpkg "net/url"
14 "os" 15 "os"
15 "os/exec"
16 "path/filepath" 16 "path/filepath"
17 "regexp" 17 "regexp"
18 "runtime" 18 "runtime"
diff --git a/libgo/go/cmd/go/internal/fmtcmd/fmt.go b/libgo/go/cmd/go/internal/fmtcmd/fmt.go
index b0c1c59b40c..6b98f0ccd31 100644
--- a/libgo/go/cmd/go/internal/fmtcmd/fmt.go
+++ b/libgo/go/cmd/go/internal/fmtcmd/fmt.go
@@ -75,7 +75,8 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
75 } 75 }
76 if pkg.Error != nil { 76 if pkg.Error != nil {
77 var nogo *load.NoGoError 77 var nogo *load.NoGoError
78 if errors.As(pkg.Error, &nogo) && len(pkg.InternalAllGoFiles()) > 0 { 78 var embed *load.EmbedError
79 if (errors.As(pkg.Error, &nogo) || errors.As(pkg.Error, &embed)) && len(pkg.InternalAllGoFiles()) > 0 {
79 // Skip this error, as we will format 80 // Skip this error, as we will format
80 // all files regardless. 81 // all files regardless.
81 } else { 82 } else {
diff --git a/libgo/go/cmd/go/internal/generate/generate.go b/libgo/go/cmd/go/internal/generate/generate.go
index c7401948b8b..a48311d51b0 100644
--- a/libgo/go/cmd/go/internal/generate/generate.go
+++ b/libgo/go/cmd/go/internal/generate/generate.go
@@ -12,10 +12,10 @@ import (
12 "fmt" 12 "fmt"
13 "go/parser" 13 "go/parser"
14 "go/token" 14 "go/token"
15 exec "internal/execabs"
15 "io" 16 "io"
16 "log" 17 "log"
17 "os" 18 "os"
18 "os/exec"
19 "path/filepath" 19 "path/filepath"
20 "regexp" 20 "regexp"
21 "strconv" 21 "strconv"
@@ -52,15 +52,6 @@ that can be run locally. It must either be in the shell path
52(gofmt), a fully qualified path (/usr/you/bin/mytool), or a 52(gofmt), a fully qualified path (/usr/you/bin/mytool), or a
53command alias, described below. 53command alias, described below.
54 54
55To convey to humans and machine tools that code is generated,
56generated source should have a line that matches the following
57regular expression (in Go syntax):
58
59 ^// Code generated .* DO NOT EDIT\.$
60
61The line may appear anywhere in the file, but is typically
62placed near the beginning so it is easy to find.
63
64Note that go generate does not parse the file, so lines that look 55Note that go generate does not parse the file, so lines that look
65like directives in comments or multiline strings will be treated 56like directives in comments or multiline strings will be treated
66as directives. 57as directives.
@@ -72,6 +63,15 @@ arguments when it is run.
72Quoted strings use Go syntax and are evaluated before execution; a 63Quoted strings use Go syntax and are evaluated before execution; a
73quoted string appears as a single argument to the generator. 64quoted string appears as a single argument to the generator.
74 65
66To convey to humans and machine tools that code is generated,
67generated source should have a line that matches the following
68regular expression (in Go syntax):
69
70 ^// Code generated .* DO NOT EDIT\.$
71
72This line must appear before the first non-comment, non-blank
73text in the file.
74
75Go generate sets several variables when it runs the generator: 75Go generate sets several variables when it runs the generator:
76 76
77 $GOARCH 77 $GOARCH
diff --git a/libgo/go/cmd/go/internal/get/get.go b/libgo/go/cmd/go/internal/get/get.go
index 94a42c4f73a..38ff3823f22 100644
--- a/libgo/go/cmd/go/internal/get/get.go
+++ b/libgo/go/cmd/go/internal/get/get.go
@@ -202,7 +202,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
202func downloadPaths(patterns []string) []string { 202func downloadPaths(patterns []string) []string {
203 for _, arg := range patterns { 203 for _, arg := range patterns {
204 if strings.Contains(arg, "@") { 204 if strings.Contains(arg, "@") {
205 base.Fatalf("go: cannot use path@version syntax in GOPATH mode") 205 base.Fatalf("go: can only use path@version syntax with 'go get' and 'go install' in module-aware mode")
206 continue 206 continue
207 } 207 }
208 208
diff --git a/libgo/go/cmd/go/internal/help/helpdoc.go b/libgo/go/cmd/go/internal/help/helpdoc.go
index 98f58441b4d..e07ad0e1db1 100644
--- a/libgo/go/cmd/go/internal/help/helpdoc.go
+++ b/libgo/go/cmd/go/internal/help/helpdoc.go
@@ -266,7 +266,7 @@ listed in the GOPATH environment variable.
266(See 'go help gopath-get' and 'go help gopath'.) 266(See 'go help gopath-get' and 'go help gopath'.)
267 267
268When using modules, downloaded packages are stored in the module cache. 268When using modules, downloaded packages are stored in the module cache.
269(See 'go help module-get' and 'go help goproxy'.) 269See https://golang.org/ref/mod#module-cache.
270 270
271When using modules, an additional variant of the go-import meta tag is 271When using modules, an additional variant of the go-import meta tag is
272recognized and is preferred over those listing version control systems. 272recognized and is preferred over those listing version control systems.
@@ -276,7 +276,8 @@ That variant uses "mod" as the vcs in the content value, as in:
276 276
277This tag means to fetch modules with paths beginning with example.org 277This tag means to fetch modules with paths beginning with example.org
278from the module proxy available at the URL https://code.org/moduleproxy. 278from the module proxy available at the URL https://code.org/moduleproxy.
279See 'go help goproxy' for details about the proxy protocol. 279See https://golang.org/ref/mod#goproxy-protocol for details about the
280proxy protocol.
280 281
281Import path checking 282Import path checking
282 283
@@ -483,6 +484,10 @@ See 'go help env' for details.
483 484
484General-purpose environment variables: 485General-purpose environment variables:
485 486
487 GO111MODULE
488 Controls whether the go command runs in module-aware mode or GOPATH mode.
489 May be "off", "on", or "auto".
490 See https://golang.org/ref/mod#mod-commands.
486 GCCGO 491 GCCGO
487 The gccgo command to run for 'go build -compiler=gccgo'. 492 The gccgo command to run for 'go build -compiler=gccgo'.
488 GOARCH 493 GOARCH
@@ -521,20 +526,24 @@ General-purpose environment variables:
521 GOPATH 526 GOPATH
522 For more details see: 'go help gopath'. 527 For more details see: 'go help gopath'.
523 GOPROXY 528 GOPROXY
524 URL of Go module proxy. See 'go help modules'. 529 URL of Go module proxy. See https://golang.org/ref/mod#environment-variables
530 and https://golang.org/ref/mod#module-proxy for details.
525 GOPRIVATE, GONOPROXY, GONOSUMDB 531 GOPRIVATE, GONOPROXY, GONOSUMDB
526 Comma-separated list of glob patterns (in the syntax of Go's path.Match) 532 Comma-separated list of glob patterns (in the syntax of Go's path.Match)
527 of module path prefixes that should always be fetched directly 533 of module path prefixes that should always be fetched directly
528 or that should not be compared against the checksum database. 534 or that should not be compared against the checksum database.
529 See 'go help private'. 535 See https://golang.org/ref/mod#private-modules.
530 GOROOT 536 GOROOT
531 The root of the go tree. 537 The root of the go tree.
532 GOSUMDB 538 GOSUMDB
533 The name of checksum database to use and optionally its public key and 539 The name of checksum database to use and optionally its public key and
534 URL. See 'go help module-auth'. 540 URL. See https://golang.org/ref/mod#authenticating.
535 GOTMPDIR 541 GOTMPDIR
536 The directory where the go command will write 542 The directory where the go command will write
537 temporary source files, packages, and binaries. 543 temporary source files, packages, and binaries.
544 GOVCS
545 Lists version control commands that may be used with matching servers.
546 See 'go help vcs'.
538 547
539Environment variables for use with cgo: 548Environment variables for use with cgo:
540 549
diff --git a/libgo/go/cmd/go/internal/list/list.go b/libgo/go/cmd/go/internal/list/list.go
index ce6f579c058..b4d82d9f8cc 100644
--- a/libgo/go/cmd/go/internal/list/list.go
+++ b/libgo/go/cmd/go/internal/list/list.go
@@ -89,6 +89,14 @@ to -f '{{.ImportPath}}'. The struct being passed to the template is:
89 TestGoFiles []string // _test.go files in package 89 TestGoFiles []string // _test.go files in package
90 XTestGoFiles []string // _test.go files outside package 90 XTestGoFiles []string // _test.go files outside package
91 91
92 // Embedded files
93 EmbedPatterns []string // //go:embed patterns
94 EmbedFiles []string // files matched by EmbedPatterns
95 TestEmbedPatterns []string // //go:embed patterns in TestGoFiles
96 TestEmbedFiles []string // files matched by TestEmbedPatterns
97 XTestEmbedPatterns []string // //go:embed patterns in XTestGoFiles
98 XTestEmbedFiles []string // files matched by XTestEmbedPatterns
99
92 // Cgo directives 100 // Cgo directives
93 CgoCFLAGS []string // cgo: flags for C compiler 101 CgoCFLAGS []string // cgo: flags for C compiler
94 CgoCPPFLAGS []string // cgo: flags for C preprocessor 102 CgoCPPFLAGS []string // cgo: flags for C preprocessor
@@ -300,7 +308,7 @@ For more about build flags, see 'go help build'.
300 308
301For more about specifying packages, see 'go help packages'. 309For more about specifying packages, see 'go help packages'.
302 310
303For more about modules, see 'go help modules'. 311For more about modules, see https://golang.org/ref/mod.
304 `, 312 `,
305} 313}
306 314
@@ -577,8 +585,6 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
577 // Show vendor-expanded paths in listing 585 // Show vendor-expanded paths in listing
578 p.TestImports = p.Resolve(p.TestImports) 586 p.TestImports = p.Resolve(p.TestImports)
579 p.XTestImports = p.Resolve(p.XTestImports) 587 p.XTestImports = p.Resolve(p.XTestImports)
580 p.TestEmbedFiles = p.ResolveEmbed(p.TestEmbedPatterns)
581 p.XTestEmbedFiles = p.ResolveEmbed(p.XTestEmbedPatterns)
582 p.DepOnly = !cmdline[p] 588 p.DepOnly = !cmdline[p]
583 589
584 if *listCompiled { 590 if *listCompiled {
diff --git a/libgo/go/cmd/go/internal/load/pkg.go b/libgo/go/cmd/go/internal/load/pkg.go
index b3679728f1f..8757d666fb2 100644
--- a/libgo/go/cmd/go/internal/load/pkg.go
+++ b/libgo/go/cmd/go/internal/load/pkg.go
@@ -96,7 +96,7 @@ type PackagePublic struct {
96 96
97 // Embedded files 97 // Embedded files
98 EmbedPatterns []string `json:",omitempty"` // //go:embed patterns 98 EmbedPatterns []string `json:",omitempty"` // //go:embed patterns
99 EmbedFiles []string `json:",omitempty"` // files and directories matched by EmbedPatterns 99 EmbedFiles []string `json:",omitempty"` // files matched by EmbedPatterns
100 100
101 // Cgo directives 101 // Cgo directives
102 CgoCFLAGS []string `json:",omitempty"` // cgo: flags for C compiler 102 CgoCFLAGS []string `json:",omitempty"` // cgo: flags for C compiler
@@ -122,11 +122,11 @@ type PackagePublic struct {
122 TestGoFiles []string `json:",omitempty"` // _test.go files in package 122 TestGoFiles []string `json:",omitempty"` // _test.go files in package
123 TestImports []string `json:",omitempty"` // imports from TestGoFiles 123 TestImports []string `json:",omitempty"` // imports from TestGoFiles
124 TestEmbedPatterns []string `json:",omitempty"` // //go:embed patterns 124 TestEmbedPatterns []string `json:",omitempty"` // //go:embed patterns
125 TestEmbedFiles []string `json:",omitempty"` // //files matched by EmbedPatterns 125 TestEmbedFiles []string `json:",omitempty"` // files matched by TestEmbedPatterns
126 XTestGoFiles []string `json:",omitempty"` // _test.go files outside package 126 XTestGoFiles []string `json:",omitempty"` // _test.go files outside package
127 XTestImports []string `json:",omitempty"` // imports from XTestGoFiles 127 XTestImports []string `json:",omitempty"` // imports from XTestGoFiles
128 XTestEmbedPatterns []string `json:",omitempty"` // //go:embed patterns 128 XTestEmbedPatterns []string `json:",omitempty"` // //go:embed patterns
129 XTestEmbedFiles []string `json:",omitempty"` // //files matched by EmbedPatterns 129 XTestEmbedFiles []string `json:",omitempty"` // files matched by XTestEmbedPatterns
130} 130}
131 131
132// AllFiles returns the names of all the files considered for the package. 132// AllFiles returns the names of all the files considered for the package.
@@ -304,7 +304,7 @@ func (p *Package) setLoadPackageDataError(err error, path string, stk *ImportSta
304 } 304 }
305 305
306 if path != stk.Top() { 306 if path != stk.Top() {
307 p = setErrorPos(p, importPos) 307 p.Error.setPos(importPos)
308 } 308 }
309} 309}
310 310
@@ -412,6 +412,9 @@ type PackageError struct {
412} 412}
413 413
414func (p *PackageError) Error() string { 414func (p *PackageError) Error() string {
415 // TODO(#43696): decide when to print the stack or the position based on
416 // the error type and whether the package is in the main module.
417 // Document the rationale.
415 if p.Pos != "" && (len(p.ImportStack) == 0 || !p.alwaysPrintStack) { 418 if p.Pos != "" && (len(p.ImportStack) == 0 || !p.alwaysPrintStack) {
416 // Omit import stack. The full path to the file where the error 419 // Omit import stack. The full path to the file where the error
417 // is the most important thing. 420 // is the most important thing.
@@ -447,6 +450,15 @@ func (p *PackageError) MarshalJSON() ([]byte, error) {
447 return json.Marshal(perr) 450 return json.Marshal(perr)
448} 451}
449 452
453func (p *PackageError) setPos(posList []token.Position) {
454 if len(posList) == 0 {
455 return
456 }
457 pos := posList[0]
458 pos.Filename = base.ShortPath(pos.Filename)
459 p.Pos = pos.String()
460}
461
450// ImportPathError is a type of error that prevents a package from being loaded 462// ImportPathError is a type of error that prevents a package from being loaded
451// for a given import path. When such a package is loaded, a *Package is 463// for a given import path. When such a package is loaded, a *Package is
452// returned with Err wrapping an ImportPathError: the error is attached to 464// returned with Err wrapping an ImportPathError: the error is attached to
@@ -695,17 +707,19 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
695 Err: ImportErrorf(path, "non-canonical import path %q: should be %q", path, pathpkg.Clean(path)), 707 Err: ImportErrorf(path, "non-canonical import path %q: should be %q", path, pathpkg.Clean(path)),
696 } 708 }
697 p.Incomplete = true 709 p.Incomplete = true
698 setErrorPos(p, importPos) 710 p.Error.setPos(importPos)
699 } 711 }
700 } 712 }
701 713
702 // Checked on every import because the rules depend on the code doing the importing. 714 // Checked on every import because the rules depend on the code doing the importing.
703 if perr := disallowInternal(srcDir, parent, parentPath, p, stk); perr != p { 715 if perr := disallowInternal(srcDir, parent, parentPath, p, stk); perr != p {
704 return setErrorPos(perr, importPos) 716 perr.Error.setPos(importPos)
717 return perr
705 } 718 }
706 if mode&ResolveImport != 0 { 719 if mode&ResolveImport != 0 {
707 if perr := disallowVendor(srcDir, path, parentPath, p, stk); perr != p { 720 if perr := disallowVendor(srcDir, path, parentPath, p, stk); perr != p {
708 return setErrorPos(perr, importPos) 721 perr.Error.setPos(importPos)
722 return perr
709 } 723 }
710 } 724 }
711 725
@@ -715,7 +729,8 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
715 ImportStack: stk.Copy(), 729 ImportStack: stk.Copy(),
716 Err: ImportErrorf(path, "import %q is a program, not an importable package", path), 730 Err: ImportErrorf(path, "import %q is a program, not an importable package", path),
717 } 731 }
718 return setErrorPos(&perr, importPos) 732 perr.Error.setPos(importPos)
733 return &perr
719 } 734 }
720 735
721 if p.Internal.Local && parent != nil && !parent.Internal.Local { 736 if p.Internal.Local && parent != nil && !parent.Internal.Local {
@@ -730,21 +745,13 @@ func loadImport(ctx context.Context, pre *preload, path, srcDir string, parent *
730 ImportStack: stk.Copy(), 745 ImportStack: stk.Copy(),
731 Err: err, 746 Err: err,
732 } 747 }
733 return setErrorPos(&perr, importPos) 748 perr.Error.setPos(importPos)
749 return &perr
734 } 750 }
735 751
736 return p 752 return p
737} 753}
738 754
739func setErrorPos(p *Package, importPos []token.Position) *Package {
740 if len(importPos) > 0 {
741 pos := importPos[0]
742 pos.Filename = base.ShortPath(pos.Filename)
743 p.Error.Pos = pos.String()
744 }
745 return p
746}
747
748// loadPackageData loads information needed to construct a *Package. The result 755// loadPackageData loads information needed to construct a *Package. The result
749// is cached, and later calls to loadPackageData for the same package will return 756// is cached, and later calls to loadPackageData for the same package will return
750// the same data. 757// the same data.
@@ -769,11 +776,7 @@ func loadPackageData(path, parentPath, parentDir, parentRoot string, parentIsStd
769 } 776 }
770 777
771 if strings.Contains(path, "@") { 778 if strings.Contains(path, "@") {
772 if cfg.ModulesEnabled { 779 return nil, false, errors.New("can only use path@version syntax with 'go get' and 'go install' in module-aware mode")
773 return nil, false, errors.New("can only use path@version syntax with 'go get'")
774 } else {
775 return nil, false, errors.New("cannot use path@version syntax in GOPATH mode")
776 }
777 } 780 }
778 781
779 // Determine canonical package path and directory. 782 // Determine canonical package path and directory.
@@ -1659,7 +1662,7 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
1659 // must be either in an explicit command-line argument, 1662 // must be either in an explicit command-line argument,
1660 // or on the importer side (indicated by a non-empty importPos). 1663 // or on the importer side (indicated by a non-empty importPos).
1661 if path != stk.Top() && len(importPos) > 0 { 1664 if path != stk.Top() && len(importPos) > 0 {
1662 p = setErrorPos(p, importPos) 1665 p.Error.setPos(importPos)
1663 } 1666 }
1664 } 1667 }
1665 } 1668 }
@@ -1669,11 +1672,6 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
1669 p.setLoadPackageDataError(err, path, stk, importPos) 1672 p.setLoadPackageDataError(err, path, stk, importPos)
1670 } 1673 }
1671 1674
1672 p.EmbedFiles, p.Internal.Embed, err = p.resolveEmbed(p.EmbedPatterns)
1673 if err != nil {
1674 setError(err)
1675 }
1676
1677 useBindir := p.Name == "main" 1675 useBindir := p.Name == "main"
1678 if !p.Standard { 1676 if !p.Standard {
1679 switch cfg.BuildBuildmode { 1677 switch cfg.BuildBuildmode {
@@ -1809,9 +1807,20 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
1809 return 1807 return
1810 } 1808 }
1811 1809
1810 // Errors after this point are caused by this package, not the importing
1811 // package. Pushing the path here prevents us from reporting the error
1812 // with the position of the import declaration.
1812 stk.Push(path) 1813 stk.Push(path)
1813 defer stk.Pop() 1814 defer stk.Pop()
1814 1815
1816 p.EmbedFiles, p.Internal.Embed, err = resolveEmbed(p.Dir, p.EmbedPatterns)
1817 if err != nil {
1818 p.Incomplete = true
1819 setError(err)
1820 embedErr := err.(*EmbedError)
1821 p.Error.setPos(p.Internal.Build.EmbedPatternPos[embedErr.Pattern])
1822 }
1823
1815 // Check for case-insensitive collision of input files. 1824 // Check for case-insensitive collision of input files.
1816 // To avoid problems on case-insensitive files, we reject any package 1825 // To avoid problems on case-insensitive files, we reject any package
1817 // where two different input files have equal names under a case-insensitive 1826 // where two different input files have equal names under a case-insensitive
@@ -1915,35 +1924,62 @@ func (p *Package) load(ctx context.Context, path string, stk *ImportStack, impor
1915 } 1924 }
1916} 1925}
1917 1926
1927// An EmbedError indicates a problem with a go:embed directive.
1928type EmbedError struct {
1929 Pattern string
1930 Err error
1931}
1932
1933func (e *EmbedError) Error() string {
1934 return fmt.Sprintf("pattern %s: %v", e.Pattern, e.Err)
1935}
1936
1937func (e *EmbedError) Unwrap() error {
1938 return e.Err
1939}
1940
1918// ResolveEmbed resolves //go:embed patterns and returns only the file list. 1941// ResolveEmbed resolves //go:embed patterns and returns only the file list.
1919// For use by go list to compute p.TestEmbedFiles and p.XTestEmbedFiles. 1942// For use by go mod vendor to find embedded files it should copy into the
1920func (p *Package) ResolveEmbed(patterns []string) []string { 1943// vendor directory.
1921 files, _, _ := p.resolveEmbed(patterns) 1944// TODO(#42504): Once go mod vendor uses load.PackagesAndErrors, just
1922 return files 1945// call (*Package).ResolveEmbed
1946func ResolveEmbed(dir string, patterns []string) ([]string, error) {
1947 files, _, err := resolveEmbed(dir, patterns)
1948 return files, err
1923} 1949}
1924 1950
1925// resolveEmbed resolves //go:embed patterns to precise file lists. 1951// resolveEmbed resolves //go:embed patterns to precise file lists.
1926// It sets files to the list of unique files matched (for go list), 1952// It sets files to the list of unique files matched (for go list),
1927// and it sets pmap to the more precise mapping from 1953// and it sets pmap to the more precise mapping from
1928// patterns to files. 1954// patterns to files.
1929// TODO(rsc): All these messages need position information for better error reports. 1955func resolveEmbed(pkgdir string, patterns []string) (files []string, pmap map[string][]string, err error) {
1930func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[string][]string, err error) { 1956 var pattern string
1957 defer func() {
1958 if err != nil {
1959 err = &EmbedError{
1960 Pattern: pattern,
1961 Err: err,
1962 }
1963 }
1964 }()
1965
1966 // TODO(rsc): All these messages need position information for better error reports.
1931 pmap = make(map[string][]string) 1967 pmap = make(map[string][]string)
1932 have := make(map[string]int) 1968 have := make(map[string]int)
1933 dirOK := make(map[string]bool) 1969 dirOK := make(map[string]bool)
1934 pid := 0 // pattern ID, to allow reuse of have map 1970 pid := 0 // pattern ID, to allow reuse of have map
1935 for _, pattern := range patterns { 1971 for _, pattern = range patterns {
1936 pid++ 1972 pid++
1937 1973
1938 // Check pattern is valid for //go:embed. 1974 // Check pattern is valid for //go:embed.
1939 if _, err := path.Match(pattern, ""); err != nil || !validEmbedPattern(pattern) { 1975 if _, err := path.Match(pattern, ""); err != nil || !validEmbedPattern(pattern) {
1940 return nil, nil, fmt.Errorf("pattern %s: invalid pattern syntax", pattern) 1976 return nil, nil, fmt.Errorf("invalid pattern syntax")
1941 } 1977 }
1942 1978
1943 // Glob to find matches. 1979 // Glob to find matches.
1944 match, err := fsys.Glob(p.Dir + string(filepath.Separator) + filepath.FromSlash(pattern)) 1980 match, err := fsys.Glob(pkgdir + string(filepath.Separator) + filepath.FromSlash(pattern))
1945 if err != nil { 1981 if err != nil {
1946 return nil, nil, fmt.Errorf("pattern %s: %v", pattern, err) 1982 return nil, nil, err
1947 } 1983 }
1948 1984
1949 // Filter list of matches down to the ones that will still exist when 1985 // Filter list of matches down to the ones that will still exist when
@@ -1952,7 +1988,7 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
1952 // then there may be other things lying around, like symbolic links or .git directories.) 1988 // then there may be other things lying around, like symbolic links or .git directories.)
1953 var list []string 1989 var list []string
1954 for _, file := range match { 1990 for _, file := range match {
1955 rel := filepath.ToSlash(file[len(p.Dir)+1:]) // file, relative to p.Dir 1991 rel := filepath.ToSlash(file[len(pkgdir)+1:]) // file, relative to p.Dir
1956 1992
1957 what := "file" 1993 what := "file"
1958 info, err := fsys.Lstat(file) 1994 info, err := fsys.Lstat(file)
@@ -1965,28 +2001,28 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
1965 2001
1966 // Check that directories along path do not begin a new module 2002 // Check that directories along path do not begin a new module
1967 // (do not contain a go.mod). 2003 // (do not contain a go.mod).
1968 for dir := file; len(dir) > len(p.Dir)+1 && !dirOK[dir]; dir = filepath.Dir(dir) { 2004 for dir := file; len(dir) > len(pkgdir)+1 && !dirOK[dir]; dir = filepath.Dir(dir) {
1969 if _, err := fsys.Stat(filepath.Join(dir, "go.mod")); err == nil { 2005 if _, err := fsys.Stat(filepath.Join(dir, "go.mod")); err == nil {
1970 return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: in different module", pattern, what, rel) 2006 return nil, nil, fmt.Errorf("cannot embed %s %s: in different module", what, rel)
1971 } 2007 }
1972 if dir != file { 2008 if dir != file {
1973 if info, err := fsys.Lstat(dir); err == nil && !info.IsDir() { 2009 if info, err := fsys.Lstat(dir); err == nil && !info.IsDir() {
1974 return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: in non-directory %s", pattern, what, rel, dir[len(p.Dir)+1:]) 2010 return nil, nil, fmt.Errorf("cannot embed %s %s: in non-directory %s", what, rel, dir[len(pkgdir)+1:])
1975 } 2011 }
1976 } 2012 }
1977 dirOK[dir] = true 2013 dirOK[dir] = true
1978 if elem := filepath.Base(dir); isBadEmbedName(elem) { 2014 if elem := filepath.Base(dir); isBadEmbedName(elem) {
1979 if dir == file { 2015 if dir == file {
1980 return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: invalid name %s", pattern, what, rel, elem) 2016 return nil, nil, fmt.Errorf("cannot embed %s %s: invalid name %s", what, rel, elem)
1981 } else { 2017 } else {
1982 return nil, nil, fmt.Errorf("pattern %s: cannot embed %s %s: in invalid directory %s", pattern, what, rel, elem) 2018 return nil, nil, fmt.Errorf("cannot embed %s %s: in invalid directory %s", what, rel, elem)
1983 } 2019 }
1984 } 2020 }
1985 } 2021 }
1986 2022
1987 switch { 2023 switch {
1988 default: 2024 default:
1989 return nil, nil, fmt.Errorf("pattern %s: cannot embed irregular file %s", pattern, rel) 2025 return nil, nil, fmt.Errorf("cannot embed irregular file %s", rel)
1990 2026
1991 case info.Mode().IsRegular(): 2027 case info.Mode().IsRegular():
1992 if have[rel] != pid { 2028 if have[rel] != pid {
@@ -2002,7 +2038,7 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
2002 if err != nil { 2038 if err != nil {
2003 return err 2039 return err
2004 } 2040 }
2005 rel := filepath.ToSlash(path[len(p.Dir)+1:]) 2041 rel := filepath.ToSlash(path[len(pkgdir)+1:])
2006 name := info.Name() 2042 name := info.Name()
2007 if path != file && (isBadEmbedName(name) || name[0] == '.' || name[0] == '_') { 2043 if path != file && (isBadEmbedName(name) || name[0] == '.' || name[0] == '_') {
2008 // Ignore bad names, assuming they won't go into modules. 2044 // Ignore bad names, assuming they won't go into modules.
@@ -2033,13 +2069,13 @@ func (p *Package) resolveEmbed(patterns []string) (files []string, pmap map[stri
2033 return nil, nil, err 2069 return nil, nil, err
2034 } 2070 }
2035 if count == 0 { 2071 if count == 0 {
2036 return nil, nil, fmt.Errorf("pattern %s: cannot embed directory %s: contains no embeddable files", pattern, rel) 2072 return nil, nil, fmt.Errorf("cannot embed directory %s: contains no embeddable files", rel)
2037 } 2073 }
2038 } 2074 }
2039 } 2075 }
2040 2076
2041 if len(list) == 0 { 2077 if len(list) == 0 {
2042 return nil, nil, fmt.Errorf("pattern %s: no matching files found", pattern) 2078 return nil, nil, fmt.Errorf("no matching files found")
2043 } 2079 }
2044 sort.Strings(list) 2080 sort.Strings(list)
2045 pmap[pattern] = list 2081 pmap[pattern] = list
diff --git a/libgo/go/cmd/go/internal/load/test.go b/libgo/go/cmd/go/internal/load/test.go
index d884361aaad..eb8aef3ee28 100644
--- a/libgo/go/cmd/go/internal/load/test.go
+++ b/libgo/go/cmd/go/internal/load/test.go
@@ -124,12 +124,14 @@ func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (p
124 imports = append(imports, p1) 124 imports = append(imports, p1)
125 } 125 }
126 var err error 126 var err error
127 p.TestEmbedFiles, testEmbed, err = p.resolveEmbed(p.TestEmbedPatterns) 127 p.TestEmbedFiles, testEmbed, err = resolveEmbed(p.Dir, p.TestEmbedPatterns)
128 if err != nil && ptestErr == nil { 128 if err != nil && ptestErr == nil {
129 ptestErr = &PackageError{ 129 ptestErr = &PackageError{
130 ImportStack: stk.Copy(), 130 ImportStack: stk.Copy(),
131 Err: err, 131 Err: err,
132 } 132 }
133 embedErr := err.(*EmbedError)
134 ptestErr.setPos(p.Internal.Build.TestEmbedPatternPos[embedErr.Pattern])
133 } 135 }
134 stk.Pop() 136 stk.Pop()
135 137
@@ -145,12 +147,14 @@ func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (p
145 } 147 }
146 p.XTestImports[i] = p1.ImportPath 148 p.XTestImports[i] = p1.ImportPath
147 } 149 }
148 p.XTestEmbedFiles, xtestEmbed, err = p.resolveEmbed(p.XTestEmbedPatterns) 150 p.XTestEmbedFiles, xtestEmbed, err = resolveEmbed(p.Dir, p.XTestEmbedPatterns)
149 if err != nil && pxtestErr == nil { 151 if err != nil && pxtestErr == nil {
150 pxtestErr = &PackageError{ 152 pxtestErr = &PackageError{
151 ImportStack: stk.Copy(), 153 ImportStack: stk.Copy(),
152 Err: err, 154 Err: err,
153 } 155 }
156 embedErr := err.(*EmbedError)
157 pxtestErr.setPos(p.Internal.Build.XTestEmbedPatternPos[embedErr.Pattern])
154 } 158 }
155 stk.Pop() 159 stk.Pop()
156 160
diff --git a/libgo/go/cmd/go/internal/modcmd/download.go b/libgo/go/cmd/go/internal/modcmd/download.go
index ef1ad780c81..e7d3d869cbc 100644
--- a/libgo/go/cmd/go/internal/modcmd/download.go
+++ b/libgo/go/cmd/go/internal/modcmd/download.go
@@ -52,7 +52,9 @@ corresponding to this Go struct:
52 52
53The -x flag causes download to print the commands download executes. 53The -x flag causes download to print the commands download executes.
54 54
55See 'go help modules' for more about module queries. 55See https://golang.org/ref/mod#go-mod-download for more about 'go mod download'.
56
57See https://golang.org/ref/mod#version-queries for more about version queries.
56 `, 58 `,
57} 59}
58 60
diff --git a/libgo/go/cmd/go/internal/modcmd/edit.go b/libgo/go/cmd/go/internal/modcmd/edit.go
index b203a8a2b0a..1df104eb1dd 100644
--- a/libgo/go/cmd/go/internal/modcmd/edit.go
+++ b/libgo/go/cmd/go/internal/modcmd/edit.go
@@ -95,6 +95,7 @@ writing it back to go.mod. The JSON output corresponds to these Go types:
95 Require []Require 95 Require []Require
96 Exclude []Module 96 Exclude []Module
97 Replace []Replace 97 Replace []Replace
98 Retract []Retract
98 } 99 }
99 100
100 type Require struct { 101 type Require struct {
@@ -121,9 +122,7 @@ Note that this only describes the go.mod file itself, not other modules
121referred to indirectly. For the full set of modules available to a build, 122referred to indirectly. For the full set of modules available to a build,
122use 'go list -m -json all'. 123use 'go list -m -json all'.
123 124
124For example, a tool can obtain the go.mod as a data structure by 125See https://golang.org/ref/mod#go-mod-edit for more about 'go mod edit'.
125parsing the output of 'go mod edit -json' and can then make changes
126by invoking 'go mod edit' with -require, -exclude, and so on.
127 `, 126 `,
128} 127}
129 128
diff --git a/libgo/go/cmd/go/internal/modcmd/graph.go b/libgo/go/cmd/go/internal/modcmd/graph.go
index 3277548c235..a88e9ef4557 100644
--- a/libgo/go/cmd/go/internal/modcmd/graph.go
+++ b/libgo/go/cmd/go/internal/modcmd/graph.go
@@ -26,6 +26,8 @@ Graph prints the module requirement graph (with replacements applied)
26in text form. Each line in the output has two space-separated fields: a module 26in text form. Each line in the output has two space-separated fields: a module
27and one of its requirements. Each module is identified as a string of the form 27and one of its requirements. Each module is identified as a string of the form
28path@version, except for the main module, which has no @version suffix. 28path@version, except for the main module, which has no @version suffix.
29
30See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'.
29 `, 31 `,
30 Run: runGraph, 32 Run: runGraph,
31} 33}
diff --git a/libgo/go/cmd/go/internal/modcmd/init.go b/libgo/go/cmd/go/internal/modcmd/init.go
index c081bb547d1..73cc282d814 100644
--- a/libgo/go/cmd/go/internal/modcmd/init.go
+++ b/libgo/go/cmd/go/internal/modcmd/init.go
@@ -27,6 +27,8 @@ Gopkg.lock), and the current directory (if in GOPATH).
27 27
28If a configuration file for a vendoring tool is present, init will attempt to 28If a configuration file for a vendoring tool is present, init will attempt to
29import module requirements from it. 29import module requirements from it.
30
31See https://golang.org/ref/mod#go-mod-init for more about 'go mod init'.
30`, 32`,
31 Run: runInit, 33 Run: runInit,
32} 34}
diff --git a/libgo/go/cmd/go/internal/modcmd/tidy.go b/libgo/go/cmd/go/internal/modcmd/tidy.go
index fb43e33ec58..3b83d87a8eb 100644
--- a/libgo/go/cmd/go/internal/modcmd/tidy.go
+++ b/libgo/go/cmd/go/internal/modcmd/tidy.go
@@ -29,6 +29,8 @@ to standard error.
29 29
30The -e flag causes tidy to attempt to proceed despite errors 30The -e flag causes tidy to attempt to proceed despite errors
31encountered while loading packages. 31encountered while loading packages.
32
33See https://golang.org/ref/mod#go-mod-tidy for more about 'go mod tidy'.
32 `, 34 `,
33 Run: runTidy, 35 Run: runTidy,
34} 36}
diff --git a/libgo/go/cmd/go/internal/modcmd/vendor.go b/libgo/go/cmd/go/internal/modcmd/vendor.go
index 1bbb57d353b..d3ed9e00e22 100644
--- a/libgo/go/cmd/go/internal/modcmd/vendor.go
+++ b/libgo/go/cmd/go/internal/modcmd/vendor.go
@@ -7,7 +7,9 @@ package modcmd
7import ( 7import (
8 "bytes" 8 "bytes"
9 "context" 9 "context"
10 "errors"
10 "fmt" 11 "fmt"
12 "go/build"
11 "io" 13 "io"
12 "io/fs" 14 "io/fs"
13 "os" 15 "os"
@@ -19,7 +21,9 @@ import (
19 "cmd/go/internal/cfg" 21 "cmd/go/internal/cfg"
20 "cmd/go/internal/fsys" 22 "cmd/go/internal/fsys"
21 "cmd/go/internal/imports" 23 "cmd/go/internal/imports"
24 "cmd/go/internal/load"
22 "cmd/go/internal/modload" 25 "cmd/go/internal/modload"
26 "cmd/go/internal/str"
23 27
24 "golang.org/x/mod/module" 28 "golang.org/x/mod/module"
25 "golang.org/x/mod/semver" 29 "golang.org/x/mod/semver"
@@ -38,6 +42,8 @@ modules and packages to standard error.
38 42
39The -e flag causes vendor to attempt to proceed despite errors 43The -e flag causes vendor to attempt to proceed despite errors
40encountered while loading packages. 44encountered while loading packages.
45
46See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
41 `, 47 `,
42 Run: runVendor, 48 Run: runVendor,
43} 49}
@@ -180,19 +186,76 @@ func moduleLine(m, r module.Version) string {
180} 186}
181 187
182func vendorPkg(vdir, pkg string) { 188func vendorPkg(vdir, pkg string) {
189 // TODO(#42504): Instead of calling modload.ImportMap then build.ImportDir,
190 // just call load.PackagesAndErrors. To do that, we need to add a good way
191 // to ignore build constraints.
183 realPath := modload.ImportMap(pkg) 192 realPath := modload.ImportMap(pkg)
184 if realPath != pkg && modload.ImportMap(realPath) != "" { 193 if realPath != pkg && modload.ImportMap(realPath) != "" {
185 fmt.Fprintf(os.Stderr, "warning: %s imported as both %s and %s; making two copies.\n", realPath, realPath, pkg) 194 fmt.Fprintf(os.Stderr, "warning: %s imported as both %s and %s; making two copies.\n", realPath, realPath, pkg)
186 } 195 }
187 196
197 copiedFiles := make(map[string]bool)
188 dst := filepath.Join(vdir, pkg) 198 dst := filepath.Join(vdir, pkg)
189 src := modload.PackageDir(realPath) 199 src := modload.PackageDir(realPath)
190 if src == "" { 200 if src == "" {
191 fmt.Fprintf(os.Stderr, "internal error: no pkg for %s -> %s\n", pkg, realPath) 201 fmt.Fprintf(os.Stderr, "internal error: no pkg for %s -> %s\n", pkg, realPath)
192 } 202 }
193 copyDir(dst, src, matchPotentialSourceFile) 203 copyDir(dst, src, matchPotentialSourceFile, copiedFiles)
194 if m := modload.PackageModule(realPath); m.Path != "" { 204 if m := modload.PackageModule(realPath); m.Path != "" {
195 copyMetadata(m.Path, realPath, dst, src) 205 copyMetadata(m.Path, realPath, dst, src, copiedFiles)
206 }
207
208 ctx := build.Default
209 ctx.UseAllFiles = true
210 bp, err := ctx.ImportDir(src, build.IgnoreVendor)
211 // Because UseAllFiles is set on the build.Context, it's possible ta get
212 // a MultiplePackageError on an otherwise valid package: the package could
213 // have different names for GOOS=windows and GOOS=mac for example. On the
214 // other hand if there's a NoGoError, the package might have source files
215 // specifying "// +build ignore" those packages should be skipped because
216 // embeds from ignored files can't be used.
217 // TODO(#42504): Find a better way to avoid errors from ImportDir. We'll
218 // need to figure this out when we switch to PackagesAndErrors as per the
219 // TODO above.
220 var multiplePackageError *build.MultiplePackageError
221 var noGoError *build.NoGoError
222 if err != nil {
223 if errors.As(err, &noGoError) {
224 return // No source files in this package are built. Skip embeds in ignored files.
225 } else if !errors.As(err, &multiplePackageError) { // multiplePackgeErrors are okay, but others are not.
226 base.Fatalf("internal error: failed to find embedded files of %s: %v\n", pkg, err)
227 }
228 }
229 embedPatterns := str.StringList(bp.EmbedPatterns, bp.TestEmbedPatterns, bp.XTestEmbedPatterns)
230 embeds, err := load.ResolveEmbed(bp.Dir, embedPatterns)
231 if err != nil {
232 base.Fatalf("go mod vendor: %v", err)
233 }
234 for _, embed := range embeds {
235 embedDst := filepath.Join(dst, embed)
236 if copiedFiles[embedDst] {
237 continue
238 }
239
240 // Copy the file as is done by copyDir below.
241 r, err := os.Open(filepath.Join(src, embed))
242 if err != nil {
243 base.Fatalf("go mod vendor: %v", err)
244 }
245 if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil {
246 base.Fatalf("go mod vendor: %v", err)
247 }
248 w, err := os.Create(embedDst)
249 if err != nil {
250 base.Fatalf("go mod vendor: %v", err)
251 }
252 if _, err := io.Copy(w, r); err != nil {
253 base.Fatalf("go mod vendor: %v", err)
254 }
255 r.Close()
256 if err := w.Close(); err != nil {
257 base.Fatalf("go mod vendor: %v", err)
258 }
196 } 259 }
197} 260}
198 261
@@ -205,14 +268,14 @@ var copiedMetadata = make(map[metakey]bool)
205 268
206// copyMetadata copies metadata files from parents of src to parents of dst, 269// copyMetadata copies metadata files from parents of src to parents of dst,
207// stopping after processing the src parent for modPath. 270// stopping after processing the src parent for modPath.
208func copyMetadata(modPath, pkg, dst, src string) { 271func copyMetadata(modPath, pkg, dst, src string, copiedFiles map[string]bool) {
209 for parent := 0; ; parent++ { 272 for parent := 0; ; parent++ {
210 if copiedMetadata[metakey{modPath, dst}] { 273 if copiedMetadata[metakey{modPath, dst}] {
211 break 274 break
212 } 275 }
213 copiedMetadata[metakey{modPath, dst}] = true 276 copiedMetadata[metakey{modPath, dst}] = true
214 if parent > 0 { 277 if parent > 0 {
215 copyDir(dst, src, matchMetadata) 278 copyDir(dst, src, matchMetadata, copiedFiles)
216 } 279 }
217 if modPath == pkg { 280 if modPath == pkg {
218 break 281 break
@@ -280,7 +343,7 @@ func matchPotentialSourceFile(dir string, info fs.DirEntry) bool {
280} 343}
281 344
282// copyDir copies all regular files satisfying match(info) from src to dst. 345// copyDir copies all regular files satisfying match(info) from src to dst.
283func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool) { 346func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool, copiedFiles map[string]bool) {
284 files, err := os.ReadDir(src) 347 files, err := os.ReadDir(src)
285 if err != nil { 348 if err != nil {
286 base.Fatalf("go mod vendor: %v", err) 349 base.Fatalf("go mod vendor: %v", err)
@@ -292,11 +355,14 @@ func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool) {
292 if file.IsDir() || !file.Type().IsRegular() || !match(src, file) { 355 if file.IsDir() || !file.Type().IsRegular() || !match(src, file) {
293 continue 356 continue
294 } 357 }
358 copiedFiles[file.Name()] = true
295 r, err := os.Open(filepath.Join(src, file.Name())) 359 r, err := os.Open(filepath.Join(src, file.Name()))
296 if err != nil { 360 if err != nil {
297 base.Fatalf("go mod vendor: %v", err) 361 base.Fatalf("go mod vendor: %v", err)
298 } 362 }
299 w, err := os.Create(filepath.Join(dst, file.Name())) 363 dstPath := filepath.Join(dst, file.Name())
364 copiedFiles[dstPath] = true
365 w, err := os.Create(dstPath)
300 if err != nil { 366 if err != nil {
301 base.Fatalf("go mod vendor: %v", err) 367 base.Fatalf("go mod vendor: %v", err)
302 } 368 }
diff --git a/libgo/go/cmd/go/internal/modcmd/verify.go b/libgo/go/cmd/go/internal/modcmd/verify.go
index c83e70076ae..83214291310 100644
--- a/libgo/go/cmd/go/internal/modcmd/verify.go
+++ b/libgo/go/cmd/go/internal/modcmd/verify.go
@@ -31,6 +31,8 @@ modified since being downloaded. If all the modules are unmodified,
31verify prints "all modules verified." Otherwise it reports which 31verify prints "all modules verified." Otherwise it reports which
32modules have been changed and causes 'go mod' to exit with a 32modules have been changed and causes 'go mod' to exit with a
33non-zero status. 33non-zero status.
34
35See https://golang.org/ref/mod#go-mod-verify for more about 'go mod verify'.
34 `, 36 `,
35 Run: runVerify, 37 Run: runVerify,
36} 38}
diff --git a/libgo/go/cmd/go/internal/modcmd/why.go b/libgo/go/cmd/go/internal/modcmd/why.go
index e287c880601..a5f3e8afcbe 100644
--- a/libgo/go/cmd/go/internal/modcmd/why.go
+++ b/libgo/go/cmd/go/internal/modcmd/why.go
@@ -48,6 +48,8 @@ For example:
48 # golang.org/x/text/encoding 48 # golang.org/x/text/encoding
49 (main module does not need package golang.org/x/text/encoding) 49 (main module does not need package golang.org/x/text/encoding)
50 $ 50 $
51
52See https://golang.org/ref/mod#go-mod-why for more about 'go mod why'.
51 `, 53 `,
52} 54}
53 55
diff --git a/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go b/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go
index 86c1c14d4a7..378fbae34f9 100644
--- a/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go
+++ b/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go
@@ -10,10 +10,10 @@ import (
10 "bytes" 10 "bytes"
11 "crypto/sha256" 11 "crypto/sha256"
12 "fmt" 12 "fmt"
13 exec "internal/execabs"
13 "io" 14 "io"
14 "io/fs" 15 "io/fs"
15 "os" 16 "os"
16 "os/exec"
17 "path/filepath" 17 "path/filepath"
18 "strings" 18 "strings"
19 "sync" 19 "sync"
diff --git a/libgo/go/cmd/go/internal/modfetch/codehost/git.go b/libgo/go/cmd/go/internal/modfetch/codehost/git.go
index 8abc039e7fc..72005e27d5e 100644
--- a/libgo/go/cmd/go/internal/modfetch/codehost/git.go
+++ b/libgo/go/cmd/go/internal/modfetch/codehost/git.go
@@ -8,11 +8,11 @@ import (
8 "bytes" 8 "bytes"
9 "errors" 9 "errors"
10 "fmt" 10 "fmt"
11 exec "internal/execabs"
11 "io" 12 "io"
12 "io/fs" 13 "io/fs"
13 "net/url" 14 "net/url"
14 "os" 15 "os"
15 "os/exec"
16 "path/filepath" 16 "path/filepath"
17 "sort" 17 "sort"
18 "strconv" 18 "strconv"
diff --git a/libgo/go/cmd/go/internal/modfetch/fetch.go b/libgo/go/cmd/go/internal/modfetch/fetch.go
index debeb3f3194..c55c3cf2534 100644
--- a/libgo/go/cmd/go/internal/modfetch/fetch.go
+++ b/libgo/go/cmd/go/internal/modfetch/fetch.go
@@ -768,90 +768,14 @@ var HelpModuleAuth = &base.Command{
768 UsageLine: "module-auth", 768 UsageLine: "module-auth",
769 Short: "module authentication using go.sum", 769 Short: "module authentication using go.sum",
770 Long: ` 770 Long: `
771The go command tries to authenticate every downloaded module, 771When the go command downloads a module zip file or go.mod file into the
772checking that the bits downloaded for a specific module version today 772module cache, it computes a cryptographic hash and compares it with a known
773match bits downloaded yesterday. This ensures repeatable builds 773value to verify the file hasn't changed since it was first downloaded. Known
774and detects introduction of unexpected changes, malicious or not. 774hashes are stored in a file in the module root directory named go.sum. Hashes
775 775may also be downloaded from the checksum database depending on the values of
776In each module's root, alongside go.mod, the go command maintains 776GOSUMDB, GOPRIVATE, and GONOSUMDB.
777a file named go.sum containing the cryptographic checksums of the 777
778module's dependencies. 778For details, see https://golang.org/ref/mod#authenticating.
779
780The form of each line in go.sum is three fields:
781
782 <module> <version>[/go.mod] <hash>
783
784Each known module version results in two lines in the go.sum file.
785The first line gives the hash of the module version's file tree.
786The second line appends "/go.mod" to the version and gives the hash
787of only the module version's (possibly synthesized) go.mod file.
788The go.mod-only hash allows downloading and authenticating a
789module version's go.mod file, which is needed to compute the
790dependency graph, without also downloading all the module's source code.
791
792The hash begins with an algorithm prefix of the form "h<N>:".
793The only defined algorithm prefix is "h1:", which uses SHA-256.
794
795Module authentication failures
796
797The go command maintains a cache of downloaded packages and computes
798and records the cryptographic checksum of each package at download time.
799In normal operation, the go command checks the main module's go.sum file
800against these precomputed checksums instead of recomputing them on
801each command invocation. The 'go mod verify' command checks that
802the cached copies of module downloads still match both their recorded
803checksums and the entries in go.sum.
804
805In day-to-day development, the checksum of a given module version
806should never change. Each time a dependency is used by a given main
807module, the go command checks its local cached copy, freshly
808downloaded or not, against the main module's go.sum. If the checksums
809don't match, the go command reports the mismatch as a security error
810and refuses to run the build. When this happens, proceed with caution:
811code changing unexpectedly means today's build will not match
812yesterday's, and the unexpected change may not be beneficial.
813
814If the go command reports a mismatch in go.sum, the downloaded code
815for the reported module version does not match the one used in a
816previous build of the main module. It is important at that point
817to find out what the right checksum should be, to decide whether
818go.sum is wrong or the downloaded code is wrong. Usually go.sum is right:
819you want to use the same code you used yesterday.
820
821If a downloaded module is not yet included in go.sum and it is a publicly
822available module, the go command consults the Go checksum database to fetch
823the expected go.sum lines. If the downloaded code does not match those
824lines, the go command reports the mismatch and exits. Note that the
825database is not consulted for module versions already listed in go.sum.
826
827If a go.sum mismatch is reported, it is always worth investigating why
828the code downloaded today differs from what was downloaded yesterday.
829
830The GOSUMDB environment variable identifies the name of checksum database
831to use and optionally its public key and URL, as in:
832
833 GOSUMDB="sum.golang.org"
834 GOSUMDB="sum.golang.org+<publickey>"
835 GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"
836
837The go command knows the public key of sum.golang.org, and also that the name
838sum.golang.google.cn (available inside mainland China) connects to the
839sum.golang.org checksum database; use of any other database requires giving
840the public key explicitly.
841The URL defaults to "https://" followed by the database name.
842
843GOSUMDB defaults to "sum.golang.org", the Go checksum database run by Google.
844See https://sum.golang.org/privacy for the service's privacy policy.
845
846If GOSUMDB is set to "off", or if "go get" is invoked with the -insecure flag,
847the checksum database is not consulted, and all unrecognized modules are
848accepted, at the cost of giving up the security guarantee of verified repeatable
849downloads for all modules. A better way to bypass the checksum database
850for specific modules is to use the GOPRIVATE or GONOSUMDB environment
851variables. See 'go help private' for details.
852
853The 'go env -w' command (see 'go help env') can be used to set these variables
854for future go command invocations.
855`, 779`,
856} 780}
857 781
@@ -865,8 +789,8 @@ regardless of source, against the public Go checksum database at sum.golang.org.
865These defaults work well for publicly available source code. 789These defaults work well for publicly available source code.
866 790
867The GOPRIVATE environment variable controls which modules the go command 791The GOPRIVATE environment variable controls which modules the go command
868considers to be private (not available publicly) and should therefore not use the 792considers to be private (not available publicly) and should therefore not use
869proxy or checksum database. The variable is a comma-separated list of 793the proxy or checksum database. The variable is a comma-separated list of
870glob patterns (in the syntax of Go's path.Match) of module path prefixes. 794glob patterns (in the syntax of Go's path.Match) of module path prefixes.
871For example, 795For example,
872 796
@@ -876,10 +800,6 @@ causes the go command to treat as private any module with a path prefix
876matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private, 800matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private,
877and rsc.io/private/quux. 801and rsc.io/private/quux.
878 802
879The GOPRIVATE environment variable may be used by other tools as well to
880identify non-public modules. For example, an editor could use GOPRIVATE
881to decide whether to hyperlink a package import to a godoc.org page.
882
883For fine-grained control over module download and validation, the GONOPROXY 803For fine-grained control over module download and validation, the GONOPROXY
884and GONOSUMDB environment variables accept the same kind of glob list 804and GONOSUMDB environment variables accept the same kind of glob list
885and override GOPRIVATE for the specific decision of whether to use the proxy 805and override GOPRIVATE for the specific decision of whether to use the proxy
@@ -892,12 +812,6 @@ users would configure go using:
892 GOPROXY=proxy.example.com 812 GOPROXY=proxy.example.com
893 GONOPROXY=none 813 GONOPROXY=none
894 814
895This would tell the go command and other tools that modules beginning with
896a corp.example.com subdomain are private but that the company proxy should
897be used for downloading both public and private modules, because
898GONOPROXY has been set to a pattern that won't match any modules,
899overriding GOPRIVATE.
900
901The GOPRIVATE variable is also used to define the "public" and "private" 815The GOPRIVATE variable is also used to define the "public" and "private"
902patterns for the GOVCS variable; see 'go help vcs'. For that usage, 816patterns for the GOVCS variable; see 'go help vcs'. For that usage,
903GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths 817GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
@@ -905,5 +819,7 @@ instead of module paths.
905 819
906The 'go env -w' command (see 'go help env') can be used to set these variables 820The 'go env -w' command (see 'go help env') can be used to set these variables
907for future go command invocations. 821for future go command invocations.
822
823For more details, see https://golang.org/ref/mod#private-modules.
908`, 824`,
909} 825}
diff --git a/libgo/go/cmd/go/internal/modfetch/proxy.go b/libgo/go/cmd/go/internal/modfetch/proxy.go
index d75b4da5215..6c86d8d786d 100644
--- a/libgo/go/cmd/go/internal/modfetch/proxy.go
+++ b/libgo/go/cmd/go/internal/modfetch/proxy.go
@@ -36,65 +36,8 @@ URLs of a specified form. The requests have no query parameters, so even
36a site serving from a fixed file system (including a file:/// URL) 36a site serving from a fixed file system (including a file:/// URL)
37can be a module proxy. 37can be a module proxy.
38 38
39The GET requests sent to a Go module proxy are: 39For details on the GOPROXY protocol, see
40 40https://golang.org/ref/mod#goproxy-protocol.
41GET $GOPROXY/<module>/@v/list returns a list of known versions of the given
42module, one per line.
43
44GET $GOPROXY/<module>/@v/<version>.info returns JSON-formatted metadata
45about that version of the given module.
46
47GET $GOPROXY/<module>/@v/<version>.mod returns the go.mod file
48for that version of the given module.
49
50GET $GOPROXY/<module>/@v/<version>.zip returns the zip archive
51for that version of the given module.
52
53GET $GOPROXY/<module>/@latest returns JSON-formatted metadata about the
54latest known version of the given module in the same format as
55<module>/@v/<version>.info. The latest version should be the version of
56the module the go command may use if <module>/@v/list is empty or no
57listed version is suitable. <module>/@latest is optional and may not
58be implemented by a module proxy.
59
60When resolving the latest version of a module, the go command will request
61<module>/@v/list, then, if no suitable versions are found, <module>/@latest.
62The go command prefers, in order: the semantically highest release version,
63the semantically highest pre-release version, and the chronologically
64most recent pseudo-version. In Go 1.12 and earlier, the go command considered
65pseudo-versions in <module>/@v/list to be pre-release versions, but this is
66no longer true since Go 1.13.
67
68To avoid problems when serving from case-sensitive file systems,
69the <module> and <version> elements are case-encoded, replacing every
70uppercase letter with an exclamation mark followed by the corresponding
71lower-case letter: github.com/Azure encodes as github.com/!azure.
72
73The JSON-formatted metadata about a given module corresponds to
74this Go data structure, which may be expanded in the future:
75
76 type Info struct {
77 Version string // version string
78 Time time.Time // commit time
79 }
80
81The zip archive for a specific version of a given module is a
82standard zip file that contains the file tree corresponding
83to the module's source code and related files. The archive uses
84slash-separated paths, and every file path in the archive must
85begin with <module>@<version>/, where the module and version are
86substituted directly, not case-encoded. The root of the module
87file tree corresponds to the <module>@<version>/ prefix in the
88archive.
89
90Even when downloading directly from version control systems,
91the go command synthesizes explicit info, mod, and zip files
92and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
93the same as if it had downloaded them directly from a proxy.
94The cache layout is the same as the proxy URL space, so
95serving $GOPATH/pkg/mod/cache/download at (or copying it to)
96https://example.com/proxy would let other users access those
97cached module versions with GOPROXY=https://example.com/proxy.
98`, 41`,
99} 42}
100 43
diff --git a/libgo/go/cmd/go/internal/modget/get.go b/libgo/go/cmd/go/internal/modget/get.go
index 8463ec4e9c7..574f3e194d1 100644
--- a/libgo/go/cmd/go/internal/modget/get.go
+++ b/libgo/go/cmd/go/internal/modget/get.go
@@ -56,85 +56,49 @@ var CmdGet = &base.Command{
56 UsageLine: "go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]", 56 UsageLine: "go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]",
57 Short: "add dependencies to current module and install them", 57 Short: "add dependencies to current module and install them",
58 Long: ` 58 Long: `
59Get resolves and adds dependencies to the current development module 59Get resolves its command-line arguments to packages at specific module versions,
60and then builds and installs them. 60updates go.mod to require those versions, downloads source code into the
61 61module cache, then builds and installs the named packages.
62The first step is to resolve which dependencies to add. 62
63 63To add a dependency for a package or upgrade it to its latest version:
64For each named package or package pattern, get must decide which version of 64
65the corresponding module to use. By default, get looks up the latest tagged 65 go get example.com/pkg
66release version, such as v0.4.5 or v1.2.3. If there are no tagged release 66
67versions, get looks up the latest tagged pre-release version, such as 67To upgrade or downgrade a package to a specific version:
68v0.0.1-pre1. If there are no tagged versions at all, get looks up the latest 68
69known commit. If the module is not already required at a later version 69 go get example.com/pkg@v1.2.3
70(for example, a pre-release newer than the latest release), get will use 70
71the version it looked up. Otherwise, get will use the currently 71To remove a dependency on a module and downgrade modules that require it:
72required version. 72
73 73 go get example.com/mod@none
74This default version selection can be overridden by adding an @version 74
75suffix to the package argument, as in 'go get golang.org/x/text@v0.3.0'. 75See https://golang.org/ref/mod#go-get for details.
76The version may be a prefix: @v1 denotes the latest available version starting 76
77with v1. See 'go help modules' under the heading 'Module queries' for the 77The 'go install' command may be used to build and install packages. When a
78full query syntax. 78version is specified, 'go install' runs in module-aware mode and ignores
79 79the go.mod file in the current directory. For example:
80For modules stored in source control repositories, the version suffix can 80
81also be a commit hash, branch identifier, or other syntax known to the 81 go install example.com/pkg@v1.2.3
82source control system, as in 'go get golang.org/x/text@master'. Note that 82 go install example.com/pkg@latest
83branches with names that overlap with other module query syntax cannot be 83
84selected explicitly. For example, the suffix @v2 means the latest version 84See 'go help install' or https://golang.org/ref/mod#go-install for details.
85starting with v2, not the branch named v2. 85
86 86In addition to build flags (listed in 'go help build') 'go get' accepts the
87If a module under consideration is already a dependency of the current 87following flags.
88development module, then get will update the required version.
89Specifying a version earlier than the current required version is valid and
90downgrades the dependency. The version suffix @none indicates that the
91dependency should be removed entirely, downgrading or removing modules
92depending on it as needed.
93
94The version suffix @latest explicitly requests the latest minor release of
95the module named by the given path. The suffix @upgrade is like @latest but
96will not downgrade a module if it is already required at a revision or
97pre-release version newer than the latest released version. The suffix
98@patch requests the latest patch release: the latest released version
99with the same major and minor version numbers as the currently required
100version. Like @upgrade, @patch will not downgrade a module already required
101at a newer version. If the path is not already required, @upgrade is
102equivalent to @latest, and @patch is disallowed.
103
104Although get defaults to using the latest version of the module containing
105a named package, it does not use the latest version of that module's
106dependencies. Instead it prefers to use the specific dependency versions
107requested by that module. For example, if the latest A requires module
108B v1.2.3, while B v1.2.4 and v1.3.1 are also available, then 'go get A'
109will use the latest A but then use B v1.2.3, as requested by A. (If there
110are competing requirements for a particular module, then 'go get' resolves
111those requirements by taking the maximum requested version.)
112 88
113The -t flag instructs get to consider modules needed to build tests of 89The -t flag instructs get to consider modules needed to build tests of
114packages specified on the command line. 90packages specified on the command line.
115 91
116The -u flag instructs get to update modules providing dependencies 92The -u flag instructs get to update modules providing dependencies
117of packages named on the command line to use newer minor or patch 93of packages named on the command line to use newer minor or patch
118releases when available. Continuing the previous example, 'go get -u A' 94releases when available.
119will use the latest A with B v1.3.1 (not B v1.2.3). If B requires module C,
120but C does not provide any packages needed to build packages in A
121(not including tests), then C will not be updated.
122 95
123The -u=patch flag (not -u patch) also instructs get to update dependencies, 96The -u=patch flag (not -u patch) also instructs get to update dependencies,
124but changes the default to select patch releases. 97but changes the default to select patch releases.
125Continuing the previous example,
126'go get -u=patch A@latest' will use the latest A with B v1.2.4 (not B v1.2.3),
127while 'go get -u=patch A' will use a patch release of A instead.
128 98
129When the -t and -u flags are used together, get will update 99When the -t and -u flags are used together, get will update
130test dependencies as well. 100test dependencies as well.
131 101
132In general, adding a new dependency may require upgrading
133existing dependencies to keep a working build, and 'go get' does
134this automatically. Similarly, downgrading one dependency may
135require downgrading other dependencies, and 'go get' does
136this automatically as well.
137
138The -insecure flag permits fetching from repositories and resolving 102The -insecure flag permits fetching from repositories and resolving
139custom domains using insecure schemes such as HTTP, and also bypassess 103custom domains using insecure schemes such as HTTP, and also bypassess
140module sum validation using the checksum database. Use with caution. 104module sum validation using the checksum database. Use with caution.
@@ -143,12 +107,8 @@ To permit the use of insecure schemes, use the GOINSECURE environment
143variable instead. To bypass module sum validation, use GOPRIVATE or 107variable instead. To bypass module sum validation, use GOPRIVATE or
144GONOSUMDB. See 'go help environment' for details. 108GONOSUMDB. See 'go help environment' for details.
145 109
146The second step is to download (if needed), build, and install 110The -d flag instructs get not to build or install packages. get will only
147the named packages. 111update go.mod and download source code needed to build packages.
148
149The -d flag instructs get to skip this step, downloading source code
150needed to build the named packages and their dependencies, but not
151building or installing.
152 112
153Building and installing packages with get is deprecated. In a future release, 113Building and installing packages with get is deprecated. In a future release,
154the -d flag will be enabled by default, and 'go get' will be only be used to 114the -d flag will be enabled by default, and 'go get' will be only be used to
@@ -157,31 +117,14 @@ dependencies from the current module, use 'go install'. To install a package
157ignoring the current module, use 'go install' with an @version suffix like 117ignoring the current module, use 'go install' with an @version suffix like
158"@latest" after each argument. 118"@latest" after each argument.
159 119
160If an argument names a module but not a package (because there is no 120For more about modules, see https://golang.org/ref/mod.
161Go source code in the module's root directory), then the install step
162is skipped for that argument, instead of causing a build failure.
163For example 'go get golang.org/x/perf' succeeds even though there
164is no code corresponding to that import path.
165
166Note that package patterns are allowed and are expanded after resolving
167the module versions. For example, 'go get golang.org/x/perf/cmd/...'
168adds the latest golang.org/x/perf and then installs the commands in that
169latest version.
170
171With no package arguments, 'go get' applies to Go package in the
172current directory, if any. In particular, 'go get -u' and
173'go get -u=patch' update all the dependencies of that package.
174With no package arguments and also without -u, 'go get' is not much more
175than 'go install', and 'go get -d' not much more than 'go list'.
176
177For more about modules, see 'go help modules'.
178 121
179For more about specifying packages, see 'go help packages'. 122For more about specifying packages, see 'go help packages'.
180 123
181This text describes the behavior of get using modules to manage source 124This text describes the behavior of get using modules to manage source
182code and dependencies. If instead the go command is running in GOPATH 125code and dependencies. If instead the go command is running in GOPATH
183mode, the details of get's flags and effects change, as does 'go help get'. 126mode, the details of get's flags and effects change, as does 'go help get'.
184See 'go help modules' and 'go help gopath-get'. 127See 'go help gopath-get'.
185 128
186See also: go build, go install, go clean, go mod. 129See also: go build, go install, go clean, go mod.
187 `, 130 `,
@@ -1558,7 +1501,7 @@ func (r *resolver) checkPackagesAndRetractions(ctx context.Context, pkgPatterns
1558 } 1501 }
1559 } 1502 }
1560 if retractPath != "" { 1503 if retractPath != "" {
1561 fmt.Fprintf(os.Stderr, "go: run 'go get %s@latest' to switch to the latest unretracted version\n", retractPath) 1504 fmt.Fprintf(os.Stderr, "go: to switch to the latest unretracted version, run:\n\tgo get %s@latest", retractPath)
1562 } 1505 }
1563} 1506}
1564 1507
diff --git a/libgo/go/cmd/go/internal/modget/query.go b/libgo/go/cmd/go/internal/modget/query.go
index 20eb0b6364e..d8364c8c0d3 100644
--- a/libgo/go/cmd/go/internal/modget/query.go
+++ b/libgo/go/cmd/go/internal/modget/query.go
@@ -281,14 +281,14 @@ func reportError(q *query, err error) {
281 // TODO(bcmills): Use errors.As to unpack these errors instead of parsing 281 // TODO(bcmills): Use errors.As to unpack these errors instead of parsing
282 // strings with regular expressions. 282 // strings with regular expressions.
283 283
284 patternRE := regexp.MustCompile("(?m)(?:[ \t(\"`]|^)" + regexp.QuoteMeta(q.pattern) + "(?:[ @:)\"`]|$)") 284 patternRE := regexp.MustCompile("(?m)(?:[ \t(\"`]|^)" + regexp.QuoteMeta(q.pattern) + "(?:[ @:;)\"`]|$)")
285 if patternRE.MatchString(errStr) { 285 if patternRE.MatchString(errStr) {
286 if q.rawVersion == "" { 286 if q.rawVersion == "" {
287 base.Errorf("go get: %s", errStr) 287 base.Errorf("go get: %s", errStr)
288 return 288 return
289 } 289 }
290 290
291 versionRE := regexp.MustCompile("(?m)(?:[ @(\"`]|^)" + regexp.QuoteMeta(q.version) + "(?:[ :)\"`]|$)") 291 versionRE := regexp.MustCompile("(?m)(?:[ @(\"`]|^)" + regexp.QuoteMeta(q.version) + "(?:[ :;)\"`]|$)")
292 if versionRE.MatchString(errStr) { 292 if versionRE.MatchString(errStr) {
293 base.Errorf("go get: %s", errStr) 293 base.Errorf("go get: %s", errStr)
294 return 294 return
diff --git a/libgo/go/cmd/go/internal/modload/buildlist.go b/libgo/go/cmd/go/internal/modload/buildlist.go
index 896adebbb19..45f220a6ee6 100644
--- a/libgo/go/cmd/go/internal/modload/buildlist.go
+++ b/libgo/go/cmd/go/internal/modload/buildlist.go
@@ -28,6 +28,11 @@ import (
28// 28//
29var buildList []module.Version 29var buildList []module.Version
30 30
31// additionalExplicitRequirements is a list of modules paths for which
32// WriteGoMod should record explicit requirements, even if they would be
33// selected without those requirements. Each path must also appear in buildList.
34var additionalExplicitRequirements []string
35
31// capVersionSlice returns s with its cap reduced to its length. 36// capVersionSlice returns s with its cap reduced to its length.
32func capVersionSlice(s []module.Version) []module.Version { 37func capVersionSlice(s []module.Version) []module.Version {
33 return s[:len(s):len(s)] 38 return s[:len(s):len(s)]
@@ -121,6 +126,12 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) error
121 126
122 if !inconsistent { 127 if !inconsistent {
123 buildList = final 128 buildList = final
129 additionalExplicitRequirements = make([]string, 0, len(mustSelect))
130 for _, m := range mustSelect {
131 if m.Version != "none" {
132 additionalExplicitRequirements = append(additionalExplicitRequirements, m.Path)
133 }
134 }
124 return nil 135 return nil
125 } 136 }
126 137
diff --git a/libgo/go/cmd/go/internal/modload/help.go b/libgo/go/cmd/go/internal/modload/help.go
index d81dfd56fb5..1cb58961bed 100644
--- a/libgo/go/cmd/go/internal/modload/help.go
+++ b/libgo/go/cmd/go/internal/modload/help.go
@@ -12,395 +12,16 @@ var HelpModules = &base.Command{
12 UsageLine: "modules", 12 UsageLine: "modules",
13 Short: "modules, module versions, and more", 13 Short: "modules, module versions, and more",
14 Long: ` 14 Long: `
15A module is a collection of related Go packages. 15Modules are how Go manages dependencies.
16Modules are the unit of source code interchange and versioning.
17The go command has direct support for working with modules,
18including recording and resolving dependencies on other modules.
19Modules replace the old GOPATH-based approach to specifying
20which source files are used in a given build.
21 16
22Module support 17A module is a collection of packages that are released, versioned, and
18distributed together. Modules may be downloaded directly from version control
19repositories or from module proxy servers.
23 20
24The go command includes support for Go modules. Module-aware mode is active 21For a series of tutorials on modules, see
25by default whenever a go.mod file is found in the current directory or in 22https://golang.org/doc/tutorial/create-module.
26any parent directory.
27 23
28The quickest way to take advantage of module support is to check out your 24For a detailed reference on modules, see https://golang.org/ref/mod.
29repository, create a go.mod file (described in the next section) there, and run
30go commands from within that file tree.
31
32For more fine-grained control, the go command continues to respect
33a temporary environment variable, GO111MODULE, which can be set to one
34of three string values: off, on, or auto (the default).
35If GO111MODULE=on, then the go command requires the use of modules,
36never consulting GOPATH. We refer to this as the command
37being module-aware or running in "module-aware mode".
38If GO111MODULE=off, then the go command never uses
39module support. Instead it looks in vendor directories and GOPATH
40to find dependencies; we now refer to this as "GOPATH mode."
41If GO111MODULE=auto or is unset, then the go command enables or disables
42module support based on the current directory.
43Module support is enabled only when the current directory contains a
44go.mod file or is below a directory containing a go.mod file.
45
46In module-aware mode, GOPATH no longer defines the meaning of imports
47during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)
48and installed commands (in GOPATH/bin, unless GOBIN is set).
49
50Defining a module
51
52A module is defined by a tree of Go source files with a go.mod file
53in the tree's root directory. The directory containing the go.mod file
54is called the module root. Typically the module root will also correspond
55to a source code repository root (but in general it need not).
56The module is the set of all Go packages in the module root and its
57subdirectories, but excluding subtrees with their own go.mod files.
58
59The "module path" is the import path prefix corresponding to the module root.
60The go.mod file defines the module path and lists the specific versions
61of other modules that should be used when resolving imports during a build,
62by giving their module paths and versions.
63
64For example, this go.mod declares that the directory containing it is the root
65of the module with path example.com/m, and it also declares that the module
66depends on specific versions of golang.org/x/text and gopkg.in/yaml.v2:
67
68 module example.com/m
69
70 require (
71 golang.org/x/text v0.3.0
72 gopkg.in/yaml.v2 v2.1.0
73 )
74
75The go.mod file can also specify replacements and excluded versions
76that only apply when building the module directly; they are ignored
77when the module is incorporated into a larger build.
78For more about the go.mod file, see 'go help go.mod'.
79
80To start a new module, simply create a go.mod file in the root of the
81module's directory tree, containing only a module statement.
82The 'go mod init' command can be used to do this:
83
84 go mod init example.com/m
85
86In a project already using an existing dependency management tool like
87godep, glide, or dep, 'go mod init' will also add require statements
88matching the existing configuration.
89
90Once the go.mod file exists, no additional steps are required:
91go commands like 'go build', 'go test', or even 'go list' will automatically
92add new dependencies as needed to satisfy imports.
93
94The main module and the build list
95
96The "main module" is the module containing the directory where the go command
97is run. The go command finds the module root by looking for a go.mod in the
98current directory, or else the current directory's parent directory,
99or else the parent's parent directory, and so on.
100
101The main module's go.mod file defines the precise set of packages available
102for use by the go command, through require, replace, and exclude statements.
103Dependency modules, found by following require statements, also contribute
104to the definition of that set of packages, but only through their go.mod
105files' require statements: any replace and exclude statements in dependency
106modules are ignored. The replace and exclude statements therefore allow the
107main module complete control over its own build, without also being subject
108to complete control by dependencies.
109
110The set of modules providing packages to builds is called the "build list".
111The build list initially contains only the main module. Then the go command
112adds to the list the exact module versions required by modules already
113on the list, recursively, until there is nothing left to add to the list.
114If multiple versions of a particular module are added to the list,
115then at the end only the latest version (according to semantic version
116ordering) is kept for use in the build.
117
118The 'go list' command provides information about the main module
119and the build list. For example:
120
121 go list -m # print path of main module
122 go list -m -f={{.Dir}} # print root directory of main module
123 go list -m all # print build list
124
125Maintaining module requirements
126
127The go.mod file is meant to be readable and editable by both programmers and
128tools. Most updates to dependencies can be performed using "go get" and
129"go mod tidy". Other module-aware build commands may be invoked using the
130-mod=mod flag to automatically add missing requirements and fix inconsistencies.
131
132The "go get" command updates go.mod to change the module versions used in a
133build. An upgrade of one module may imply upgrading others, and similarly a
134downgrade of one module may imply downgrading others. The "go get" command
135makes these implied changes as well. See "go help module-get".
136
137The "go mod" command provides other functionality for use in maintaining
138and understanding modules and go.mod files. See "go help mod", particularly
139"go help mod tidy" and "go help mod edit".
140
141As part of maintaining the require statements in go.mod, the go command
142tracks which ones provide packages imported directly by the current module
143and which ones provide packages only used indirectly by other module
144dependencies. Requirements needed only for indirect uses are marked with a
145"// indirect" comment in the go.mod file. Indirect requirements may be
146automatically removed from the go.mod file once they are implied by other
147direct requirements. Indirect requirements only arise when using modules
148that fail to state some of their own dependencies or when explicitly
149upgrading a module's dependencies ahead of its own stated requirements.
150
151The -mod build flag provides additional control over the updating and use of
152go.mod for commands that build packages like "go build" and "go test".
153
154If invoked with -mod=readonly (the default in most situations), the go command
155reports an error if a package named on the command line or an imported package
156is not provided by any module in the build list computed from the main module's
157requirements. The go command also reports an error if a module's checksum is
158missing from go.sum (see Module downloading and verification). Either go.mod or
159go.sum must be updated in these situations.
160
161If invoked with -mod=mod, the go command automatically updates go.mod and
162go.sum, fixing inconsistencies and adding missing requirements and checksums
163as needed. If the go command finds an unfamiliar import, it looks up the
164module containing that import and adds a requirement for the latest version
165of that module to go.mod. In most cases, therefore, one may add an import to
166source code and run "go build", "go test", or even "go list" with -mod=mod:
167as part of analyzing the package, the go command will resolve the import and
168update the go.mod file.
169
170If invoked with -mod=vendor, the go command loads packages from the main
171module's vendor directory instead of downloading modules to and loading packages
172from the module cache. The go command assumes the vendor directory holds
173correct copies of dependencies, and it does not compute the set of required
174module versions from go.mod files. However, the go command does check that
175vendor/modules.txt (generated by "go mod vendor") contains metadata consistent
176with go.mod.
177
178If the go command is not invoked with a -mod flag, and the vendor directory
179is present, and the "go" version in go.mod is 1.14 or higher, the go command
180will act as if it were invoked with -mod=vendor. Otherwise, the -mod flag
181defaults to -mod=readonly.
182
183Note that neither "go get" nor the "go mod" subcommands accept the -mod flag.
184
185Pseudo-versions
186
187The go.mod file and the go command more generally use semantic versions as
188the standard form for describing module versions, so that versions can be
189compared to determine which should be considered earlier or later than another.
190A module version like v1.2.3 is introduced by tagging a revision in the
191underlying source repository. Untagged revisions can be referred to
192using a "pseudo-version" like v0.0.0-yyyymmddhhmmss-abcdefabcdef,
193where the time is the commit time in UTC and the final suffix is the prefix
194of the commit hash. The time portion ensures that two pseudo-versions can
195be compared to determine which happened later, the commit hash identifes
196the underlying commit, and the prefix (v0.0.0- in this example) is derived from
197the most recent tagged version in the commit graph before this commit.
198
199There are three pseudo-version forms:
200
201vX.0.0-yyyymmddhhmmss-abcdefabcdef is used when there is no earlier
202versioned commit with an appropriate major version before the target commit.
203(This was originally the only form, so some older go.mod files use this form
204even for commits that do follow tags.)
205
206vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef is used when the most
207recent versioned commit before the target commit is vX.Y.Z-pre.
208
209vX.Y.(Z+1)-0.yyyymmddhhmmss-abcdefabcdef is used when the most
210recent versioned commit before the target commit is vX.Y.Z.
211
212Pseudo-versions never need to be typed by hand: the go command will accept
213the plain commit hash and translate it into a pseudo-version (or a tagged
214version if available) automatically. This conversion is an example of a
215module query.
216
217Module queries
218
219The go command accepts a "module query" in place of a module version
220both on the command line and in the main module's go.mod file.
221(After evaluating a query found in the main module's go.mod file,
222the go command updates the file to replace the query with its result.)
223
224A fully-specified semantic version, such as "v1.2.3",
225evaluates to that specific version.
226
227A semantic version prefix, such as "v1" or "v1.2",
228evaluates to the latest available tagged version with that prefix.
229
230A semantic version comparison, such as "<v1.2.3" or ">=v1.5.6",
231evaluates to the available tagged version nearest to the comparison target
232(the latest version for < and <=, the earliest version for > and >=).
233
234The string "latest" matches the latest available tagged version,
235or else the underlying source repository's latest untagged revision.
236
237The string "upgrade" is like "latest", but if the module is
238currently required at a later version than the version "latest"
239would select (for example, a newer pre-release version), "upgrade"
240will select the later version instead.
241
242The string "patch" matches the latest available tagged version
243of a module with the same major and minor version numbers as the
244currently required version. If no version is currently required,
245"patch" is equivalent to "latest".
246
247A revision identifier for the underlying source repository, such as
248a commit hash prefix, revision tag, or branch name, selects that
249specific code revision. If the revision is also tagged with a
250semantic version, the query evaluates to that semantic version.
251Otherwise the query evaluates to a pseudo-version for the commit.
252Note that branches and tags with names that are matched by other
253query syntax cannot be selected this way. For example, the query
254"v2" means the latest version starting with "v2", not the branch
255named "v2".
256
257All queries prefer release versions to pre-release versions.
258For example, "<v1.2.3" will prefer to return "v1.2.2"
259instead of "v1.2.3-pre1", even though "v1.2.3-pre1" is nearer
260to the comparison target.
261
262Module versions disallowed by exclude statements in the
263main module's go.mod are considered unavailable and cannot
264be returned by queries.
265
266For example, these commands are all valid:
267
268 go get github.com/gorilla/mux@latest # same (@latest is default for 'go get')
269 go get github.com/gorilla/mux@v1.6.2 # records v1.6.2
270 go get github.com/gorilla/mux@e3702bed2 # records v1.6.2
271 go get github.com/gorilla/mux@c856192 # records v0.0.0-20180517173623-c85619274f5d
272 go get github.com/gorilla/mux@master # records current meaning of master
273
274Module compatibility and semantic versioning
275
276The go command requires that modules use semantic versions and expects that
277the versions accurately describe compatibility: it assumes that v1.5.4 is a
278backwards-compatible replacement for v1.5.3, v1.4.0, and even v1.0.0.
279More generally the go command expects that packages follow the
280"import compatibility rule", which says:
281
282"If an old package and a new package have the same import path,
283the new package must be backwards compatible with the old package."
284
285Because the go command assumes the import compatibility rule,
286a module definition can only set the minimum required version of one
287of its dependencies: it cannot set a maximum or exclude selected versions.
288Still, the import compatibility rule is not a guarantee: it may be that
289v1.5.4 is buggy and not a backwards-compatible replacement for v1.5.3.
290Because of this, the go command never updates from an older version
291to a newer version of a module unasked.
292
293In semantic versioning, changing the major version number indicates a lack
294of backwards compatibility with earlier versions. To preserve import
295compatibility, the go command requires that modules with major version v2
296or later use a module path with that major version as the final element.
297For example, version v2.0.0 of example.com/m must instead use module path
298example.com/m/v2, and packages in that module would use that path as
299their import path prefix, as in example.com/m/v2/sub/pkg. Including the
300major version number in the module path and import paths in this way is
301called "semantic import versioning". Pseudo-versions for modules with major
302version v2 and later begin with that major version instead of v0, as in
303v2.0.0-20180326061214-4fc5987536ef.
304
305As a special case, module paths beginning with gopkg.in/ continue to use the
306conventions established on that system: the major version is always present,
307and it is preceded by a dot instead of a slash: gopkg.in/yaml.v1
308and gopkg.in/yaml.v2, not gopkg.in/yaml and gopkg.in/yaml/v2.
309
310The go command treats modules with different module paths as unrelated:
311it makes no connection between example.com/m and example.com/m/v2.
312Modules with different major versions can be used together in a build
313and are kept separate by the fact that their packages use different
314import paths.
315
316In semantic versioning, major version v0 is for initial development,
317indicating no expectations of stability or backwards compatibility.
318Major version v0 does not appear in the module path, because those
319versions are preparation for v1.0.0, and v1 does not appear in the
320module path either.
321
322Code written before the semantic import versioning convention
323was introduced may use major versions v2 and later to describe
324the same set of unversioned import paths as used in v0 and v1.
325To accommodate such code, if a source code repository has a
326v2.0.0 or later tag for a file tree with no go.mod, the version is
327considered to be part of the v1 module's available versions
328and is given an +incompatible suffix when converted to a module
329version, as in v2.0.0+incompatible. The +incompatible tag is also
330applied to pseudo-versions derived from such versions, as in
331v2.0.1-0.yyyymmddhhmmss-abcdefabcdef+incompatible.
332
333In general, having a dependency in the build list (as reported by 'go list -m all')
334on a v0 version, pre-release version, pseudo-version, or +incompatible version
335is an indication that problems are more likely when upgrading that
336dependency, since there is no expectation of compatibility for those.
337
338See https://research.swtch.com/vgo-import for more information about
339semantic import versioning, and see https://semver.org/ for more about
340semantic versioning.
341
342Module code layout
343
344For now, see https://research.swtch.com/vgo-module for information
345about how source code in version control systems is mapped to
346module file trees.
347
348Module downloading and verification
349
350The go command can fetch modules from a proxy or connect to source control
351servers directly, according to the setting of the GOPROXY environment
352variable (see 'go help env'). The default setting for GOPROXY is
353"https://proxy.golang.org,direct", which means to try the
354Go module mirror run by Google and fall back to a direct connection
355if the proxy reports that it does not have the module (HTTP error 404 or 410).
356See https://proxy.golang.org/privacy for the service's privacy policy.
357
358If GOPROXY is set to the string "direct", downloads use a direct connection to
359source control servers. Setting GOPROXY to "off" disallows downloading modules
360from any source. Otherwise, GOPROXY is expected to be list of module proxy URLs
361separated by either comma (,) or pipe (|) characters, which control error
362fallback behavior. For each request, the go command tries each proxy in
363sequence. If there is an error, the go command will try the next proxy in the
364list if the error is a 404 or 410 HTTP response or if the current proxy is
365followed by a pipe character, indicating it is safe to fall back on any error.
366
367The GOPRIVATE and GONOPROXY environment variables allow bypassing
368the proxy for selected modules. See 'go help private' for details.
369
370No matter the source of the modules, the go command checks downloads against
371known checksums, to detect unexpected changes in the content of any specific
372module version from one day to the next. This check first consults the current
373module's go.sum file but falls back to the Go checksum database, controlled by
374the GOSUMDB and GONOSUMDB environment variables. See 'go help module-auth'
375for details.
376
377See 'go help goproxy' for details about the proxy protocol and also
378the format of the cached downloaded packages.
379
380Modules and vendoring
381
382When using modules, the go command typically satisfies dependencies by
383downloading modules from their sources and using those downloaded copies
384(after verification, as described in the previous section). Vendoring may
385be used to allow interoperation with older versions of Go, or to ensure
386that all files used for a build are stored together in a single file tree.
387
388The command 'go mod vendor' constructs a directory named vendor in the main
389module's root directory that contains copies of all packages needed to support
390builds and tests of packages in the main module. 'go mod vendor' also
391creates the file vendor/modules.txt that contains metadata about vendored
392packages and module versions. This file should be kept consistent with go.mod:
393when vendoring is used, 'go mod vendor' should be run after go.mod is updated.
394
395If the vendor directory is present in the main module's root directory, it will
396be used automatically if the "go" version in the main module's go.mod file is
3971.14 or higher. Build commands like 'go build' and 'go test' will load packages
398from the vendor directory instead of accessing the network or the local module
399cache. To explicitly enable vendoring, invoke the go command with the flag
400-mod=vendor. To disable vendoring, use the flag -mod=mod.
401
402Unlike vendoring in GOPATH, the go command ignores vendor directories in
403locations other than the main module's root directory.
404 `, 25 `,
405} 26}
406 27
@@ -413,87 +34,22 @@ file in its root. When the go command is run, it looks in the current
413directory and then successive parent directories to find the go.mod 34directory and then successive parent directories to find the go.mod
414marking the root of the main (current) module. 35marking the root of the main (current) module.
415 36
416The go.mod file itself is line-oriented, with // comments but 37The go.mod file format is described in detail at
417no /* */ comments. Each line holds a single directive, made up of a 38https://golang.org/ref/mod#go-mod-file.
418verb followed by arguments. For example:
419
420 module my/thing
421 go 1.12
422 require other/thing v1.0.2
423 require new/thing/v2 v2.3.4
424 exclude old/thing v1.2.3
425 replace bad/thing v1.4.5 => good/thing v1.4.5
426 retract v1.5.6
427
428The verbs are
429 module, to define the module path;
430 go, to set the expected language version;
431 require, to require a particular module at a given version or later;
432 exclude, to exclude a particular module version from use;
433 replace, to replace a module version with a different module version; and
434 retract, to indicate a previously released version should not be used.
435Exclude and replace apply only in the main module's go.mod and are ignored
436in dependencies. See https://golang.org/ref/mod for details.
437
438The leading verb can be factored out of adjacent lines to create a block,
439like in Go imports:
440
441 require (
442 new/thing/v2 v2.3.4
443 old/thing v1.2.3
444 )
445
446The go.mod file is designed both to be edited directly and to be
447easily updated by tools. The 'go mod edit' command can be used to
448parse and edit the go.mod file from programs and tools.
449See 'go help mod edit'.
450
451The go command automatically updates go.mod each time it uses the
452module graph, to make sure go.mod always accurately reflects reality
453and is properly formatted. For example, consider this go.mod file:
454
455 module M
456
457 require (
458 A v1
459 B v1.0.0
460 C v1.0.0
461 D v1.2.3
462 E dev
463 )
464
465 exclude D v1.2.3
466
467The update rewrites non-canonical version identifiers to semver form,
468so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the
469latest commit on the dev branch, perhaps v0.0.0-20180523231146-b3f5c0f6e5f1.
470
471The update modifies requirements to respect exclusions, so the
472requirement on the excluded D v1.2.3 is updated to use the next
473available version of D, perhaps D v1.2.4 or D v1.3.0.
474 39
475The update removes redundant or misleading requirements. 40To create a new go.mod file, use 'go help init'. For details see
476For example, if A v1.0.0 itself requires B v1.2.0 and C v1.0.0, 41'go help mod init' or https://golang.org/ref/mod#go-mod-init.
477then go.mod's requirement of B v1.0.0 is misleading (superseded by
478A's need for v1.2.0), and its requirement of C v1.0.0 is redundant
479(implied by A's need for the same version), so both will be removed.
480If module M contains packages that directly import packages from B or
481C, then the requirements will be kept but updated to the actual
482versions being used.
483 42
484Finally, the update reformats the go.mod in a canonical formatting, so 43To add missing module requirements or remove unneeded requirements,
485that future mechanical changes will result in minimal diffs. 44use 'go mod tidy'. For details, see 'go help mod tidy' or
45https://golang.org/ref/mod#go-mod-tidy.
486 46
487Because the module graph defines the meaning of import statements, any 47To add, upgrade, downgrade, or remove a specific module requirement, use
488commands that load packages also use and therefore update go.mod, 48'go get'. For details, see 'go help module-get' or
489including go build, go get, go install, go list, go test, go mod graph, 49https://golang.org/ref/mod#go-get.
490go mod tidy, and go mod why.
491 50
492The expected language version, set by the go directive, determines 51To make other changes or to parse go.mod as JSON for use by other tools,
493which language features are available when compiling the module. 52use 'go mod edit'. See 'go help mod edit' or
494Language features available in that version will be available for use. 53https://golang.org/ref/mod#go-mod-edit.
495Language features removed in earlier versions, or added in later versions,
496will not be available. Note that the language version does not affect
497build tags, which are determined by the Go release being used.
498 `, 54 `,
499} 55}
diff --git a/libgo/go/cmd/go/internal/modload/import.go b/libgo/go/cmd/go/internal/modload/import.go
index ce5671728e0..182429aee41 100644
--- a/libgo/go/cmd/go/internal/modload/import.go
+++ b/libgo/go/cmd/go/internal/modload/import.go
@@ -31,10 +31,6 @@ type ImportMissingError struct {
31 Module module.Version 31 Module module.Version
32 QueryErr error 32 QueryErr error
33 33
34 // inAll indicates whether Path is in the "all" package pattern,
35 // and thus would be added by 'go mod tidy'.
36 inAll bool
37
38 // isStd indicates whether we would expect to find the package in the standard 34 // isStd indicates whether we would expect to find the package in the standard
39 // library. This is normally true for all dotless import paths, but replace 35 // library. This is normally true for all dotless import paths, but replace
40 // directives can cause us to treat the replaced paths as also being in 36 // directives can cause us to treat the replaced paths as also being in
@@ -58,7 +54,7 @@ func (e *ImportMissingError) Error() string {
58 if e.QueryErr != nil { 54 if e.QueryErr != nil {
59 return fmt.Sprintf("cannot find module providing package %s: %v", e.Path, e.QueryErr) 55 return fmt.Sprintf("cannot find module providing package %s: %v", e.Path, e.QueryErr)
60 } 56 }
61 if cfg.BuildMod == "mod" { 57 if cfg.BuildMod == "mod" || (cfg.BuildMod == "readonly" && allowMissingModuleImports) {
62 return "cannot find module providing package " + e.Path 58 return "cannot find module providing package " + e.Path
63 } 59 }
64 60
@@ -67,16 +63,14 @@ func (e *ImportMissingError) Error() string {
67 if !modfetch.IsZeroPseudoVersion(e.replaced.Version) { 63 if !modfetch.IsZeroPseudoVersion(e.replaced.Version) {
68 suggestArg = e.replaced.String() 64 suggestArg = e.replaced.String()
69 } 65 }
70 return fmt.Sprintf("module %s provides package %s and is replaced but not required; try 'go get -d %s' to add it", e.replaced.Path, e.Path, suggestArg) 66 return fmt.Sprintf("module %s provides package %s and is replaced but not required; to add it:\n\tgo get %s", e.replaced.Path, e.Path, suggestArg)
71 } 67 }
72 68
73 suggestion := "" 69 suggestion := ""
74 if !HasModRoot() { 70 if !HasModRoot() {
75 suggestion = ": working directory is not part of a module" 71 suggestion = ": working directory is not part of a module"
76 } else if e.inAll {
77 suggestion = "; try 'go mod tidy' to add it"
78 } else { 72 } else {
79 suggestion = fmt.Sprintf("; try 'go get -d %s' to add it", e.Path) 73 suggestion = fmt.Sprintf("; to add it:\n\tgo get %s", e.Path)
80 } 74 }
81 return fmt.Sprintf("no required module provides package %s%s", e.Path, suggestion) 75 return fmt.Sprintf("no required module provides package %s%s", e.Path, suggestion)
82 } 76 }
@@ -136,24 +130,57 @@ func (e *AmbiguousImportError) Error() string {
136} 130}
137 131
138// ImportMissingSumError is reported in readonly mode when we need to check 132// ImportMissingSumError is reported in readonly mode when we need to check
139// if a module in the build list contains a package, but we don't have a sum 133// if a module contains a package, but we don't have a sum for its .zip file.
140// for its .zip file. 134// We might need sums for multiple modules to verify the package is unique.
135//
136// TODO(#43653): consolidate multiple errors of this type into a single error
137// that suggests a 'go get' command for root packages that transtively import
138// packages from modules with missing sums. load.CheckPackageErrors would be
139// a good place to consolidate errors, but we'll need to attach the import
140// stack here.
141type ImportMissingSumError struct { 141type ImportMissingSumError struct {
142 importPath string 142 importPath string
143 found, inAll bool 143 found bool
144 mods []module.Version
145 importer, importerVersion string // optional, but used for additional context
146 importerIsTest bool
144} 147}
145 148
146func (e *ImportMissingSumError) Error() string { 149func (e *ImportMissingSumError) Error() string {
150 var importParen string
151 if e.importer != "" {
152 importParen = fmt.Sprintf(" (imported by %s)", e.importer)
153 }
147 var message string 154 var message string
148 if e.found { 155 if e.found {
149 message = fmt.Sprintf("missing go.sum entry needed to verify package %s is provided by exactly one module", e.importPath) 156 message = fmt.Sprintf("missing go.sum entry needed to verify package %s%s is provided by exactly one module", e.importPath, importParen)
150 } else { 157 } else {
151 message = fmt.Sprintf("missing go.sum entry for module providing package %s", e.importPath) 158 message = fmt.Sprintf("missing go.sum entry for module providing package %s%s", e.importPath, importParen)
152 } 159 }
153 if e.inAll { 160 var hint string
154 return message + "; try 'go mod tidy' to add it" 161 if e.importer == "" {
162 // Importing package is unknown, or the missing package was named on the