aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
AgeCommit message (Collapse)Author
2025-07-24cmd/doc: deleteMichael Matloob
Users should not invoke "go tool doc" directly, but should instead run "go doc". Remove "cmd/doc" because it no longer invokes the "doc" tool but incorporates its logic directly. Fixes #74667 Change-Id: I357a3d7e0ca075f028df66e34951a41354c08941 Reviewed-on: https://go-review.googlesource.com/c/go/+/689835 Reviewed-by: Michael Matloob <matloob@google.com> Auto-Submit: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-06-03cmd/doc: build cmd/doc directly into the go commandMichael Matloob
There are a couple of places where our tests expect that 'go doc' doesn't need to do a build. Invoke the cmd/doc code directly by the go command instead of starting the doc tool in a separate process so we can preserve that property. This change moves most of the doc code into the package cmd/internal/doc, and exposes a Main function from that function that's called both by the cmd/doc package, and by go doc. This change makes couple of additional changes to intergrate doc into the go command: The counter.Open call and the increment of invocations counter are only needed by cmd/doc. The go command will open the counters file and increment a counter for the doc subcommand. We add a cmd_go_bootstrap tagged variant of the file that defines go doc so that we don't end up linking net into the bootstrap version of the go command. We don't need doc in that version of the command. We create a new flagSet rather than using flag.CommandLine because when running as part of the go command, the flags to "go doc" won't be the top level flags. We change TestGoListTest in go_test.go to use gofmt instead of doc as an example of a main package in cmd with an in-package test. For #71867 Change-Id: I3e3df83e5fa266559606fdc086b461165e09f037 Reviewed-on: https://go-review.googlesource.com/c/go/+/677775 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Matloob <matloob@google.com>
2025-05-22cmd/doc: properly set GOPROXY to avoid deprecation checksMichael Matloob
This change fixes a bug that was introduced in CL 675155. Instead of doing the two step download and run with GOPROXY=off, do the run with GOPROXY=<download cache>:$GOPROXY, so that we use the previously downloaded version of pkgsite as the latest. Fixes #73833 Change-Id: I8803426498ab026602805d6448a130eb11458c99 Reviewed-on: https://go-review.googlesource.com/c/go/+/675576 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-22Revert "cmd/doc: better support for no network"Michael Matloob
This reverts commit 988eb0d11e8d96e8ca150f401ed82326b276f653. Reason for revert: breaks viewing documentation for unfetched modules For #73833 Change-Id: I89bc459e820c85e96837d1707058501488a14eef Reviewed-on: https://go-review.googlesource.com/c/go/+/675575 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com>
2025-05-21cmd/doc: better support for no networkMichael Matloob
Allow skipping the deprecation check when GOPROXY=off. The deprecation check is an informational message so this doesn't affect the success of the command. We should probably skip the check in more cases when GOPROXY=off but that's a bigger change that should be made in a later release. There are still some deps.dev log messages that we should try to suppress. For #68106 Change-Id: Ifa0efd01ed623bb68c7ad7c5cfb6705547d157a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/675155 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Matloob <matloob@google.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
2025-05-21cmd/doc: add more convenient behavior for go doc -http with no argsMichael Matloob
If we're in a module, go to the module's page. Outside of a module, but in a workspace go to the home page, and outside of a module or workspace, show the stdlib docs. For #68106 Change-Id: I911a90a0e2b0a2bbb622f56e32827d5bdfa7f2fd Reviewed-on: https://go-review.googlesource.com/c/go/+/675235 Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-05-21cmd/doc: allow go doc -http without package in current directoryMichael Matloob
go doc tries to find a package to display documentation for. In the case that no package is provided, it uses "." just like go list does. So if go doc -http is run without any arguments, it tries to show the documentation for the package in the current directory. As a special case, if no arguments are provided, allow no package to match the current directory and just open the root pkgsite page. For #68106 Change-Id: I6d65b160a838591db953fac630eced6b09106877 Reviewed-on: https://go-review.googlesource.com/c/go/+/675075 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-20cmd/doc: use golang.org/x/pkgsite/cmd/internal/doc to start serverMichael Matloob
This change switches the pkgsite command invoked to start a pkgsite server from golang.org/x/pkgsite/cmd/pkgsite to golang.org/x/pkgsite/cmd/internal/doc. The doc command is a simplified version of cmd/pkgsite that changes some options to improve the user experience. For example, it limits logging informational log messages, doesn't always expect to find modules (for example if we're outside of a module getting documentation for the standard library), and it takes the address of the page to open in the browser (which simplifies waiting for the server to start listening). Fixes #68106 Change-Id: I667a49d03823242fa1aff333ecb1c0f198e92412 Reviewed-on: https://go-review.googlesource.com/c/go/+/674158 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-05-20cmd/doc: use go list to determine import path if it's missingMichael Matloob
cmd/doc uses go/build to get information about the packages it's documenting. In some cases, go/build can return a build.Package that it couldn't determine an import path for, in which case it sets the import path to ".". This can happen for relative package paths in in a module: for relative package paths we don't use the go command to get information about the module and just open the source files directly instead, and will be missing the import path. This is usually okay because go doc doesn't need to print the import path of the package it's documenting, but for go doc -http, we want to know the import path so we can open the right page in the browser. For #68106 Change-Id: Ifba92862ad01d8d63f531c2451f18db2b0d7a3e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/674556 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Michael Matloob <matloob@google.com>
2025-05-20cmd/doc: show page for the requested objectMichael Matloob
This fixes a bug where we start pkgsite for every requested object, rather than the one that we would have printed the documentation for. To make things simple, we'll run the logic that prints the documentation, but with an io.Discard writer. Then we can tell if the documentation was found based on the return values of those functions. For #68106 Change-Id: Ibf2ab1720f381d7214fc9239b9c2e915c91f7f7b Reviewed-on: https://go-review.googlesource.com/c/go/+/674555 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-03cmd/doc: add support for starting pkgsite instance for docsMichael Matloob
This change adds a new flag "-http" to cmd/doc which enables starting a pkgsite instance. -http will start a pkgsite instance and navigate to the page for the requested package, at the anchor for the item requested. For #68106 Change-Id: Ic1c113795cb2e1035e99c89c8e972c799342385b Reviewed-on: https://go-review.googlesource.com/c/go/+/628175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sam Thanawalla <samthanawalla@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2024-09-04all: use t.Chdir in testsKir Kolyshkin
Change-Id: I5bc514bedeb1155e6db52e37736fd6101774aea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/529896 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@golang.org>
2024-06-21cmd/internal: separate counter package from telemetry packageMichael Matloob
Move the code that opens and increments counters out of the cmd/internal/telemetry package into cmd/internal/telemetry/counter. The telemetry package has dependencies on the upload code, which we do not want to pull into the rest of the go toolchain. For #68109 Change-Id: I463c106819b169177a783de4a7d93377e81f4e3e Reviewed-on: https://go-review.googlesource.com/c/go/+/593976 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
2024-06-13cmd/go: call telemetry.MaybeChild at start of go commandMichael Matloob
Call the new telemetry.MaybeChild function at the start of the go command so that the child process logic can be run immediately without running toolchain selection if this is the child process. The Start function in the telemetry shim package has been renamed to OpenCounters to make it clear that that's its only function. The StartWithUpload function in the telemetry shim package has been renamed to MaybeParent because that's its actual effective behavior in cmd/go, the only place it's called: it won't run as the child because MaybeChild has already been called and would have run as the child if the program was the telemetry child, and it won't open counters because telemetry.Start has been called. Checks are added that those functions are always called before so that the function name and comment are accurate. It might make sense to add a true telemetry.MaybeParent function that doesn't try to start the child or open counters to make things a little simpler. Change-Id: Ie81e2418af85cef18ec41f75db66365f6597b8b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/592535 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-14cmd: add telemetry for commands in cmdMichael Matloob
This change modifies the commands in cmd to open counter files, increment invocations counters and to increment counters for the names of the flags that were passed in. cmd/pprof and cmd/vet are both wrappers around tools defined in other modules which do their own flag processing so we can't directly increment flag counters right after flags are parsed. For those two commands we wait to increment counters until after the programs have returned. cmd/dist is built with the bootstrap go so it can't depend on telemetry yet. We can add telemetry support to it once 1.23 is the minimum bootstrap version. For #58894 Change-Id: Ic7f6009992465e55c56ad4dc6451bcb1ca51374a Reviewed-on: https://go-review.googlesource.com/c/go/+/585235 Reviewed-by: Sam Thanawalla <samthanawalla@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-08cmd/doc: fix inconsistent receiver nameMehdi Mostafavi
The ToText method of Package is the only one with a receiver declared 'p'; all the rest have 'pkg'. Fix it to be consistent. Change-Id: I2b47c719f4f6f8d87336316b7f80deb1b49e17dc GitHub-Last-Rev: 7d273b4ef0780b7ed8b651c117a28b25bab5bcb1 GitHub-Pull-Request: golang/go#64912 Reviewed-on: https://go-review.googlesource.com/c/go/+/553335 Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2023-09-07cmd/doc: print bugs with -all flagPascal S. de Kloe
Includes cleanup and deduplication. fixes: #33970 Change-Id: I7e84b3e5c8fb9c560cf0a1f8b7cbb7a6977666aa Reviewed-on: https://go-review.googlesource.com/c/go/+/511935 Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-04-10cmd/doc: format field doc comments when printing entire structIan Lance Taylor
cmd/doc passes structs to go/format, but that means that comments on fields within those structs don't look like what cmd/doc prints when asked for a struct field directly. Tweak the field comments so that they look the same either way. Fixes #56592 Change-Id: I198cb7a58e3d8558406c386072c630332f91c6b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/483055 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2022-11-03cmd/go: add -C flagRuss Cox
The -C flag is like tar -C or make -C: it changes to the named directory early in command startup, before anything else happens. Fixes #50332. Change-Id: I8e4546f69044cb3a028d4d26dfba482b08cb845d Reviewed-on: https://go-review.googlesource.com/c/go/+/421436 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
2022-09-06cmd/doc: use strings.Buildercuiweixie
Change-Id: Ib33d1f1c2e9aed0cb9e00bd699c4ae4a2df5dfca Reviewed-on: https://go-review.googlesource.com/c/go/+/428288 Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Rob Pike <r@golang.org> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-02all: use os/exec instead of internal/execabsRuss Cox
We added internal/execabs back in January 2021 in order to fix a security problem caused by os/exec's handling of the current directory. Now that os/exec has that code, internal/execabs is superfluous and can be deleted. This commit rewrites all the imports back to os/exec and deletes internal/execabs. For #43724. Change-Id: Ib9736baf978be2afd42a1225e2ab3fd5d33d19df Reviewed-on: https://go-review.googlesource.com/c/go/+/381375 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-11cmd/doc: use new go/doc APIsRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Use the new per-Package go/doc API instead of the top-level functions from go/doc. These handle links better. For #51082. Change-Id: I169b46d973673abdb6f126352c9f1e30f9fe1122 Reviewed-on: https://go-review.googlesource.com/c/go/+/384266 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-18internal/testenv: add GOROOT and use it to fix tests broken with -trimpathBryan C. Mills
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>
2022-03-17cmd/doc: use the 'go' command from buildCtx.GOROOT, not whatever is in $PATHBryan C. Mills
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>
2022-03-17cmd/doc: use 'go env' to identify GOROOT if it isn't otherwise knownBryan C. Mills
Updates #51483. Change-Id: I13d8e58b30639d8a5ed3c9e8b72c8bbaa6a6f1cc Reviewed-on: https://go-review.googlesource.com/c/go/+/391813 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>
2021-12-20cmd/doc: don't log on constraint type elementsIan Lance Taylor
Fixes #50256 Change-Id: I2327a0b28f8173c801ed2946bec8083967667027 Reviewed-on: https://go-review.googlesource.com/c/go/+/373314 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-26cmd/doc: fix "builtin" package parsingRoi Martin
As stated in the code, "The builtin package needs special treatment: its symbols are lower case but we want to see them, always". Thus, cmd/doc forces the -u flag if the package being queried is called "builtin". However, this happens after having already parsed the package. This CL forces the -u flag just after parsing the command arguments and before parsing any package. Fixes #49796. Change-Id: If690a900c7cfd1700feecb9529bd4344c3c249d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/367134 Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-11-04cmd/doc, go/doc: add basic support for generic codeRobert Findley
Update cmd/doc and go/doc for the generics, by adding handling for type parameters and the new embedded interface elements. Specifically: - Format type parameters when summarizing type and function nodes. - Find the origin type name for instantiation expressions, so that methods are associated with generic type declarations. - Generalize the handling of embedding 'error' in interfaces to arbitrary predeclared types. - Keep embedded type literals. - Update filtering to descend into embedded type literals. Also add "any" to the list of predeclared types. Updates #49210 Change-Id: I6ea82869f19c3cdbc3c842f01581c8fc7e1c2ee7 Reviewed-on: https://go-review.googlesource.com/c/go/+/359778 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-10-06all: use bytes.Cut, strings.CutRuss Cox
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-19cmd/doc: properly display interface methodsAgniva De Sarker
Previously, we used to call doc.ToText to print each comment in a comment group attached to an interface method. This broke any preformatted code block attached to the comment, and displayed everything aligned to a single column. Additionally, the name of the interface also wasn't displayed which didn't show which interface the method belonged to. To fix this, we print the entire interface node using format.Node which takes care of displaying the comments correctly, and we also filter out the methods that don't match, so that the method can be displayed as belonging to an interface. As an example, previously it would show: // Comment before exported method. // // // Code block showing how to use ExportedMethod // func DoSomething() error { // ExportedMethod() // return nil // } func ExportedMethod() // Comment on line with exported method. Now, it shows: type ExportedInterface interface { // Comment before exported method. // // // Code block showing how to use ExportedMethod // func DoSomething() error { // ExportedMethod() // return nil // } ExportedMethod() // Comment on line with exported method. } Fixes #43188 Change-Id: I28099fe4aab35e08049b2616a3506240f57133cc Reviewed-on: https://go-review.googlesource.com/c/go/+/279433 Trust: Agniva De Sarker <agniva.quicksilver@gmail.com> Trust: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Rob Pike <r@golang.org>
2021-01-21all: introduce and use internal/execabsRoland Shoemaker
Introduces a wrapper around os/exec, internal/execabs, for use in all commands. This wrapper prevents exec.LookPath and exec.Command from running executables in the current directory. All imports of os/exec in non-test files in cmd/ are replaced with imports of internal/execabs. This issue was reported by RyotaK. Fixes CVE-2021-3115 Fixes #43783 Change-Id: I0423451a6e27ec1e1d6f3fe929ab1ef69145c08f Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/955304 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/284783 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-06all: enable more tests on macOS/ARM64Cherry Zhang
Updates #38485. Change-Id: Iac96f5ffe88521fcb11eab306d0df6463bdce046 Reviewed-on: https://go-review.googlesource.com/c/go/+/256920 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-09-23all: add GOOS=iosCherry Zhang
Introduce GOOS=ios for iOS systems. GOOS=ios matches "darwin" build tag, like GOOS=android matches "linux" and GOOS=illumos matches "solaris". Only ios/arm64 is supported (ios/amd64 is not). GOOS=ios and GOOS=darwin remain essentially the same at this point. They will diverge at later time, to differentiate macOS and iOS. Uses of GOOS=="darwin" are changed to (GOOS=="darwin" || GOOS=="ios"), except if it clearly means macOS (e.g. GOOS=="darwin" && GOARCH=="amd64"), it remains GOOS=="darwin". Updates #38485. Change-Id: I4faacdc1008f42434599efb3c3ad90763a83b67c Reviewed-on: https://go-review.googlesource.com/c/go/+/254740 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2020-04-17cmd/doc: don't print package clauses on errorRob Pike
Everybody was deferring a flush when main already did that, so drop all that nonsense. (Flush was doing the package clause stuff.) But then make sure we do get a package clause when there is correctly no output, as for an empty package. Do that by triggering a package clause in allDoc and packageDoc. Slightly tricky but way less intricate than before. Fixes #37969. Change-Id: Ia86828436e6c4ab46e6fdaf2c550047f37f353f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/226998 Reviewed-by: Russ Cox <rsc@golang.org>
2020-04-08all: remove scattered remnants of darwin/armAustin Clements
This removes all conditions and conditional code (that I could find) that depended on darwin/arm. Fixes #35439 (since that only happened on darwin/arm) Fixes #37611. Change-Id: Ia4c32a5a4368ed75231075832b0b5bfb1ad11986 Reviewed-on: https://go-review.googlesource.com/c/go/+/227198 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-03-05cmd/doc: fix merging comments in -src modeIvan Trubach
These changes fix go doc -src mode that vomits comments from random files if filesystem does not sort files by name. The issue was with parse.ParseDir using the Readdir order of files, which varies between platforms and filesystem implementations. Another option is to merge comments using token.FileSet.Iterate order in cmd/doc, but since ParseDir is mostly used in go doc, I’ve opted for smaller change because it’s unlikely to break other uses or cause any perfomance issues. Example (macOS APFS): `go doc -src net.ListenPacket` Change-Id: I7f9f368c7d9ccd9a2cbc48665f2cb9798c7b3a3f GitHub-Last-Rev: 654fb450421266a0bb64518016944db22bd681e3 GitHub-Pull-Request: golang/go#36104 Reviewed-on: https://go-review.googlesource.com/c/go/+/210999 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-12-18cmd/doc: flag usage() inconsistencyGert Cuykens
Inconsistency between cmd/doc/main.go and cmd/go/internal/doc/doc.go Fixes #34976 Change-Id: I429200f9305d473edb4505216bb4840ba92af818 Reviewed-on: https://go-review.googlesource.com/c/go/+/201857 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-11-12cmd/doc: show the package clause alwaysAgniva De Sarker
If no writes to the package buffer happen, then the package clause does not get printed. This is a bug for cases where a file just contains the package clause. We fix this by separating the printing of package clause to a new function and calling it from (*pkgBuffer).Write as well as (*Package).flush. Updates #31457 Change-Id: Ia3bd0ea3963274c460a45d1e37fafc6ee0a197f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/206128 Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-11-12cmd/doc: show variables of unexported types for -allAgniva De Sarker
We use the typedValue map to prevent showing typed variables and constants from appearing in the VARIABLES/CONSTANTS section because they will be anyways shown in the TYPES section for that type. However, when a type is unexported, but the variable is exported, then unconditionally setting it to true in the map suppresses it from being shown in the VARIABLES section. Thus, we set the variable or constant in the typedValue map only when the type name is exported. Fixes #31067 Change-Id: Id3ec4b313c9ea7e3ce6fe279680d56f65451719f Reviewed-on: https://go-review.googlesource.com/c/go/+/206129 Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-07cmd/doc: don't bother checking validity of symbols at top levelRob Pike
No need to check as pieces further down do so anyway: % go doc '&&.%$^' doc: symbol && is not a type in package fmt installed in "fmt" exit status 1 % Removing this check allows 'go doc sort.interface' or 'go doc types.type' to discover sort.Interface and go/types.Type. Easily Fixes #34656. Change-Id: I84352e83dd7f91a232f45a44d1a52f019a1a9a06 Reviewed-on: https://go-review.googlesource.com/c/go/+/205778 Reviewed-by: Caleb Spare <cespare@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
2019-11-06cmd/doc: understand vendor directories in module modeBryan C. Mills
This change employs the same strategy as in CL 203017 to detect when vendoring is in use, and if so treats the vendor directory as a (non-module, prefixless) root. The integration test also verifies that the 'std' and 'cmd' modules are included and their vendored dependencies are visible (as they are with 'go list') even when outside of those modules. Fixes #35224 Change-Id: I18cd01218e9eb97c1fc6e2401c1907536b0b95f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/205577 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-11-06cmd/doc: avoid calling token.IsExported on non-tokensBryan C. Mills
token.IsExported expects to be passed a token, and does not check for non-token arguments such as "C:\workdir\go\src\text". While we're at it, clean up a few other parts of the code that are assuming a package path where a directory may be passed instead. There are probably others lurking around here, but I believe this change is sufficient to get past the test failures on the windows-amd64-longtest builder. Fixes #35236 Change-Id: Ic79fa035531ca0777f64b1446c2f9237397b1bdf Reviewed-on: https://go-review.googlesource.com/c/go/+/204442 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-10cmd/go: forbid module pattern 'all' when outside a moduleJay Conrod
Also, in cmd/doc, avoid calling 'go list -m all' when in module mode outside a module since it's now an error. Fixes #32027 Change-Id: I7224c7fdf7e950bce6c058ab2a5837c27ba3b899 Reviewed-on: https://go-review.googlesource.com/c/go/+/200297 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-10-09cmd/doc: show original import error when package cannot be foundJay Conrod
Updates #34669 Change-Id: I8d0ee68885e804e131f42a512080486f9b25e9dd Reviewed-on: https://go-review.googlesource.com/c/go/+/199819 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-10-09all: remove the nacl port (part 1)Brad Fitzpatrick
You were a useful port and you've served your purpose. Thanks for all the play. A subsequent CL will remove amd64p32 (including assembly files and toolchain bits) and remaining bits. The amd64p32 removal will be separated into its own CL in case we want to support the Linux x32 ABI in the future and want our old amd64p32 support as a starting point. Updates #30439 Change-Id: Ia3a0c7d49804adc87bf52a4dea7e3d3007f2b1cd Reviewed-on: https://go-review.googlesource.com/c/go/+/199499 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-19cmd/doc: add option to output a clean one-line symbol representationGert Cuykens
Currently there is no way for go doc to output a clean one-line symbol representation of types, functions, vars and consts without documentation lines or other text lines added. For example `go doc fmt` has a huge introduction so if you pass that to grep or fzf to search a symbol let say scan `go doc fmt | grep scan` you get way to many false positives. Added a `-short` flag to be able to do `go doc -short fmt | grep scan` instead which will result in just the symbols you are looking for. func Fscan(r io.Reader, a ...interface{}) (n int, err error) func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error) func Fscanln(r io.Reader, a ...interface{}) (n int, err error) func Sscan(str string, a ...interface{}) (n int, err error) func Sscanf(str string, format string, a ...interface{}) (n int, err error) func Sscanln(str string, a ...interface{}) (n int, err error) Fixes #32597 Change-Id: I77a73838adc512c8d1490f5a82075de6b0462a31 Reviewed-on: https://go-review.googlesource.com/c/go/+/184017 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-06-28cmd/doc: provide working directory to build.Import callsDmitri Shuralyov
The current cmd/doc implementation uses go/build.Import in a few places to check whether a package is findable and importable. go/build has limited support for finding packages in modules, but to do so, build.Import requires knowing the source directory to use when performing the lookup (so it can find the go.mod file). Otherwise, it only looks inside the GOPATH workspace. Start passing the current working directory to build.Import calls, so that it can correctly look for packages in modules when in cmd/doc is executed in module mode. Before this change, cmd/doc in module mode could mistakenly find and use a package in the GOPATH workspace, instead of the current module. Since the result of os.Getwd is needed in even more places, assign it to a local variable in parseArgs now. Fixes #28992 Updates #26504 Change-Id: I7571618e18420d2d3b3890cc69ade2d97b1962bf Reviewed-on: https://go-review.googlesource.com/c/go/+/183991 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>