summaryrefslogtreecommitdiff
path: root/src/cmd/go
Commit message (Collapse)AuthorAgeFilesLines
* all: fix various doc comment formatting nitsRuss Cox2022-04-011-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A run of lines that are indented with any number of spaces or tabs format as a <pre> block. This commit fixes various doc comments that format badly according to that (standard) rule. For example, consider: // - List item. // Second line. // - Another item. Because the - lines are unindented, this is actually two paragraphs separated by a one-line <pre> block. This CL rewrites it to: // - List item. // Second line. // - Another item. Today, that will format as a single <pre> block. In a future release, we hope to format it as a bulleted list. Various other minor fixes as well, all in preparation for reformatting. For #51082. Change-Id: I95cf06040d4186830e571cd50148be3bf8daf189 Reviewed-on: https://go-review.googlesource.com/c/go/+/384257 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: prevent go work use panic when given a fileJohn Anthony2022-03-312-4/+21
| | | | | | | | | | | | | | | | | The current implementation fails to identify that an argument to go work use is a file when expecting a directory, and panics when attempting to access it as a directory. This change checks arguments are directories and generates an error otherwise. Fixes #51749 Change-Id: If8f69d233409e93fcf391a8774bace74c031c986 Reviewed-on: https://go-review.googlesource.com/c/go/+/393615 Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
* cmd/go: allow either test to complete first in ↵Bryan C. Mills2022-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | TestScript/test_chatty_parallel_success_run This fixes a failure mode observed in https://build.golang.org/log/7b28a914b1914dabe94f7c4e36ad6466ebd4de5d, in which the expected CONT lines are present but the test completions are reported in a different (but valid) order. CONT lines are only printed between interleaved output lines, so if the ordering of the tests swaps after all output is already generated the PASS lines can be in arbitrary order. Fixes #51221 (again). Change-Id: I051f8ec4331e2e3ab1bb00a7c188c322ad4e0a03 Reviewed-on: https://go-review.googlesource.com/c/go/+/397194 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* cmd/go: update TestCgoHandlesWlORIGIN to avoid -rpath on windowsThan McIntosh2022-03-311-1/+1
| | | | | | | | | | | | | | | | Tweak the cgo recipe for the TestCgoHandlesWlORIGIN testpoint to avoid using "-rpath" on Windows, where it doesn't make sense to use it. This change needed to avoid an "unknown flag -rpath" from clang/ldd on windows. Updates #35006. Change-Id: I4fcd649df4687aa3aff5690e11a15fc0e0f42332 Reviewed-on: https://go-review.googlesource.com/c/go/+/384155 Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd: make go and moddeps tests insensitive to presence of src/go.workDavid Chase2022-03-301-0/+1
| | | | | | | | | | | | | | If there is a go.work file in src, "go test cmd/internal/moddeps" and "go test cmd/go" fail. Setting GOWORK=off in various command invocations avoids this problem. Change-Id: I89fd021ff94998ceda6a3bbc4c3743f08558f98b Reviewed-on: https://go-review.googlesource.com/c/go/+/396777 Trust: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: remove arbitrary sleep in TestScript/test_chatty_parallel_success_sleepyBryan C. Mills2022-03-302-39/+41
| | | | | | | | | | | | | | | | | | | | | (Also rename it to no longer describe itself in terms of sleeping.) This test previously relied on the scheduler to wake up a goroutine to write the "--- PASS: TestFast" line within 100ms of TestFast actually finishing. On some platforms, even that long a delay is apparently too short. Instead, we now use a deterministic "=== RUN" line instead of a timing-dependent "--- PASS" line to interrupt the output. Fixes #51221 Change-Id: I3997640fb7577e29e3866a82d4d49a3a70a4b033 Reviewed-on: https://go-review.googlesource.com/c/go/+/386154 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: use new "unix" build tag where appropriateIan Lance Taylor2022-03-295-5/+5
| | | | | | | | | | For #20322 For #51572 Change-Id: Id0b4799d097d01128e98ba4cc0092298357bca45 Reviewed-on: https://go-review.googlesource.com/c/go/+/389935 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* go/build: recognize "unix" build tagIan Lance Taylor2022-03-282-0/+2
| | | | | | | | | | | | | | | The new "unix" build tag matches any Unix or Unix-like system. This is only recognized on go:build lines, not in file names. For #20322 Fixes #51572 Change-Id: I3a991f9e69353b25e259bc6462709cdcd83640fb Reviewed-on: https://go-review.googlesource.com/c/go/+/389934 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go/internal/modfetch: remove unused FileRev structBaokun Lee2022-03-271-7/+0
| | | | | | | | | | | | | In CL 367756 we remove ReadFileRevs function, We simplified the implementation of the interface Repo. and the type FileRev is no longer used. Change-Id: Iec9e2f0d6bb227f4d0d0f565e897137dcf392a3a Reviewed-on: https://go-review.googlesource.com/c/go/+/373375 Trust: Lee Baokun <bk@golangcn.org> Run-TryBot: Lee Baokun <bk@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/gofmt: return a proper error for empty Go filesDaniel Martí2022-03-241-0/+7
| | | | | | | | | | | | | | | | | | | | | | | I was testing edge cases in gofumpt, a fork of gofmt, and noticed that gofmt will return a bare io error on empty files, as demonstrated by the added test case without a fix: > ! exec $GOROOT/bin/gofmt empty.go nopackage.go [stderr] EOF nopackage.go:1:1: expected 'package', found not The problem is the code that detects concurrent modifications. It relies on ReadFull and correctly deals with io.ErrUnexpectedEOF, but it did not pay attention to io.EOF, which can happen when size==0. Change-Id: I6092391721edad4584fb5922d3e3a8fb3da86493 Reviewed-on: https://go-review.googlesource.com/c/go/+/393757 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Trust: Matt Layher <mdlayher@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: diagnose unset GOROOT when built with -trimpathBryan C. Mills2022-03-184-3/+27
| | | | | | | | | For #51483 Change-Id: I4546c20cf968b595020a1eba888fe1d9a1c6cfc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/391811 Reviewed-by: Russ Cox <rsc@golang.org> Trust: Bryan Mills <bcmills@google.com>
* cmd/go: include the "-trimpath" flag in the stamped build settingsBryan C. Mills2022-03-182-0/+7
| | | | | | | | | | | | | | | The -trimpath flag has a strong effect on the resulting binary: in particular, it determines whether runtime.GOROOT can report a meaningful path in the absence of an explicit GOROOT environment variable. For #51461 Change-Id: Id0d55572c0a0a4e2e4724363ed80dfa05b202186 Reviewed-on: https://go-review.googlesource.com/c/go/+/391810 Trust: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: stamp build settings for binaries in cmdBryan C. Mills2022-03-181-48/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | Also update cmd/dist to avoid setting gcflags and ldflags explicitly when the set of flags to be set is empty (a verbose way of specifying the default behavior). Stamping was disabled for the Go standard library in CL 356014 due to the cmd/dist flags causing cmd/go to (correctly) report the resulting binaries as stale. With cmd/dist fixed, we can also remove the special case in cmd/go, which will allow tests of binaries in 'cmd' to read the build info embedded in the test binary. That build info may be useful to determine (say) whether runtime.GOROOT ought to work without GOROOT set in the environment. For #51483 Updates #37475 Change-Id: I64d04f5990190094eb6c0522db829d3bdfa50ef3 Reviewed-on: https://go-review.googlesource.com/c/go/+/391809 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go/internal/test: ensure that build.ToolDir is accurate in testsBryan C. Mills2022-03-182-17/+39
| | | | | | | | | | | | | | This fixes a build failure due to inability to locate the "vet" tool when the test binary is built with -trimpath. Updates #51461 Change-Id: I81838cc8842e4ff7900cab81af60501ebba86ff1 Reviewed-on: https://go-review.googlesource.com/c/go/+/391808 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* go/build: avoid setting Default.GOROOT when runtime.GOROOT() is emptyBryan C. Mills2022-03-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | Previously, we called path.Clean on the value of runtime.GOROOT() even if it was empty, which would set it explicitly to ".". That would cause (*Context).importGo to assume that errors resolving paths in GOROOT are fatal and return early: https://cs.opensource.google/go/go/+/master:src/go/build/build.go;l=1121-1127;drc=38174b3a3514629b84dcd76878b2f536b189dd7b If we instead leave it empty (and are in module mode), then importGo will fall back to letting the 'go' command resolve the path, which may succeed if the 'go' command can infer the correct GOROOT (from its own stamped-in default GOROOT or executable path). Fixes #51483 Change-Id: I44dce7cec6c3d1c86670e629ddfbca8be461130c Reviewed-on: https://go-review.googlesource.com/c/go/+/391805 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/testenv: add GOROOT and use it to fix tests broken with -trimpathBryan C. Mills2022-03-181-2/+1
| | | | | | | | | | | | | | | This fixes many (but not all) of the tests that currently fail (due to a bogus path reported by runtime.GOROOT) when run with 'go test -trimpath std cmd'. Updates #51461 Change-Id: Ia2cc05705529c4859e7928f32eeceed647f2e986 Reviewed-on: https://go-review.googlesource.com/c/go/+/391806 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/link: avoid stamping runtime.defaultGOROOT when paths are being trimmedBryan C. Mills2022-03-182-1/+64
| | | | | | | | | | | | | | | | | Previously, runtime.GOROOT() would return the string "go" in a binary build with -trimpath. This change stamps the empty string instead, using a sentinel value passed from cmd/go that looks like the GOROOT environment variable (either "$GOROOT" or "%GOROOT%", depending on the platform). Fixes #51461 Change-Id: I1f10ef2435016a7b6213bd8c547df911f7feeae7 Reviewed-on: https://go-review.googlesource.com/c/go/+/390024 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: avoid stamping VCS metadata in test binariesBryan C. Mills2022-03-185-11/+123
| | | | | | | | | | | | | | | | | | | | | | Invoking a VCS tool requires that the VCS tool be installed, and also adds latency to build commands. Unfortunately, we had been mistakenly loading VCS metadata for tests of "main" packages. Users almost never care about versioning for test binaries, because 'go test' runs the test in the source tree and test binaries are only rarely used outside of 'go test'. So the user already knows exactly which version the test is built against, because the source code is right there — it's not worth the overhead to stamp. Fixes #51723. Change-Id: I96f191c5a765f5183e5e10b6dfb75a0381c99814 Reviewed-on: https://go-review.googlesource.com/c/go/+/393894 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Trust: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: run 'go help documentation' through gofmt in TestDocsUpToDateRuss Cox2022-03-181-3/+11
| | | | | | | | | | | | | mkalldocs.sh runs gofmt on the output, but the test does not. If go help documentation and gofmt disagree, the test will fail. Fix that. Change-Id: I837374a2d36cb5d71278ecefe2a7b6544622c576 Reviewed-on: https://go-review.googlesource.com/c/go/+/384256 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/buildcfg: extract logic specific to cmd/goBryan C. Mills2022-03-186-44/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/doc: use the 'go' command from buildCtx.GOROOT, not whatever is in $PATHBryan C. Mills2022-03-171-0/+30
| | | | | | | | | | | For #51483. Change-Id: I6150fdf97763d858e9ab012e807515da3387c25f Reviewed-on: https://go-review.googlesource.com/c/go/+/393366 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/txtar: bring back to main repo, for tests in stdRuss Cox2022-03-166-10/+6
| | | | | | | | | | | | | | | | | | | | | | | | | This used to be cmd/go/internal/txtar, and then it was moved to golang.org/x/tools/txtar and revendored from there into cmd/vendor/golang.org/x/tools/txtar. We have a use for txtar in a new test in the standard library, which cannot access cmd/vendor. But we also don't really want to vendor it into the standard library as is, because that would be the first vendoring of x/tools in std, and it would be better to keep std separate from x/tools, even for testing. Instead, since a little copying is better than a little dependency, just make a copy in internal/txtar. The package does not change. Having done that, replace the uses in cmd/go so that there's only one copy in the main repo. Change-Id: I70b5cc05da3f6ebcc0fd9052ebcb3d369fb57956 Reviewed-on: https://go-review.googlesource.com/c/go/+/384254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: document that 'go run' strips debug infoIan Lance Taylor2022-03-152-0/+8
| | | | | | | | | Change-Id: Ie7293a33862853ac56ee0a9017b201d8ff0ba1f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/392574 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go: use testGOROOT in TestListTemplateContextFunctionBryan C. Mills2022-03-141-1/+1
| | | | | | | | | | | | | | | | | This test uses testgo to run 'go list', so it should use the correct GOROOT for testgo. (This may be particularly relevant when the test binary itself is build with -trimpath, in which case runtime.GOROOT() is not valid.) Updates #51483 Change-Id: I79b310f88e3a200122d6289073df1385e3e97cca Reviewed-on: https://go-review.googlesource.com/c/go/+/391801 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Trust: Daniel Martí <mvdan@mvdan.cc>
* cmd/go: use the correct gofmt binary in TestScript/fmt_load_errorsBryan C. Mills2022-03-111-4/+3
| | | | | | | | | | | Otherwise, this test may fail when GOROOT/bin is not in $PATH. Change-Id: Id744f365f6604716207184c9ea49436ab2e3a835 Reviewed-on: https://go-review.googlesource.com/c/go/+/391802 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/fuzz: minimization should not reduce coverageSteven Johnstone2022-03-101-11/+0
| | | | | | | | | | | | | | | | Minimization should result in a fuzz input which includes the same coverage bits as the original input. Updates #48326 Change-Id: I6c5f30058b57ccd1a096ad0e9452a4dfbb7d9aab Reviewed-on: https://go-review.googlesource.com/c/go/+/391454 Trust: Bryan Mills <bcmills@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/fuzz: don't use dirty coverage maps during minimizationRoland Shoemaker2022-03-101-0/+84
| | | | | | | | | | | | | | | | | | | When minimizing a value, if the value cannot be minimized (i.e. it is the final value is the same value as was sent for minimization) return the initial coverage map, rather than the coverageSnapshot, which is actually the coverage map for the final minimization step and may not accurately reflect whether the input actually expands the coverage set or not. Updates #48326 Change-Id: I01f0eebe5841e808b6799647d2e5fe3aa45cd2e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/391614 Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: fix buildvcs when using older git versionsMark Pulford2022-03-092-2/+2
| | | | | | | | | | | | | | | Git versions before v2.10.0 do not support --no-show-signature. Using "-c" allows Git to ignore the configuration option if it does not exist. Fixes #51253 Change-Id: I2b1adaca0eb18ae31f2e1119e354ce515b00cfc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/388194 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go: for gccgo expect one fewer file in TestScript/list_swigcxxIan Lance Taylor2022-03-081-2/+3
| | | | | | | | | | | | One of the files in CompileGoFiles is actually _cgo_import.go, but that file is only generated for gc, not for gccgo. Change-Id: I87bb55552e1409cc57da8f35a32b37ce4a3df60c Reviewed-on: https://go-review.googlesource.com/c/go/+/390895 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go: clarify error from 'go install' when arguments have mismatched ↵uji2022-03-042-2/+2
| | | | | | | | | | | | | | | | | versions and paths Fixes #51196. Change-Id: I0ee4d8234f11e4f3b71b81546518647e07fafd7d GitHub-Last-Rev: 8fd1a77adff982dd00385c5b25a4e0cdf3e2e220 GitHub-Pull-Request: golang/go#51373 Reviewed-on: https://go-review.googlesource.com/c/go/+/388154 Trust: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Trust: Than McIntosh <thanm@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
* cmd/go: avoid rebuilding itself in TestMainDaniel Martí2022-03-047-73/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An extra "go build" was happening, for the sake of -tags=testgo, which would insert some extra behavior into ./internal/work. Instead, reuse the test binary as cmd/go directly, by calling the main func when a special env var is set. We still duplicate the test binary into testBin, because we need a "go" executable in that directory for $PATH. Finally, the special behavior is instead inserted via TestMain. The numbers below represent how long it takes to run zero tests, measured via: benchcmd GoTestNothing go test -run=- That is, the time it takes to run the first test is reduced by half. Note that these numbers are on a warm build cache, so if the -tags=testgo build were to be done from scratch, the speed-up would be significantly more noticeable. name old time/op new time/op delta GoTestNothing 830ms ± 2% 380ms ± 7% -54.23% (p=0.008 n=5+5) name old user-time/op new user-time/op delta GoTestNothing 1.64s ± 1% 0.82s ± 3% -50.24% (p=0.008 n=5+5) name old sys-time/op new sys-time/op delta GoTestNothing 306ms ± 7% 159ms ±28% -48.15% (p=0.008 n=5+5) name old peak-RSS-bytes new peak-RSS-bytes delta GoTestNothing 173MB ± 1% 147MB ± 1% -14.96% (p=0.008 n=5+5) Change-Id: I1f8fc71269a7b45bc5b82b7228e13f56589d44c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/378294 Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go: add links to workspaces reference and tutorial to go help workMichael Matloob2022-03-036-8/+35
| | | | | | | | | | | For #45713 Change-Id: Ia2901cbfc5deb52503e74fcf9dff26a56ec582c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/389297 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: error out of 'go work use' if no directories are givenBryan C. Mills2022-03-033-2/+16
| | | | | | | | | | | | Otherwise, the behavior of 'go work use -r' (without arguments) may be surprising. Change-Id: I50cf1339591720ec5bd333146b89c9944ce420d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/389855 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: make paths consistent between 'go work init' and 'go work use'Bryan C. Mills2022-03-036-12/+29
| | | | | | | | | | | Fixes #51448 Change-Id: I86719b55037c377eb82154e169d8a9bbae20b77c Reviewed-on: https://go-review.googlesource.com/c/go/+/389854 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
* cmd/go: ignore the workspace when running a package at a specified versionBryan C. Mills2022-03-033-2/+24
| | | | | | | | | | | For #51390 Change-Id: I805e66809b2aafb48f7040dee72910dd7d6c1396 Reviewed-on: https://go-review.googlesource.com/c/go/+/388917 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
* cmd/go: allow users to specify required fields in JSON outputMichael Matloob2022-03-023-18/+137
| | | | | | | | | | | For #29666 Change-Id: Ibae3d75bb2c19571c8d473cb47d6c4b3a880bba8 Reviewed-on: https://go-review.googlesource.com/c/go/+/381035 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* internal/goversion: update Version to 1.19Carlos Amedee2022-02-281-1/+1
| | | | | | | | | | | | | | | | | | This is the start of the Go 1.19 development cycle, so update the Version value accordingly. It represents the Go 1.x version that will soon open up for development (and eventually become released). Updates #40705 Updates #51336 Change-Id: Ic4b3f2c04b1fa5c588cb6d62e829f2ed1864e511 Reviewed-on: https://go-review.googlesource.com/c/go/+/388376 Trust: Carlos Amedee <carlos@golang.org> Run-TryBot: Carlos Amedee <carlos@golang.org> Trust: Alex Rakoczy <alex@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Alex Rakoczy <alex@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: make work and work_edit script tests version-independentMichael Matloob2022-02-282-6/+6
| | | | | | | | | | | | | | | | | | The work and work_edit script tests ran go work init, which put the current Go version into the go.work files. Before this change, the tests used cmp to compare the outputs with a file that contained a literal "go 1.18" line. Instead, use cmpenv so we can compare with "go $goversion". (Some of the test cases still compare against files that contain "go 1.18" lines, but these tests explicitly set the version to go 1.18 either in the original go.work files or using go work edit.) Change-Id: Iea2caa7697b5fe5939070558b1664f70130095ce Reviewed-on: https://go-review.googlesource.com/c/go/+/388514 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
* cmd/go: avoid +incompatible major versions if a go.mod file exists in a ↵Bryan C. Mills2022-02-242-12/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 #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>
* cmd/go/internal/modload: set errors for packages with invalid import pathsBryan C. Mills2022-02-166-24/+79
| | | | | | | | | | | | | | | | | | | | | | | | Prior to CL 339170, relative errors in module mode resulted in a base.Fatalf from the module loader, which caused unrecoverable errors from 'go list -e' but successfully rejected relative imports (which were never intended to work in module mode in the first place). After that CL, the base.Fatalf is no longer present, but some errors that had triggered that base.Fatalf were no longer diagnosed at all: the module loader left them for the package loader to report, and the package loader assumed that the module loader would report them. Since the module loader already knows that the paths are invalid, it now reports those errors itself. Fixes #51125 Change-Id: I70e5818cfcfeea0ac70e17274427b08a74fd7c13 Reviewed-on: https://go-review.googlesource.com/c/go/+/386176 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* testing: panic in Fuzz if the function returns a valueBryan C. Mills2022-02-161-0/+19
| | | | | | | | | | | | | | | | | | | Otherwise, the behavior of a fuzz target that returns an error could be confusing. Fuzz is already documented to require a function “with no return value”, so this fixes the implementation to match the existing documentation. Fixes #51222 Change-Id: I44ca7ee10960214c92f5ac066ac8484c8bb9cd6f Reviewed-on: https://go-review.googlesource.com/c/go/+/386175 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Nooras Saba‎ <saba@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: set go.work path using GOWORK, and remove -workfile flagMichael Matloob2022-02-1625-84/+77
| | | | | | | | | | | | | | | | | | | | This change removes the -workfile flag and allows the go.work file path to be set using GOWORK (which was previously read-only). This removes the potential discrepancy and confusion between the flag and environment variable. GOWORK will still return the actual path of the go.work file found if it is set to '' or 'auto'. GOWORK will return 'off' if it is set to 'off'. For #45713 Fixes #51171 Change-Id: I72eed65d47c63c81433f2b54158d514daeaa1ab3 Reviewed-on: https://go-review.googlesource.com/c/go/+/385995 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/go: in workspace mode, resolve replacements relative to their go.mod filesBryan C. Mills2022-02-153-6/+77
| | | | | | | | | | | Fixes #51204 Change-Id: I41106b7d04120be5ba68573bd25fd33e985688de Reviewed-on: https://go-review.googlesource.com/c/go/+/385994 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go/internal/modfetch: avoid leaking a lockedfile.File in case of write ↵alex.schade2022-02-151-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | errors The go modules download command has a method called hashZip which checks the hash of a zipped directory versus an expected value, and then writes it out to a file. In the event that the write operation is not successful, we do not close the file, leading to it being leaked. This could happen if the user runs out of disk space, causing the underlying OS write command to return an error. Ultimately, this led to a panic in lockfile.OpenFile which was invoked from a finalizer garbage collecting the leaked file. The result was a stack trace that didn't show the call stack from where the write operation actually failed. Fixes #50858 Change-Id: I4a24d2ab13dc903d623bbf8252b37bb9d724b8de GitHub-Last-Rev: 354ef1d29ed9d9bb2d9bfe4b73306c550aab07fd GitHub-Pull-Request: golang/go#51058 Reviewed-on: https://go-review.googlesource.com/c/go/+/383915 Trust: Cherry Mui <cherryyz@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: enable file shortening for lines starting with \tKeith Randall2022-02-141-0/+1
| | | | | | | | | | | | | | | | | | | | | Compiler errors now (as of 1.18) might start with a tab character, for errors which take multiple lines to report. e.g.: /Users/khr/gowork/tmp1.go:3:15: x redeclared in this block /Users/khr/gowork/tmp1.go:3:8: other declaration of x This CL makes error lines starting with a tab character eligible for replacing absolute paths with relative ones. Fixes #51177 Change-Id: Ic9e9c610a1aa1e21e9f19e6a9bd05c73b5a14e4a Reviewed-on: https://go-review.googlesource.com/c/go/+/385755 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Trust: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: have go work init use the -workfile flagMichael Matloob2022-02-142-1/+19
| | | | | | | | | | Change-Id: Idb4795bde699c919222953ec33fa1083798b2000 Reviewed-on: https://go-review.googlesource.com/c/go/+/385654 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
* cmd/go: support workspaces in vetMichael Matloob2022-02-112-0/+21
| | | | | | | | | | | | | | Add modload.InitWorkfile to runVet so that the vet command recognizes and uses the workspace. Fixes #51072 Change-Id: Ia6727eff9b80eb33627f5ae23e4d72cde581e75f Reviewed-on: https://go-review.googlesource.com/c/go/+/385176 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go: mention go.work when local path outside modules in go.workMichael Matloob2022-02-106-12/+46
| | | | | | | | | | | | | | | | | | | | | | In workspace mode, if a user lists a package or patternthat's inside a module that's not listed in go.work, mention that the package or pattern is outside the modules listed in go.work so the user has a better idea of how to fix the issue. (Question: it's valid in those flows to add a pattern that points into the module cache. Should we expand the error to say "package outside modules listed in go.work file or contained in module cache"? That seems clunky (and is the uncommon case) which is why I didn't do so in this case, but it's possible) Fixes #49632 Change-Id: I3f0ea1b2f566d52a8079b58593fcc5cc095e7a41 Reviewed-on: https://go-review.googlesource.com/c/go/+/384236 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* runtime/debug: replace (*BuildInfo).Marshal methods with Parse and StringBryan C. Mills2022-02-092-15/+9
| | | | | | | | | | | | | | | | | | | | | | Since a String method cannot return an error, escape fields that may contain unsanitized values, and unescape them during parsing. Add a fuzz test to verify that calling the String method on any BuildInfo returned by Parse produces a string that parses to the same BuildInfo. (Note that this doesn't ensure that String always produces a parseable input: we assume that a user constructing a BuildInfo provides valid paths and versions, so we don't bother to escape those. It also doesn't ensure that ParseBuildInfo accepts all inputs that ought to be valid.) Fixes #51026 Change-Id: Ida18010ce47622cfedb1494060f32bd7705df014 Reviewed-on: https://go-review.googlesource.com/c/go/+/384154 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
* cmd/go: remove deleted subdirectories in 'go work use'Bryan C. Mills2022-02-084-47/+143
| | | | | | | | | | | | | | Also remove absolute names (relative to PWD) when updating relative directories, and relative names when updating absolute directories. Fixes #50959 Change-Id: If129019cad7146e82face7f23427b28240d29cfc Reviewed-on: https://go-review.googlesource.com/c/go/+/383837 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>