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

go/build: 1.14 regression of Import("path", "", FindOnly) for finding packages with errors in module mode #37153

Closed
dmitshur opened this issue Feb 10, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Feb 10, 2020

There is a regression in go1.14rc1 when calling Import with an empty srcDir parameter in build.FindOnly mode, on an import path of a Go package that produces errors when loading (e.g., due to build constraints not matching the current build context).

This regression applies only when in module mode. It's related to but not the same as issue #31603.

To reproduce:

# Initial setup.
$ cd $(mktemp -d)
$ export GOPATH=$(mktemp -d)
$ GO111MODULE=off go get -d golang.org/x/exp/shiny/driver
$ export GO111MODULE=on

# Test program.
$ go mod init issue37153.test
$ cat >main.go <<EOF
package main

import (
	"fmt"
	"go/build"
)

func main() {
	pkg, err := build.Import("golang.org/x/exp/shiny/example/goban/asset", "", build.FindOnly)
	fmt.Printf("pkg.Dir=%q err=%v\n", pkg.Dir, err)
}
EOF

# Previous versions of Go.
$ go1.11.13 run .
pkg.Dir="/tmp/tmp.WqlneM7y/src/golang.org/x/exp/shiny/example/goban/asset" err=<nil>
$ go1.12.16 run .
pkg.Dir="/tmp/tmp.WqlneM7y/src/golang.org/x/exp/shiny/example/goban/asset" err=<nil>
$ go1.13.7 run .
pkg.Dir="/tmp/tmp.WqlneM7y/src/golang.org/x/exp/shiny/example/goban/asset" err=<nil>

# Upcoming version of Go.
$ go1.14rc1 run .
pkg.Dir="" err=package golang.org/x/exp/shiny/example/goban/asset: build constraints exclude all Go files in /tmp/tmp.WqlneM7y/pkg/mod/golang.org/x/exp@v0.0.0-20200207192155-f17229e696bd/shiny/example/goban/asset

I've investigated this and found the root cause. See the commit message of CL 218817 for details.

The fix in CL 218817 seems small, targeted, and safe to make. It results in the following output:


# CL 218817.
$ go run .
pkg.Dir="/tmp/tmp.ERHcBPHO/pkg/mod/golang.org/x/exp@v0.0.0-20200207192155-f17229e696bd/shiny/example/goban/asset" err=<nil>

I think we should consider fixing this for 1.14, because the build.Import("some/import/path", "", build.FindOnly) pattern is quite common for finding the location of a package, and I think we should not break it unnecessarily.

I've tentatively milestoned this for 1.14, but I'm open to discussion depending on how others feel.

/cc @bcmills @jayconrod @matloob

@dmitshur dmitshur added this to the Go1.14 milestone Feb 10, 2020
@dmitshur dmitshur self-assigned this Feb 10, 2020
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Feb 10, 2020

Change https://golang.org/cl/218817 mentions this issue: go/build: populate partial package information in importGo

@gopherbot gopherbot closed this in d0050e2 Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.