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

check GOROOT before GOPATH during package resoving #993

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions dependency/resolver.go
Expand Up @@ -1032,23 +1032,23 @@ func (r *Resolver) FindPkg(name string) *PkgInfo {
//}
//}

// Check $GOPATH
for _, rr := range filepath.SplitList(r.BuildContext.GOPATH) {
// Check $GOROOT
for _, rr := range filepath.SplitList(r.BuildContext.GOROOT) {
p = filepath.Join(rr, "src", filepath.FromSlash(name))
if pkgExists(p) {
info.Path = p
info.Loc = LocGopath
info.Loc = LocGoroot
r.findCache[name] = info
return info
}
}

// Check $GOROOT
for _, rr := range filepath.SplitList(r.BuildContext.GOROOT) {
// Check $GOPATH
for _, rr := range filepath.SplitList(r.BuildContext.GOPATH) {
p = filepath.Join(rr, "src", filepath.FromSlash(name))
if pkgExists(p) {
info.Path = p
info.Loc = LocGoroot
info.Loc = LocGopath
r.findCache[name] = info
return info
}
Expand Down
13 changes: 13 additions & 0 deletions dependency/resolver_test.go
Expand Up @@ -42,6 +42,19 @@ func TestResolveLocalShallow(t *testing.T) {
}

func TestResolveLocalDeep(t *testing.T) {
// create package of same name with sys package
err := os.MkdirAll(filepath.Join(os.Getenv("GOPATH"), "src/strings"), os.ModePerm)
if err != nil {
t.Fatalf("Failed to create package of test case: %s", err)
}
// remove package of same name with sys package
defer func() {
err = os.Remove(filepath.Join(os.Getenv("GOPATH"), "src/strings"))
if err != nil {
t.Fatalf("Failed to remove package of test case: %s", err)
}
}()

r, err := NewResolver("../")
if err != nil {
t.Fatal(err)
Expand Down