Skip to content

Commit 2e44aa3

Browse files
Jay Conrodandybons
Jay Conrod
authored andcommitted
[release-branch.go1.14] cmd/go: update 'go help modules' for automatic vendoring
* Mention vendor/modules.txt verification with -mod=vendor. * Update "Modules and vendoring" section. Fixes #37931 Change-Id: Ia3ee72457daabaa2fc15b7ea7427eb324c088b8f Reviewed-on: https://go-review.googlesource.com/c/go/+/223926 Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> (cherry picked from commit b816cb2) Reviewed-on: https://go-review.googlesource.com/c/go/+/224119 TryBot-Result: Gobot Gobot <[email protected]>
1 parent c8d1e4c commit 2e44aa3

File tree

2 files changed

+66
-38
lines changed

2 files changed

+66
-38
lines changed

src/cmd/go/alldocs.go

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

src/cmd/go/internal/modload/help.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,21 @@ not need updates, such as in a continuous integration and testing system.
176176
The "go get" command remains permitted to update go.mod even with -mod=readonly,
177177
and the "go mod" commands do not take the -mod flag (or any other build flags).
178178
179-
If invoked with -mod=vendor, the go command assumes that the vendor
180-
directory holds the correct copies of dependencies and ignores
181-
the dependency descriptions in go.mod.
179+
If invoked with -mod=vendor, the go command loads packages from the main
180+
module's vendor directory instead of downloading modules to and loading packages
181+
from the module cache. The go command assumes the vendor directory holds
182+
correct copies of dependencies, and it does not compute the set of required
183+
module versions from go.mod files. However, the go command does check that
184+
vendor/modules.txt (generated by 'go mod vendor') contains metadata consistent
185+
with go.mod.
182186
183187
If invoked with -mod=mod, the go command loads modules from the module cache
184188
even if there is a vendor directory present.
185189
190+
If the go command is not invoked with a -mod flag and the vendor directory
191+
is present and the "go" version in go.mod is 1.14 or higher, the go command
192+
will act as if it were invoked with -mod=vendor.
193+
186194
Pseudo-versions
187195
188196
The go.mod file and the go command more generally use semantic versions as
@@ -380,22 +388,28 @@ the format of the cached downloaded packages.
380388
381389
Modules and vendoring
382390
383-
When using modules, the go command completely ignores vendor directories.
384-
385-
By default, the go command satisfies dependencies by downloading modules
386-
from their sources and using those downloaded copies (after verification,
387-
as described in the previous section). To allow interoperation with older
388-
versions of Go, or to ensure that all files used for a build are stored
389-
together in a single file tree, 'go mod vendor' creates a directory named
390-
vendor in the root directory of the main module and stores there all the
391-
packages from dependency modules that are needed to support builds and
392-
tests of packages in the main module.
393-
394-
To build using the main module's top-level vendor directory to satisfy
395-
dependencies (disabling use of the usual network sources and local
396-
caches), use 'go build -mod=vendor'. Note that only the main module's
397-
top-level vendor directory is used; vendor directories in other locations
398-
are still ignored.
391+
When using modules, the go command typically satisfies dependencies by
392+
downloading modules from their sources and using those downloaded copies
393+
(after verification, as described in the previous section). Vendoring may
394+
be used to allow interoperation with older versions of Go, or to ensure
395+
that all files used for a build are stored together in a single file tree.
396+
397+
The command 'go mod vendor' constructs a directory named vendor in the main
398+
module's root directory that contains copies of all packages needed to support
399+
builds and tests of packages in the main module. 'go mod vendor' also
400+
creates the file vendor/modules.txt that contains metadata about vendored
401+
packages and module versions. This file should be kept consistent with go.mod:
402+
when vendoring is used, 'go mod vendor' should be run after go.mod is updated.
403+
404+
If the vendor directory is present in the main module's root directory, it will
405+
be used automatically if the "go" version in the main module's go.mod file is
406+
1.14 or higher. Build commands like 'go build' and 'go test' will load packages
407+
from the vendor directory instead of accessing the network or the local module
408+
cache. To explicitly enable vendoring, invoke the go command with the flag
409+
-mod=vendor. To disable vendoring, use the flag -mod=mod.
410+
411+
Unlike vendoring in GOPATH, the go command ignores vendor directories in
412+
locations other than the main module's root directory.
399413
`,
400414
}
401415

0 commit comments

Comments
 (0)