diff options
author | Dmitri Shuralyov <dmitshur@golang.org> | 2020-02-07 11:15:11 -0500 |
---|---|---|
committer | Dmitri Shuralyov <dmitshur@golang.org> | 2020-02-10 19:49:03 +0000 |
commit | 6a8164a254117729104f70aecb47ecf481263c8d (patch) | |
tree | 5f36511bf4f9190b81e1adb50f4c5f5d22fa3b6a | |
parent | dff55c1f7605294568ae7e00b09ef8935dbedf3b (diff) | |
download | go-6a8164a254117729104f70aecb47ecf481263c8d.tar.gz go-6a8164a254117729104f70aecb47ecf481263c8d.zip |
go/doc: clarify that NewFromFiles caller must filter by GOOS/GOARCH
The most well known and important build constraints to take into
account when rendering package documentation are the GOOS/GOARCH
values. Make it more clear in the NewFromFiles documentation that
they are a part of all build constraints that the caller is
responsible for filtering out.
Also suggest the "go/build".Context.MatchFile method for performing
file matching. The logic to perform build context file matching is
subtle and has many rules that aren't well known (for example,
taking the gc or gccgo compiler into account). It is currently the
only exported API in the standard library that implements this logic,
and it would be unfortunate if people attempt to re-create it because
they don't realize it is already available.
Updates #23864
Change-Id: I3c5901e7081acf79125b2d429ec3aa3b58416ed7
Reviewed-on: https://go-review.googlesource.com/c/go/+/218477
Reviewed-by: Robert Griesemer <gri@golang.org>
-rw-r--r-- | src/go/doc/doc.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/go/doc/doc.go b/src/go/doc/doc.go index 0e50af04f6..79d38998e7 100644 --- a/src/go/doc/doc.go +++ b/src/go/doc/doc.go @@ -138,9 +138,12 @@ func New(pkg *ast.Package, importPath string, mode Mode) *Package { // NewFromFiles computes documentation for a package. // // The package is specified by a list of *ast.Files and corresponding -// file set, which must not be nil. NewFromFiles does not skip files -// based on build constraints, so it is the caller's responsibility to -// provide only the files that are matched by the build context. +// file set, which must not be nil. +// NewFromFiles uses all provided files when computing documentation, +// so it is the caller's responsibility to provide only the files that +// match the desired build context. "go/build".Context.MatchFile can +// be used for determining whether a file matches a build context with +// the desired GOOS and GOARCH values, and other build constraints. // The import path of the package is specified by importPath. // // Examples found in _test.go files are associated with the corresponding |