]> Cypherpunks repositories - gostls13.git/commit
cmd/doc: build cmd/doc directly into the go command
authorMichael Matloob <matloob@golang.org>
Fri, 30 May 2025 22:20:05 +0000 (18:20 -0400)
committerMichael Matloob <matloob@google.com>
Tue, 3 Jun 2025 18:28:46 +0000 (11:28 -0700)
commit94764d093822721337243de77aeba72df1f9b230
tree8798a184a7ce2e2aa37702900ef781686e302556
parent74b70eead70872ccb0b7bfe0435ef3e4a1eb288e
cmd/doc: build cmd/doc directly into the go command

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>
16 files changed:
src/cmd/doc/doc.go [new file with mode: 0644]
src/cmd/go/go_test.go
src/cmd/go/internal/doc/doc.go
src/cmd/go/internal/doc/doc_bootstrap.go [new file with mode: 0644]
src/cmd/internal/doc/dirs.go [moved from src/cmd/doc/dirs.go with 99% similarity]
src/cmd/internal/doc/doc_test.go [moved from src/cmd/doc/doc_test.go with 99% similarity]
src/cmd/internal/doc/main.go [moved from src/cmd/doc/main.go with 89% similarity]
src/cmd/internal/doc/pkg.go [moved from src/cmd/doc/pkg.go with 99% similarity]
src/cmd/internal/doc/signal_notunix.go [moved from src/cmd/doc/signal_notunix.go with 95% similarity]
src/cmd/internal/doc/signal_unix.go [moved from src/cmd/doc/signal_unix.go with 95% similarity]
src/cmd/internal/doc/testdata/merge/aa.go [moved from src/cmd/doc/testdata/merge/aa.go with 100% similarity]
src/cmd/internal/doc/testdata/merge/bb.go [moved from src/cmd/doc/testdata/merge/bb.go with 100% similarity]
src/cmd/internal/doc/testdata/nested/empty/empty.go [moved from src/cmd/doc/testdata/nested/empty/empty.go with 100% similarity]
src/cmd/internal/doc/testdata/nested/ignore.go [moved from src/cmd/doc/testdata/nested/ignore.go with 100% similarity]
src/cmd/internal/doc/testdata/nested/nested/real.go [moved from src/cmd/doc/testdata/nested/nested/real.go with 100% similarity]
src/cmd/internal/doc/testdata/pkg.go [moved from src/cmd/doc/testdata/pkg.go with 100% similarity]