You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for the NeedDeps field is unclear. It says:
// NeedDeps adds the fields requested by the LoadMode in the packages in Imports.
I think perhaps the idea might be more clearly expressed as:
// NeedDeps causes all Packages transitively reachable through
// the Imports map to also be populated according to the LoadMode.
but that isn't what actually happens. Observe:
xtools$ cat main.go
package main
import (
"fmt"
"log"
"golang.org/x/tools/go/packages"
)
func main() {
cfg := &packages.Config{
Mode: packages.NeedImports |
packages.NeedCompiledGoFiles |
//packages.NeedDeps | // try with and without this line
0,
}
pkgs, err := packages.Load(cfg, "runtime")
if err != nil {
log.Fatalf("load: %v", err)
}
packages.Visit(pkgs, nil, func(p *packages.Package) {
fmt.Println(p, len(p.CompiledGoFiles))
})
}
xtools$ go run ./main.go > with
# Now uncomment the NeedDeps line.
xtools$ go run ./main.go > without
xtools$ diff with without
xtools$
# nothing
In other words, the NeedDeps flag seems to have no effect when the NeedImports flag is set. And If you remove NeedImports, only a single package is reported, regardless of NeedDeps. It's as if the flag has no effect at all.
I would expect the following behaviors:
Imports=true, deps=true: import graph fully populated according to mode bits
imports=true, deps=false: import map is populated to depth 1; dependencies may be stubs.
imports=false: import map is nil. Deps flag has no effect.
The text was updated successfully, but these errors were encountered:
gopherbot
added
the
Tools
This label describes issues relating to any tools in the x/tools repository.
label
Nov 7, 2022
The documentation for the NeedDeps field is unclear. It says:
I think perhaps the idea might be more clearly expressed as:
but that isn't what actually happens. Observe:
In other words, the NeedDeps flag seems to have no effect when the NeedImports flag is set. And If you remove NeedImports, only a single package is reported, regardless of NeedDeps. It's as if the flag has no effect at all.
I would expect the following behaviors:
The text was updated successfully, but these errors were encountered: