golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.07k stars 17.68k forks source link

x/tools/cmd/godoc: add -tags like go build #3398

Open ugorji opened 12 years ago

ugorji commented 12 years ago
Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull", "hg update default", rebuild, and
retry
what you did to reproduce the problem.  Thanks.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Run godoc on a package having some files with build constraints e.g. // +build ignore
2. The files are skipped by godoc and their contents are not reflected in godoc output.
I don't see the files listed either.
3.

What is the expected output?

I expected to see the information in godoc.

What do you see instead?
Nothing.

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Linux

Which version are you using?  (run 'go version')
Running at tip, but go version gives:
go version weekly.2012-03-22 +de7e784537ac

Please provide any additional information below.
rsc commented 12 years ago

Comment 1:

godoc ignores files that say "// +build ignore".
It uses the files that would be built by go build.
That seems like it is working as intended.
Maybe after Go 1 we could give godoc a flag to
allow the specification of additional build tags,
like go build's -tags.
Russ

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

ugorji commented 12 years ago

Comment 2:

That would be nice.
I stumbled upon this because I tagged some of my code which should only run on an
appengine instance with // +build appengine. After that, I couldn't see them anymore
using godoc. My only solution seemed to be to remove the build constraints.
rsc commented 12 years ago

Comment 3:

Labels changed: added go1.1maybe.

rsc commented 11 years ago

Comment 4:

Labels changed: added size-m.

rsc commented 11 years ago

Comment 5:

[The time for maybe has passed.]

Labels changed: removed go1.1maybe.

adg commented 11 years ago

Comment 6:

Labels changed: added godoc.

rsc commented 11 years ago

Comment 7:

Labels changed: added go1.2.

rsc commented 11 years ago

Comment 8:

Labels changed: added feature.

robpike commented 11 years ago

Comment 9:

This would be nice, but it won't happen for Go 1.2.

Labels changed: removed go1.2.

rsc commented 10 years ago

Comment 10:

Labels changed: added go1.3maybe.

rsc commented 10 years ago

Comment 11:

Labels changed: removed feature.

rsc commented 10 years ago

Comment 12:

Labels changed: added release-none, removed go1.3maybe.

rsc commented 10 years ago

Comment 13:

Labels changed: added repo-tools.

jeffallen commented 6 years ago

If you are someone like me who just stumbled across this old bug and are looking for a quick hack to solve your problem right now, use "go get golang.org/x/tools" to get the godoc source code then hack it like this:

diff --git a/godoc/server.go b/godoc/server.go
index 3b452e5e..d231425e 100644
--- a/godoc/server.go
+++ b/godoc/server.go
@@ -64,6 +64,7 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode,
    // Note: If goos/goarch aren't set, the current binary's GOOS/GOARCH
    // are used.
    ctxt := build.Default
+   ctxt.BuildTags = []string{"vartime"}
    ctxt.IsAbsPath = pathpkg.IsAbs
    ctxt.IsDir = func(path string) bool {
        fi, err := h.c.fs.Stat(filepath.ToSlash(path))

Then use "go build" to build a local copy of godoc that is using the build tags you need.

gopherbot commented 6 years ago

Change https://golang.org/cl/129099 mentions this issue: x/tools/cmd/godoc: add -tags like go build

SchumacherFM commented 6 years ago

Good evening,

as I currently need this feature in godoc to display documentation for specific build tags, I've added it to godoc. It took me a couple of days and I think it is ready for review 😊. See the CL https://golang.org/cl/129099

Below I've added some printscreens how the design looks like for HTML and CLI. If there are better ideas to display the build tag information, let me know.

It would be great if some one from the Go Team, etc can review the code.

screen shot 2018-08-12 at 7 43 40 pm

screen shot 2018-08-12 at 7 45 09 pm

screen shot 2018-08-12 at 7 45 41 pm

screen shot 2018-08-12 at 7 46 01 pm

screen shot 2018-08-12 at 7 47 45 pm

screen shot 2018-08-12 at 7 48 29 pm

screen shot 2018-08-12 at 7 50 54 pm