-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/buildutil: TestContainingPackage fails if tools repo is in non-first GOPATH directory. #19400
Comments
I know the exact cause of this issue, the above report is for tracking purposes. It happens because In my environment, it happened to be inside the second GOPATH directory rather than first. The following ad-hoc patch for my particular environment fixes the $ git diff
diff --git a/go/buildutil/util_test.go b/go/buildutil/util_test.go
index 72db317..a244a4a 100644
--- a/go/buildutil/util_test.go
+++ b/go/buildutil/util_test.go
@@ -18,7 +18,7 @@ import (
func TestContainingPackage(t *testing.T) {
// unvirtualized:
goroot := runtime.GOROOT()
- gopath := filepath.SplitList(os.Getenv("GOPATH"))[0]
+ gopath := filepath.SplitList(os.Getenv("GOPATH"))[1]
type Test struct {
gopath, filename, wantPkg string
$ go test golang.org/x/tools/go/buildutil
ok golang.org/x/tools/go/buildutil 0.071s |
A related issue is in func toolsDir() string {
gopath := os.Getenv("GOPATH")
if gopath == "" {
log.Println("error: GOPATH not set. Can't find client files")
os.Exit(1)
}
return filepath.Join(filepath.SplitList(gopath)[0], "src/golang.org/x/tools")
} That assumes one's The issue can be resolved by using func toolsDir() string {
p, err := build.Import("golang.org/x/tools", "", build.FindOnly)
if err != nil {
log.Println("error: can't find client files:", err)
os.Exit(1)
}
return p.Dir
} Edit: I've sent CL 38778 that fixes this. |
CL https://golang.org/cl/38778 mentions this issue. |
The GOPATH environment variable is defined at https://golang.org/cmd/go/#hdr-GOPATH_environment_variable as: > The GOPATH environment variable lists places to look for Go code. On > Unix, the value is a colon-separated string. On Windows, the value is > a semicolon-separated string. On Plan 9, the value is a list. It is legal for Go packages to be in any of those places, not only the first entry. Look in all places for golang.org/x/tools repository. Cache the directory that is found. It's slightly more expensive to look for it, since potentially multiple directories must be checked for existence. Updates golang/go#19400. Change-Id: I16661b7149d52ea6168fffc605c842d7a4da009b Reviewed-on: https://go-review.googlesource.com/38778 Reviewed-by: Michael Matloob <matloob@golang.org>
Change https://golang.org/cl/94900 mentions this issue: |
I've sent CL 94900 that resolves this issue. |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: