go/src
Bryan C. Mills 02e5505858 [release-branch.go1.16] cmd/go: avoid +incompatible major versions if a go.mod file exists in a subdirectory for that version
Previous versions of the 'go' command would reject a pseudo-version
passed to 'go get' if that pseudo-version had a mismatched major
version and lacked a "+incompatible" suffix. However, they would
erroneously accept a version *with* a "+incompatible" suffix even if
the repo contained a vN/go.mod file for the same major version, and
would generate a "+incompatible" pseudo-version or version if the user
requested a tag, branch, or commit hash.

This change uniformly rejects "vN.…" without "+incompatible", and also
avoids resolving to "vN.…+incompatible", when vN/go.mod exists.
To maintain compatibility with existing go.mod files, it still accepts
"vN.…+incompatible" if the version is requested explicitly as such
and the repo root lacks a go.mod file.

Fixes #51331
Updates #51324
Updates #36438

Change-Id: I2b16150c73fc2abe4d0a1cd34cb1600635db7139
Reviewed-on: https://go-review.googlesource.com/c/go/+/387675
Trust: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
(cherry picked from commit 5a9fc946b4)
Reviewed-on: https://go-review.googlesource.com/c/go/+/387923
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2022-03-03 14:29:55 +00:00
..
archive [release-branch.go1.16] archive/zip: don't panic on (*Reader).Open 2021-11-03 16:57:50 +00:00
bufio
builtin
bytes
cmd [release-branch.go1.16] cmd/go: avoid +incompatible major versions if a go.mod file exists in a subdirectory for that version 2022-03-03 14:29:55 +00:00
compress
container
context
crypto [release-branch.go1.16] crypto/elliptic: make IsOnCurve return false for invalid field elements 2022-02-07 19:24:54 +00:00
database/sql
debug [release-branch.go1.16] debug/pe,debug/macho: add support for DWARF5 sections 2022-02-03 20:56:11 +00:00
embed embed, io/fs: clarify that leading and trailing slashes are disallowed 2021-02-05 22:35:11 +00:00
encoding [release-branch.go1.16-security] encoding/xml: prevent infinite loop while decoding 2021-03-09 17:55:05 +00:00
errors
expvar
flag
fmt
go [release-branch.go1.16] go/internal/gccgoimporter: fix up gccgo installation test 2021-08-11 16:14:09 +00:00
hash
html [release-branch.go1.16] text/template: add lock for Template.tmpl to fix data race 2021-09-09 13:49:11 +00:00
image
index/suffixarray
internal internal/poll: netpollcheckerr before sendfile 2021-02-16 11:01:41 +00:00
io io/fs: allow backslash in ValidPath, reject in os.DirFS.Open 2021-02-11 01:10:28 +00:00
log
math [release-branch.go1.16] math/big: prevent overflow in (*Rat).SetString 2022-01-28 15:39:20 +00:00
mime
net [release-branch.go1.16] net: increase maximum accepted DNS packet to 1232 bytes 2022-02-17 19:27:56 +00:00
os [release-branch.go1.16] syscall: syscall.AllThreadsSyscall signal handling fixes 2021-05-04 20:41:53 +00:00
path
plugin
reflect
regexp [release-branch.go1.16] regexp/syntax: reject very deeply nested regexps in Parse 2022-02-17 19:21:56 +00:00
runtime [release-branch.go1.16] runtime: simplify histogram buckets considerably 2022-02-18 00:27:46 +00:00
sort
strconv
strings
sync
syscall [release-branch.go1.16] syscall: avoid writing to p when Pipe(p) fails 2021-12-09 12:28:59 +00:00
testdata
testing [release-branch.go1.16] testing: drop unusual characters from TempDir directory name 2022-01-26 18:34:58 +00:00
text [release-branch.go1.16] text/template: initialize template before locking it 2021-09-23 21:18:29 +00:00
time [release-branch.go1.16] time: fix looking for zone offset when date is close to a zone transition 2021-11-29 02:12:23 +00:00
unicode
unsafe
vendor [release-branch.go1.16] net/http: update bundled golang.org/x/net/http2 2022-01-06 15:30:21 +00:00
Make.dist
README.vendor
all.bash
all.bat
all.rc
bootstrap.bash
buildall.bash
clean.bash
clean.bat
clean.rc
cmp.bash
go.mod [release-branch.go1.16] net/http: update bundled golang.org/x/net/http2 2022-01-06 15:30:21 +00:00
go.sum [release-branch.go1.16] net/http: update bundled golang.org/x/net/http2 2022-01-06 15:30:21 +00:00
make.bash
make.bat
make.rc
race.bash
race.bat
run.bash [release-branch.go1.16] build: set GOPATH consistently in run.bash, run.bat, run.rc 2021-03-29 19:16:21 +00:00
run.bat [release-branch.go1.16] build: set GOPATH consistently in run.bash, run.bat, run.rc 2021-03-29 19:16:21 +00:00
run.rc [release-branch.go1.16] build: set GOPATH consistently in run.bash, run.bat, run.rc 2021-03-29 19:16:21 +00:00

README.vendor

Vendoring in std and cmd
========================

The Go command maintains copies of external packages needed by the
standard library in the src/vendor and src/cmd/vendor directories.

In GOPATH mode, imports of vendored packages are resolved to these
directories following normal vendor directory logic
(see golang.org/s/go15vendor).

In module mode, std and cmd are modules (defined in src/go.mod and
src/cmd/go.mod). When a package outside std or cmd is imported
by a package inside std or cmd, the import path is interpreted
as if it had a "vendor/" prefix. For example, within "crypto/tls",
an import of "golang.org/x/crypto/cryptobyte" resolves to
"vendor/golang.org/x/crypto/cryptobyte". When a package with the
same path is imported from a package outside std or cmd, it will
be resolved normally. Consequently, a binary may be built with two
copies of a package at different versions if the package is
imported normally and vendored by the standard library.

Vendored packages are internally renamed with a "vendor/" prefix
to preserve the invariant that all packages have distinct paths.
This is necessary to avoid compiler and linker conflicts. Adding
a "vendor/" prefix also maintains the invariant that standard
library packages begin with a dotless path element.

The module requirements of std and cmd do not influence version
selection in other modules. They are only considered when running
module commands like 'go get' and 'go mod vendor' from a directory
in GOROOT/src.

Maintaining vendor directories
==============================

Before updating vendor directories, ensure that module mode is enabled.
Make sure GO111MODULE=off is not set ('on' or 'auto' should work).

Requirements may be added, updated, and removed with 'go get'.
The vendor directory may be updated with 'go mod vendor'.
A typical sequence might be:

    cd src
    go get -d golang.org/x/net@latest
    go mod tidy
    go mod vendor

Use caution when passing '-u' to 'go get'. The '-u' flag updates
modules providing all transitively imported packages, not only
the module providing the target package.

Note that 'go mod vendor' only copies packages that are transitively
imported by packages in the current module. If a new package is needed,
it should be imported before running 'go mod vendor'.