-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
Milestone
Description
Environment
$ go version go version go1.12.4 darwin/amd64
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/dmitshur/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/dmitshur/go" GOPROXY="https://proxy.golang.org" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/var/folders/3m/rg2zm24d1jg40wb48wr0hdjw00jwcj/T/tmp.JaaD6nLe/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3m/rg2zm24d1jg40wb48wr0hdjw00jwcj/T/go-build560539665=/tmp/go-build -gno-record-gcc-switches -fno-common"
Issue
packages.NeedImports
is documented as:
// NeedImports adds Imports. If NeedDeps is not set, the Imports field will contain
// "placeholder" Packages with only the ID set.
NeedImports
I ran the following command at the root of a module, inside that directory:
package main
import (
"fmt"
"log"
"golang.org/x/tools/go/packages"
)
func main() {
cfg := &packages.Config{
//Mode: packages.NeedImports | packages.NeedDeps, // works
Mode: packages.NeedImports, // doesn't work
}
pkgs, err := packages.Load(cfg, ".")
if err != nil {
log.Fatalln("packages.Load:", err)
}
if len(pkgs) != 1 {
log.Fatalln("got something other than 1 package")
}
p := pkgs[0]
if len(p.Errors) > 0 {
log.Fatalln("p.Errors:", p.Errors)
}
fmt.Println("Imports:")
for _, i := range p.Imports {
fmt.Printf(" • %s\n", i.ID)
}
if len(p.Imports) == 0 {
fmt.Println(" (none)")
}
}
With this go.mod
file:
module m
go 1.12
require golang.org/x/tools v0.0.0-20190429184909-35c670923e21
With packages.Config.Mode
set to just packages.NeedImports
, the Imports field is not populated at all:
Imports:
(none)
With it set to packages.NeedImports | packages.NeedDeps
, it works as expected:
Imports:
• golang.org/x/tools/go/packages
• log
• fmt
/cc @ianthehat @matloob
SuperStar518 and jirfag
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.