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

Commit

Permalink
Pull out yet more cruft from ListPackages
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed Jan 21, 2017
1 parent 31f8590 commit 0dbe923
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions analysis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gps

import (
"errors"
"fmt"
"go/build"
"go/parser"
Expand Down Expand Up @@ -77,20 +76,6 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
Packages: make(map[string]PackageOrErr),
}

// helper func to create a Package from a *build.Package
happy := func(importPath string, p *build.Package) Package {
// Happy path - simple parsing worked
pkg := Package{
ImportPath: importPath,
CommentPath: p.ImportComment,
Name: p.Name,
Imports: p.Imports,
TestImports: dedupeStrings(p.TestImports, p.XTestImports),
}

return pkg
}

var err error
fileRoot, err = filepath.Abs(fileRoot)
if err != nil {
Expand Down Expand Up @@ -133,7 +118,13 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {

var pkg Package
if err == nil {
pkg = happy(ip, p)
pkg = Package{
ImportPath: ip,
CommentPath: p.ImportComment,
Name: p.Name,
Imports: p.Imports,
TestImports: dedupeStrings(p.TestImports, p.XTestImports),
}
} else {
switch err.(type) {
case gscan.ErrorList, *gscan.Error, *build.NoGoError:
Expand Down Expand Up @@ -190,22 +181,6 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {

// fillPackage full of info. Assumes p.Dir is set at a minimum
func fillPackage(p *build.Package) error {
if p.SrcRoot == "" {
for _, base := range build.Default.SrcDirs() {
if strings.HasPrefix(p.Dir, base) {
p.SrcRoot = base
}
}
}

if p.SrcRoot == "" {
return errors.New("Unable to find SrcRoot for package " + p.ImportPath)
}

if p.Root == "" {
p.Root = filepath.Dir(p.SrcRoot)
}

var buildMatch = "+build "
var buildFieldSplit = func(r rune) bool {
return unicode.IsSpace(r) || r == ','
Expand Down

0 comments on commit 0dbe923

Please sign in to comment.