[go] cmd/go/internal/doc: use cfg.BuildContext instead of build.Default

3 views
Skip to first unread message

Sean Liao (Gerrit)

unread,
Dec 14, 2025, 10:37:25 AM (7 days ago) Dec 14
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Sean Liao has uploaded the change for review

Commit message

cmd/go/internal/doc: use cfg.BuildContext instead of build.Default

go/build.Default is a context that only reads from the environment,
unlike cfg.BuildContext which also uses cmd/go's config file.
"go doc" should be consistent with the other go subcommands
and use the config file.

For #76829
Change-Id: Ief6cb48424b4885dde6e3ae38d7982016a6a6964

Change diff

diff --git a/src/cmd/go/internal/doc/doc.go b/src/cmd/go/internal/doc/doc.go
index fceeaf1..2a855a1 100644
--- a/src/cmd/go/internal/doc/doc.go
+++ b/src/cmd/go/internal/doc/doc.go
@@ -21,6 +21,7 @@
"strings"

"cmd/go/internal/base"
+ "cmd/go/internal/cfg"
"cmd/internal/telemetry/counter"
)

@@ -379,7 +380,7 @@
// Done below.
case 2:
// Package must be findable and importable.
- pkg, err := build.Import(args[0], wd, build.ImportComment)
+ pkg, err := cfg.BuildContext.Import(args[0], wd, build.ImportComment)
if err == nil {
return pkg, args[0], args[1], false
}
@@ -388,7 +389,7 @@
if !ok {
break
}
- if pkg, err := build.ImportDir(packagePath, build.ImportComment); err == nil {
+ if pkg, err := cfg.BuildContext.ImportDir(packagePath, build.ImportComment); err == nil {
return pkg, arg, args[1], true
}
}
@@ -402,12 +403,12 @@
// package paths as their prefix.
var importErr error
if filepath.IsAbs(arg) {
- pkg, importErr = build.ImportDir(arg, build.ImportComment)
+ pkg, importErr = cfg.BuildContext.ImportDir(arg, build.ImportComment)
if importErr == nil {
return pkg, arg, "", false
}
} else {
- pkg, importErr = build.Import(arg, wd, build.ImportComment)
+ pkg, importErr = cfg.BuildContext.Import(arg, wd, build.ImportComment)
if importErr == nil {
return pkg, arg, "", false
}
@@ -417,7 +418,7 @@
// Kills the problem caused by case-insensitive file systems
// matching an upper case name as a package name.
if !strings.ContainsAny(arg, `/\`) && token.IsExported(arg) {
- pkg, err := build.ImportDir(".", build.ImportComment)
+ pkg, err := cfg.BuildContext.ImportDir(".", build.ImportComment)
if err == nil {
return pkg, "", arg, false
}
@@ -443,7 +444,7 @@
symbol = arg[period+1:]
}
// Have we identified a package already?
- pkg, err := build.Import(arg[0:period], wd, build.ImportComment)
+ pkg, err := cfg.BuildContext.Import(arg[0:period], wd, build.ImportComment)
if err == nil {
return pkg, arg[0:period], symbol, false
}
@@ -455,7 +456,7 @@
if !ok {
break
}
- if pkg, err = build.ImportDir(path, build.ImportComment); err == nil {
+ if pkg, err = cfg.BuildContext.ImportDir(path, build.ImportComment); err == nil {
return pkg, arg[0:period], symbol, true
}
}
@@ -463,8 +464,8 @@
}
// If it has a slash, we've failed.
if slash >= 0 {
- // build.Import should always include the path in its error message,
- // and we should avoid repeating it. Unfortunately, build.Import doesn't
+ // cfg.BuildContext.Import should always include the path in its error message,
+ // and we should avoid repeating it. Unfortunately, cfg.BuildContext.Import doesn't
// return a structured error. That can't easily be fixed, since it
// invokes 'go list' and returns the error text from the loaded package.
// TODO(golang.org/issue/34750): load using golang.org/x/tools/go/packages
@@ -505,9 +506,9 @@
return false
}

-// importDir is just an error-catching wrapper for build.ImportDir.
+// importDir is just an error-catching wrapper for cfg.BuildContext.ImportDir.
func importDir(dir string) *build.Package {
- pkg, err := build.ImportDir(dir, build.ImportComment)
+ pkg, err := cfg.BuildContext.ImportDir(dir, build.ImportComment)
if err != nil {
log.Fatal(err)
}

Change information

Files:
  • M src/cmd/go/internal/doc/doc.go
Change size: S
Delta: 1 file changed, 12 insertions(+), 11 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ief6cb48424b4885dde6e3ae38d7982016a6a6964
Gerrit-Change-Number: 729960
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
Dec 20, 2025, 6:36:28 AM (yesterday) Dec 20
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Sean Liao uploaded new patchset

Sean Liao uploaded patch set #2 to this change.
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ief6cb48424b4885dde6e3ae38d7982016a6a6964
Gerrit-Change-Number: 729960
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
Dec 20, 2025, 6:37:09 AM (yesterday) Dec 20
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Sean Liao voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ief6cb48424b4885dde6e3ae38d7982016a6a6964
Gerrit-Change-Number: 729960
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Comment-Date: Sat, 20 Dec 2025 11:37:02 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
Dec 20, 2025, 6:57:10 AM (yesterday) Dec 20
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Sean Liao

Sean Liao uploaded new patchset

Sean Liao uploaded patch set #3 to this change.
Following approvals got outdated and were removed:
  • TryBots-Pass: LUCI-TryBot-Result-1 by Go LUCI
Open in Gerrit

Related details

Attention is currently required from:
  • Sean Liao
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ief6cb48424b4885dde6e3ae38d7982016a6a6964
Gerrit-Change-Number: 729960
Gerrit-PatchSet: 3
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Attention: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
Dec 20, 2025, 7:02:55 AM (yesterday) Dec 20
to goph...@pubsubhelper.golang.org, Michael Matloob, Go LUCI, golang-co...@googlegroups.com
Attention needed from Michael Matloob

Sean Liao voted and added 1 comment

Votes added by Sean Liao

Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 3 (Latest):
Sean Liao . resolved

I'm not sure if I can write a test for this (i tried in PS 2).
`TestScript` / the luci runners sets `CGO_ENABLED` in the environment, which overrides any value set in the config file.

CGO_ENABLED seems to be the only reliable cross platform environment I could use?
The other candidates are GOOS / GOARCH / GOEXPERIMENT.

Open in Gerrit

Related details

Attention is currently required from:
  • Michael Matloob
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ief6cb48424b4885dde6e3ae38d7982016a6a6964
Gerrit-Change-Number: 729960
Gerrit-PatchSet: 3
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Sat, 20 Dec 2025 12:02:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages