Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Support vendor directory as $GOPATH/src/vendor #313

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func (c *Ctx) LoadProject(path string) (*Project, error) {
//
// The second returned string indicates which GOPATH value was used.
func (c *Ctx) SplitAbsoluteProjectRoot(path string) (string, error) {
// allow vendor directory to be directly under GOPATH/src
if filepath.Join(c.GOPATH, "src") == path {
return ".", nil
}

srcprefix := filepath.Join(c.GOPATH, "src") + string(filepath.Separator)
if filepath.HasPrefix(path, srcprefix) {
// filepath.ToSlash because we're dealing with an import path now,
Expand Down
7 changes: 7 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func TestSplitAbsoluteProjectRoot(t *testing.T) {
}
}

// test when the full path corresponds to $GOPATH/src
if got, err := depCtx.SplitAbsoluteProjectRoot(filepath.Join(depCtx.GOPATH, "src")); err != nil {
t.Fatal(err)
} else if got != "." {
t.Fatalf("expected ., got %s", got)
}

// test where it should return error
got, err := depCtx.SplitAbsoluteProjectRoot("tra/la/la/la")
if err == nil {
Expand Down