go/src
Ian Alexander f2d0d05d28 cmd/go: refactor usage of MainModules
This commit refactors usage of the global variable `MainModules` to
the global LoaderState variable of the same name.

This commit is part of the overall effort to eliminate global
modloader state.

[git-generate]
cd src/cmd/go/internal/modload
rf 'mv State.mainModules State.MainModules'
rf 'ex { MainModules -> LoaderState.MainModules }'
for dir in load modcmd modget test tool workcmd ; do
  cd ../${dir}
  rf 'ex {
    import "cmd/go/internal/modload"
    modload.MainModules -> modload.LoaderState.MainModules
  }'
done
cd ../modload
rf 'rm MainModules'

Change-Id: I15644c84190717d62ae953747a288ec6495ef168
Reviewed-on: https://go-review.googlesource.com/c/go/+/698060
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-07 13:41:26 -07:00
..
archive archive/tar: set a limit on the size of GNU sparse file 1.0 regions 2025-10-07 12:46:36 -07:00
arena
bufio unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
builtin builtin: use list instead of indentation for comments in cap, len, and make 2024-12-30 15:59:23 -08:00
bytes bytes: use clear in test 2025-09-18 15:30:59 -07:00
cmd cmd/go: refactor usage of MainModules 2025-10-07 13:41:26 -07:00
cmp cmp: add examples for Compare and Less 2025-03-11 15:22:39 -07:00
compress std: pass bytes.Buffer and strings.Builder by pointer 2025-05-19 09:13:04 -07:00
container
context context: don't return a non-nil from Err before Done is closed 2025-09-18 14:34:14 -07:00
crypto crypto/x509: improve domain name verification 2025-10-07 11:23:16 -07:00
database/sql database/sql: allow drivers to override Scan behavior 2025-08-11 14:27:36 -07:00
debug debug/elf: prevent offset overflow 2025-09-28 21:38:57 -07:00
embed embed: document exclusions more explicitly 2024-12-05 17:20:19 +00:00
encoding encoding/pem: make Decode complexity linear 2025-10-07 12:46:27 -07:00
errors errors: add AsType 2025-09-30 10:22:08 -07:00
expvar
flag flag: replace interface{} -> any for textValue.Get method 2025-02-28 08:43:46 -08:00
fmt fmt: reduce Errorf("x") allocations to match errors.New("x") 2025-10-06 17:34:52 -07:00
go net/url: enforce stricter parsing of bracketed IPv6 hostnames 2025-10-07 12:46:24 -07:00
hash all: remove redundant Swiss prefixes 2025-07-30 11:47:17 -07:00
html html/template: document comment stripping 2025-03-17 08:52:14 -07:00
image image/jpeg: replace fdct.go and idct.go with new implementation in dct.go 2025-09-25 07:54:32 -07:00
index/suffixarray
internal net/http: add httpcookiemaxnum GODEBUG option to limit number of cookies parsed 2025-10-07 11:23:20 -07:00
io io/fs: move path name documentation up to the package doc comment 2025-10-02 12:36:34 -07:00
iter iter: document that calling yield after terminated range loop causes runtime panic 2025-09-16 07:40:30 -07:00
log log/slog: use a pooled json encoder 2025-09-22 09:06:29 -07:00
maps all: fix some function names and typos in comment 2024-11-21 22:16:20 +00:00
math math: rename Modf parameter int to integer 2025-09-03 06:50:43 -07:00
mime mime: reduce allocs incurred by ParseMediaType 2025-09-30 13:40:32 -07:00
net net/mail: avoid quadratic behavior in mail address parsing 2025-10-07 12:46:33 -07:00
os os/user: simplify go:build 2025-09-26 19:38:54 -07:00
path path/filepath: fix EvalSymlinks to return ENOTDIR on plan9 2025-09-17 08:47:59 -07:00
plugin plugin: include a warning about race detector compatability in docs 2024-08-09 19:50:41 +00:00
reflect reflect: remove stale comment in unpackEface 2025-09-23 11:47:57 -07:00
regexp unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
runtime runtime: make work.spanSPMCs.all doubly-linked 2025-10-07 12:16:59 -07:00
slices slices: update TestIssue68488 to avoid false positives 2025-07-01 08:34:08 -07:00
sort std: remove unused declarations 2025-09-25 11:38:17 -07:00
strconv unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
strings bytes,strings: remove reference to non-existent SplitFunc 2025-09-16 09:42:15 -07:00
structs
sync sync/atomic: correct Uintptr.Or return doc 2025-09-25 10:29:41 -07:00
syscall all: replace os.Getenv("GO_BUILDER_NAME") with testenv.Builder in tests 2025-09-15 14:21:33 -07:00
testdata
testing testing/synctest: remove Run 2025-10-06 12:41:59 -07:00
text std: remove unused declarations 2025-09-25 11:38:17 -07:00
time time: improve ParseDuration performance for invalid input 2025-09-19 08:33:55 -07:00
unicode unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
unique unique: deflake TestCanonMap/LoadOrStore/ConcurrentUnsharedKeys 2025-08-19 13:39:08 -07:00
unsafe
vendor net/http: update bundled x/net/http2 and delete obsolete http2inTests 2025-10-02 12:52:26 -07:00
weak weak: clarify Pointer equality semantics 2025-03-28 13:50:18 -07:00
all.bash all.{bash,rc}: use "../bin/go tool dist" instead of "%GOTOOLDIR%/dist" print build info 2025-06-10 06:00:41 -07:00
all.bat {all,clean,make,race,run}.bat: simplify error handling 2025-02-11 09:45:10 -08:00
all.rc all.{bash,rc}: use "../bin/go tool dist" instead of "%GOTOOLDIR%/dist" print build info 2025-06-10 06:00:41 -07:00
bootstrap.bash
buildall.bash
clean.bash
clean.bat {all,clean,make,race,run}.bat: simplify error handling 2025-02-11 09:45:10 -08:00
clean.rc
cmp.bash
go.mod net/http: update bundled x/net/http2 and delete obsolete http2inTests 2025-10-02 12:52:26 -07:00
go.sum net/http: update bundled x/net/http2 and delete obsolete http2inTests 2025-10-02 12:52:26 -07:00
make.bash cmd/dist: require Go 1.24.6 as minimum bootstrap toolchain 2025-08-11 14:25:55 -07:00
make.bat cmd/dist: require Go 1.24.6 as minimum bootstrap toolchain 2025-08-11 14:25:55 -07:00
Make.dist
make.rc cmd/dist: require Go 1.24.6 as minimum bootstrap toolchain 2025-08-11 14:25:55 -07:00
race.bash runtime/race: add race detector support for linux/riscv64 2025-08-29 23:57:12 -07:00
race.bat make.bat,race.bat: simplify --dist-tool handling 2025-02-11 23:09:26 -08:00
README.vendor README.vendor: add note about GOROOT, recommend fresh go 2024-09-30 19:15:39 +00:00
run.bash
run.bat {all,clean,make,race,run}.bat: simplify error handling 2025-02-11 09:45:10 -08:00
run.rc

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.

There are two modules, std and cmd, 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 that GO111MODULE is not set in the environment, or that it is
set to 'on' or 'auto', and if you use a go.work file, set GOWORK=off.

Also, ensure that 'go env GOROOT' shows the root of this Go source
tree. Otherwise, the results are undefined. It's recommended to build
Go from source and use that 'go' binary to update its source tree.

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  # or src/cmd
    go get golang.org/x/net@master
    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'.