0
1
mirror of https://github.com/golang/go synced 2025-05-24 14:55:02 +00:00

cmd/go: report tool errors in go list all

Before tools there was no way to directly import a package in another
module, and so missing packages were always marked as "all" due to being
dependencies of a package in a main module.

Tools break that assumption, and so to report errors in tool packages
correctly we need to mark packages as being in "all" even if they do not
exist.

Fixes 

Change-Id: I3273e0ec7910894565206de77986f5c249a5658c
Reviewed-on: https://go-review.googlesource.com/c/go/+/634155
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Conrad Irwin
2024-12-05 22:25:14 -07:00
committed by Michael Matloob
parent 1a193b43a2
commit 2440717918
2 changed files with 15 additions and 3 deletions
src/cmd/go
internal
modload
testdata

@ -1852,6 +1852,12 @@ func (ld *loader) load(ctx context.Context, pkg *loadPkg) {
var modroot string
pkg.mod, modroot, pkg.dir, pkg.altMods, pkg.err = importFromModules(ctx, pkg.path, ld.requirements, mg, ld.skipImportModFiles)
if MainModules.Tools()[pkg.path] {
// Tools declared by main modules are always in "all".
// We apply the package flags before returning so that missing
// tool dependencies report an error https://go.dev/issue/70582
ld.applyPkgFlags(ctx, pkg, pkgInAll)
}
if pkg.dir == "" {
return
}
@ -1866,9 +1872,6 @@ func (ld *loader) load(ctx context.Context, pkg *loadPkg) {
// essentially nothing (these atomic flag ops are essentially free compared
// to scanning source code for imports).
ld.applyPkgFlags(ctx, pkg, pkgInAll)
} else if MainModules.Tools()[pkg.path] {
// Tools declared by main modules are always in "all".
ld.applyPkgFlags(ctx, pkg, pkgInAll)
}
if ld.AllowPackage != nil {
if err := ld.AllowPackage(ctx, pkg.path, pkg.mod); err != nil {

@ -0,0 +1,9 @@
! go list all
stderr 'no required module provides package example.com/tools/cmd/hello'
-- go.mod --
go 1.24
module example.com/foo
tool example.com/tools/cmd/hello