Skip to content

Commit 2440717

Browse files
ConradIrwinmatloob
authored andcommitted
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 #70582 Change-Id: I3273e0ec7910894565206de77986f5c249a5658c Reviewed-on: https://go-review.googlesource.com/c/go/+/634155 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 1a193b4 commit 2440717

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/cmd/go/internal/modload/load.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,12 @@ func (ld *loader) load(ctx context.Context, pkg *loadPkg) {
18521852

18531853
var modroot string
18541854
pkg.mod, modroot, pkg.dir, pkg.altMods, pkg.err = importFromModules(ctx, pkg.path, ld.requirements, mg, ld.skipImportModFiles)
1855+
if MainModules.Tools()[pkg.path] {
1856+
// Tools declared by main modules are always in "all".
1857+
// We apply the package flags before returning so that missing
1858+
// tool dependencies report an error https://go.dev/issue/70582
1859+
ld.applyPkgFlags(ctx, pkg, pkgInAll)
1860+
}
18551861
if pkg.dir == "" {
18561862
return
18571863
}
@@ -1866,9 +1872,6 @@ func (ld *loader) load(ctx context.Context, pkg *loadPkg) {
18661872
// essentially nothing (these atomic flag ops are essentially free compared
18671873
// to scanning source code for imports).
18681874
ld.applyPkgFlags(ctx, pkg, pkgInAll)
1869-
} else if MainModules.Tools()[pkg.path] {
1870-
// Tools declared by main modules are always in "all".
1871-
ld.applyPkgFlags(ctx, pkg, pkgInAll)
18721875
}
18731876
if ld.AllowPackage != nil {
18741877
if err := ld.AllowPackage(ctx, pkg.path, pkg.mod); err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! go list all
2+
stderr 'no required module provides package example.com/tools/cmd/hello'
3+
4+
-- go.mod --
5+
go 1.24
6+
7+
module example.com/foo
8+
9+
tool example.com/tools/cmd/hello

0 commit comments

Comments
 (0)