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
// If FindOnly is set, Import stops after locating the directory
// that should contain the sources for a package. It does not
// read any files in the directory.
$ cd$(mktemp -d)
$ cat >main.go <<EOFpackage mainimport ( "fmt" "go/build" "log" "os")func main() { wd, err := os.Getwd() if err != nil { log.Fatalln(err) } p, err := build.Import("golang.org/x/exp/shiny/example/goban", wd, build.FindOnly) fmt.Printf("dir=%q err=%v\n", p.Dir, err)}EOF# Run in GOPATH mode.
$ GO111MODULE=off go run .
dir="/Users/gopher/go/src/golang.org/x/exp/shiny/example/goban" err=<nil>
But build.FindOnly has no effect in module mode:
# Run in module mode.
$ go mod init m
go: creating new go.mod: module m
$ GO111MODULE=on go run .
dir="" err=go/build: importGo golang.org/x/exp/shiny/example/goban: exit status 1
can't load package: package golang.org/x/exp/shiny/example/goban: build constraints exclude all Go files in /Users/gopher/go/pkg/mod/golang.org/x/[email protected]/shiny/example/goban
The text was updated successfully, but these errors were encountered:
dmitshur
changed the title
go/build: Import does not respect build.FindOnly flag in module mode
go/build: Import does not respect FindOnly flag in module mode
Apr 21, 2019
dmitshur
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Feb 10, 2020
Issue #26504 was about making it possible for
go/build
'sImport
andContext.Import
to find packages in module mode.The
build.FindOnly
import mode is documented as:For example, consider the following Go program:
It works as expected in GOPATH mode:
But
build.FindOnly
has no effect in module mode:The text was updated successfully, but these errors were encountered: