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
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

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 NeedsFix The path to resolution is known, but the work has not been done. modules labels Feb 10, 2020
@dmitshur dmitshur added this to the Go1.14 milestone Feb 10, 2020
@dmitshur dmitshur self-assigned this Feb 10, 2020
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Feb 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants