Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/go/packages: NeedDeps has no effect #56633

Open
adonovan opened this issue Nov 7, 2022 · 0 comments
Open

x/tools/go/packages: NeedDeps has no effect #56633

adonovan opened this issue Nov 7, 2022 · 0 comments
Assignees
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Nov 7, 2022

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.
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Nov 7, 2022
@gopherbot gopherbot added this to the Unreleased milestone Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants