Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
Don't use build.ImportDir as it ignores tags
Browse files Browse the repository at this point in the history
Instead use our own directory scanning stuff. I hope this doesn't have other
fallout, but it probably will.  :-(

Fixed #529 though.
  • Loading branch information
Edward Muller committed Jan 19, 2017
1 parent 1ea5971 commit 796a322
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#v78 (2017/01/19)

* Don't use build.ImportDir when discovering packages for the package spec. Fixes #529

#v77 (2017/01/13)

* Don't include quotes around hg revisions
Expand Down
30 changes: 27 additions & 3 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ func fillPackage(p *build.Package) error {
return err
}

if len(gofiles) == 0 {
return &build.NoGoError{Dir: p.Dir}
}

var testImports []string
var imports []string
NextFile:
Expand Down Expand Up @@ -345,13 +349,21 @@ NextFile:
// importPaths returns the import paths to use for the given command line.
// $GOROOT/src/cmd/main.go:366
func importPaths(args []string) []string {
debugf("importPathsNoDotExpansion(%q) == ", args)
args = importPathsNoDotExpansion(args)
debugf("%q\n", args)
var out []string
for _, a := range args {
if strings.Contains(a, "...") {
if build.IsLocalImport(a) {
out = append(out, allPackagesInFS(a)...)
debugf("build.IsLocalImport(%q) == true\n", a)
pkgs := allPackagesInFS(a)
debugf("allPackagesInFS(%q) == %q\n", a, pkgs)
out = append(out, pkgs...)
} else {
debugf("build.IsLocalImport(%q) == false\n", a)
pkgs := allPackages(a)
debugf("allPackages(%q) == %q\n", a, pkgs)
out = append(out, allPackages(a)...)
}
continue
Expand Down Expand Up @@ -421,6 +433,7 @@ func allPackages(pattern string) []string {
}

// $GOROOT/src/cmd/main.go:554
// This has been changed to not use build.ImportDir
func matchPackages(pattern string) []string {
match := func(string) bool { return true }
treeCanMatch := func(string) bool { return true }
Expand Down Expand Up @@ -474,8 +487,13 @@ func matchPackages(pattern string) []string {
if !match(name) {
return nil
}
_, err = build.ImportDir(path, 0)

ap, err := filepath.Abs(path)
if err != nil {
return nil
}
if _, err = fullPackageInDir(ap); err != nil {
debugf("matchPackage(%q) ap=%q Error: %q\n", ap, pattern, err)
if _, noGo := err.(*build.NoGoError); noGo {
return nil
}
Expand Down Expand Up @@ -521,6 +539,7 @@ func hasPathPrefix(s, prefix string) bool {
}

// $GOROOT/src/cmd/go/main.go:631
// This has been changed to not use build.ImportDir
func matchPackagesInFS(pattern string) []string {
// Find directory to begin the scan.
// Could be smarter but this one optimization
Expand Down Expand Up @@ -567,7 +586,12 @@ func matchPackagesInFS(pattern string) []string {
if !match(name) {
return nil
}
if _, err = build.ImportDir(path, 0); err != nil {
ap, err := filepath.Abs(path)
if err != nil {
return nil
}
if _, err = fullPackageInDir(ap); err != nil {
debugf("matchPackageInFS(%q) ap=%q Error: %q\n", ap, pattern, err)
if _, noGo := err.(*build.NoGoError); !noGo {
log.Print(err)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ type Package struct {
Dependencies []build.Package
}

// LoadPackages loads the named packages using go list -json.
// LoadPackages loads the named packages
// Unlike the go tool, an empty argument list is treated as an empty list; "."
// must be given explicitly if desired.
// IgnoredGoFiles will be processed and their dependencies resolved recursively
// Files with a build tag of `ignore` are skipped. Files with other build tags
// are however processed.
func LoadPackages(names ...string) (a []*Package, err error) {
debugln("LoadPackages", names)
if len(names) == 0 {
Expand Down

0 comments on commit 796a322

Please sign in to comment.