From 536add9e86ef859e90f6f6c60842a894fc50040a Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Wed, 10 May 2017 14:36:23 -0700 Subject: [PATCH 1/5] Don't try to parse directories named *.go fillPackage is supposed to use the AST parser on individual files. Unforntunately, `filepath.Glob("*.go")` returns directories as well as files. Fixes #550 --- internal/gps/_testdata/src/dotgodir/.go/.gitkeep | 0 internal/gps/pkgtree/pkgtree.go | 6 ++++++ internal/gps/pkgtree/pkgtree_test.go | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 internal/gps/_testdata/src/dotgodir/.go/.gitkeep diff --git a/internal/gps/_testdata/src/dotgodir/.go/.gitkeep b/internal/gps/_testdata/src/dotgodir/.go/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/gps/pkgtree/pkgtree.go b/internal/gps/pkgtree/pkgtree.go index a83fb4e034..bb4700c0ef 100644 --- a/internal/gps/pkgtree/pkgtree.go +++ b/internal/gps/pkgtree/pkgtree.go @@ -203,6 +203,12 @@ func fillPackage(p *build.Package) error { if filepath.Base(file)[0] == '_' { continue } + + // Skip any directories that happen to end with ".go" + if stat, err := os.Stat(file); err == nil && stat.IsDir() { + continue + } + pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments) if err != nil { if os.IsPermission(err) { diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index 1cecf65cf6..5ca1b90117 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1280,6 +1280,11 @@ func TestListPackages(t *testing.T) { }, }, }, + "skip '.go' directories": { + fileRoot: j("dotgodir"), + importRoot: "dotgodir", + err: nil, + }, } for name, fix := range table { From 2ff06431684552cc8c7503d391ad1634fab1a705 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Wed, 10 May 2017 18:23:00 -0700 Subject: [PATCH 2/5] Update logic to ignore all '.'-prefixed files --- internal/gps/pkgtree/pkgtree.go | 5 +++-- internal/gps/pkgtree/pkgtree_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/gps/pkgtree/pkgtree.go b/internal/gps/pkgtree/pkgtree.go index bb4700c0ef..007b4d52cf 100644 --- a/internal/gps/pkgtree/pkgtree.go +++ b/internal/gps/pkgtree/pkgtree.go @@ -199,8 +199,9 @@ func fillPackage(p *build.Package) error { var testImports []string var imports []string for _, file := range gofiles { - // Skip underscore-led files, in keeping with the rest of the toolchain. - if filepath.Base(file)[0] == '_' { + // Skip underscore-led or dot-led files, in keeping with the rest of the toolchain. + bPrefix := filepath.Base(file)[0] + if bPrefix == '_' || bPrefix == '.' { continue } diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index 5ca1b90117..b4b4f60a3e 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1280,7 +1280,7 @@ func TestListPackages(t *testing.T) { }, }, }, - "skip '.go' directories": { + "skip directories starting with '.'": { fileRoot: j("dotgodir"), importRoot: "dotgodir", err: nil, From 474fb3ef59cb0d6d3b61eb48c41fd7c787018360 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Wed, 10 May 2017 18:33:38 -0700 Subject: [PATCH 3/5] Handle directories ending in .go --- internal/gps/_testdata/src/dotgodir/foo.go/.gitkeep | 0 internal/gps/pkgtree/pkgtree.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 internal/gps/_testdata/src/dotgodir/foo.go/.gitkeep diff --git a/internal/gps/_testdata/src/dotgodir/foo.go/.gitkeep b/internal/gps/_testdata/src/dotgodir/foo.go/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/gps/pkgtree/pkgtree.go b/internal/gps/pkgtree/pkgtree.go index 007b4d52cf..a6b452764d 100644 --- a/internal/gps/pkgtree/pkgtree.go +++ b/internal/gps/pkgtree/pkgtree.go @@ -205,7 +205,7 @@ func fillPackage(p *build.Package) error { continue } - // Skip any directories that happen to end with ".go" + // Skip any directories that happened to get caught by glob if stat, err := os.Stat(file); err == nil && stat.IsDir() { continue } From 78ecf7b678ac5c45ce302544a31acc41daa45777 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Wed, 10 May 2017 18:56:55 -0700 Subject: [PATCH 4/5] Add tests for recursing into dot-go directories --- .../gps/_testdata/src/dotgodir/foo.go/foo.go | 3 +++ internal/gps/pkgtree/pkgtree_test.go | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 internal/gps/_testdata/src/dotgodir/foo.go/foo.go diff --git a/internal/gps/_testdata/src/dotgodir/foo.go/foo.go b/internal/gps/_testdata/src/dotgodir/foo.go/foo.go new file mode 100644 index 0000000000..eef38b192c --- /dev/null +++ b/internal/gps/_testdata/src/dotgodir/foo.go/foo.go @@ -0,0 +1,3 @@ +package foo + +// yes, this is dumb, don't use ".go" in your directory names diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index b4b4f60a3e..d9112df09b 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1283,7 +1283,24 @@ func TestListPackages(t *testing.T) { "skip directories starting with '.'": { fileRoot: j("dotgodir"), importRoot: "dotgodir", - err: nil, + out: PackageTree{ + ImportRoot: "dotgodir", + Packages: map[string]PackageOrErr{ + "dotgodir": { + P: Package{ + ImportPath: "dotgodir", + Imports: []string{}, + }, + }, + "dotgodir/foo.go": { + P: Package{ + ImportPath: "dotgodir/foo.go", + Name: "foo", + Imports: []string{}, + }, + }, + }, + }, }, } From 27fbbf283f88b10c7e614f437db3ebed46231d87 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Thu, 11 May 2017 00:01:17 -0700 Subject: [PATCH 5/5] Fix header and test import --- internal/gps/_testdata/src/dotgodir/foo.go/foo.go | 9 +++++++++ internal/gps/pkgtree/pkgtree_test.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/gps/_testdata/src/dotgodir/foo.go/foo.go b/internal/gps/_testdata/src/dotgodir/foo.go/foo.go index eef38b192c..1de8b0ab15 100644 --- a/internal/gps/_testdata/src/dotgodir/foo.go/foo.go +++ b/internal/gps/_testdata/src/dotgodir/foo.go/foo.go @@ -1,3 +1,12 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package foo +import "sort" + +var _ = sort.Strings + // yes, this is dumb, don't use ".go" in your directory names +// See https://github.com/golang/dep/issues/550 for more information diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index d9112df09b..9371900079 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1296,7 +1296,7 @@ func TestListPackages(t *testing.T) { P: Package{ ImportPath: "dotgodir/foo.go", Name: "foo", - Imports: []string{}, + Imports: []string{"sort"}, }, }, },