aboutsummaryrefslogtreecommitdiff
path: root/internal/fetch
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-06-10 13:37:23 -0700
committerGopher Robot <gobot@golang.org>2025-06-11 11:17:28 -0700
commitac5509ca2c6f5fe7909cfc831e11bd17f6bb796a (patch)
tree528fac306c621edde05e6a59b366e6d91981818b /internal/fetch
parent77fcf55b4a93360dc99c9f5b5f7a07d850cb2c49 (diff)
downloadgo-x-pkgsite-ac5509ca2c6f5fe7909cfc831e11bd17f6bb796a.tar.xz
internal/fetch: don't include goexperiment.jsonv2 for encoding/json
Setting the goexperiment.jsonv2 constraint switches the encoding/json package over to the new, experimental implementation, which has both documentation differences and API additions. We don't want to display this for most users, so only enable the goexperiment.jsonv2 constraint when loading entirely new packages that use it. For golang/go#71488. For golang/go#71845. Change-Id: Id69878e2948dea07245eb3d9bf3bb04cfed15e2d Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/680675 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'internal/fetch')
-rw-r--r--internal/fetch/load.go13
-rw-r--r--internal/fetch/load_test.go22
2 files changed, 26 insertions, 9 deletions
diff --git a/internal/fetch/load.go b/internal/fetch/load.go
index 9069743d..7818d7dd 100644
--- a/internal/fetch/load.go
+++ b/internal/fetch/load.go
@@ -79,7 +79,7 @@ func loadPackage(ctx context.Context, contentDir fs.FS, goFilePaths []string, in
// track of those to avoid duplication.
docsByFiles := map[string]*internal.Documentation{}
for _, bc := range internal.BuildContexts {
- mfiles, err := matchingFiles(bc.GOOS, bc.GOARCH, files)
+ mfiles, err := matchingFiles(bc.GOOS, bc.GOARCH, importPath, files)
if err != nil {
return nil, err
}
@@ -213,7 +213,7 @@ func loadPackageMeta(ctx context.Context, contentDir fs.FS, goFilePaths []string
// in the file and then run the logic in loadPackageName on the collection of
// package name values.
for _, bc := range internal.BuildContexts {
- mfiles, err := matchingFiles(bc.GOOS, bc.GOARCH, files)
+ mfiles, err := matchingFiles(bc.GOOS, bc.GOARCH, importPath, files)
if err != nil {
return nil, err
}
@@ -408,7 +408,7 @@ func loadPackageName(innerPath string, files map[string][]byte) (pkgName string,
// matchingFiles returns a map from file names to their contents, read from zipGoFiles.
// It includes only those files that match the build context determined by goos and goarch.
-func matchingFiles(goos, goarch string, allFiles map[string][]byte) (matchedFiles map[string][]byte, err error) {
+func matchingFiles(goos, goarch string, importPath string, allFiles map[string][]byte) (matchedFiles map[string][]byte, err error) {
defer derrors.Wrap(&err, "matchingFiles(%q, %q, zipGoFiles)", goos, goarch)
// bctx is used to make decisions about which of the .go files are included
@@ -418,7 +418,7 @@ func matchingFiles(goos, goarch string, allFiles map[string][]byte) (matchedFile
GOARCH: goarch,
CgoEnabled: true,
Compiler: build.Default.Compiler,
- BuildTags: []string{"goexperiment.jsonv2", "goexperiment.synctest"},
+ BuildTags: []string{"goexperiment.synctest"},
ReleaseTags: build.Default.ReleaseTags,
JoinPath: path.Join,
@@ -437,6 +437,11 @@ func matchingFiles(goos, goarch string, allFiles map[string][]byte) (matchedFile
ReadDir: func(string) ([]os.FileInfo, error) { panic("internal error: unexpected call to ReadDir") },
}
+ switch importPath {
+ case "encoding/json/v2", "encoding/json/jsontext":
+ bctx.BuildTags = append(bctx.BuildTags, "goexperiment.jsonv2")
+ }
+
// Copy the input map so we don't modify it.
matchedFiles = map[string][]byte{}
for n, c := range allFiles {
diff --git a/internal/fetch/load_test.go b/internal/fetch/load_test.go
index 4d907c39..e1643845 100644
--- a/internal/fetch/load_test.go
+++ b/internal/fetch/load_test.go
@@ -59,6 +59,7 @@ func TestMatchingFiles(t *testing.T) {
for _, test := range []struct {
name string
goos, goarch string
+ importPath string
contents map[string]string
want map[string][]byte
}{
@@ -107,10 +108,21 @@ func TestMatchingFiles(t *testing.T) {
},
},
{
- name: "jsonv2",
- goos: "linux",
- goarch: "amd64",
- contents: jsonv2Contents,
+ name: "json",
+ goos: "linux",
+ goarch: "amd64",
+ importPath: "encoding/json",
+ contents: jsonv2Contents,
+ want: map[string][]byte{
+ "plain.go": []byte(plainGoBody),
+ },
+ },
+ {
+ name: "jsonv2",
+ goos: "linux",
+ goarch: "amd64",
+ importPath: "encoding/json/v2",
+ contents: jsonv2Contents,
want: map[string][]byte{
"plain.go": []byte(plainGoBody),
"json.go": []byte(jsonv2Body),
@@ -122,7 +134,7 @@ func TestMatchingFiles(t *testing.T) {
for n, c := range test.contents {
files[n] = []byte(c)
}
- got, err := matchingFiles(test.goos, test.goarch, files)
+ got, err := matchingFiles(test.goos, test.goarch, test.importPath, files)
if err != nil {
t.Fatal(err)
}