Skip to content

Commit

Permalink
feat(go): Golang path data (very slow)
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Apr 11, 2018
1 parent 06d9cd8 commit c21dc4c
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 111 deletions.
10 changes: 5 additions & 5 deletions builders/bower.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ type bowerJSONManifest struct {
Version string
}

func normalizeBowerComponents(parent module.ImportPath, c bowerListManifest) []module.Dependency {
var deps []module.Dependency
func normalizeBowerComponents(parent module.ImportPath, c bowerListManifest) []Imported {
var deps []Imported
for _, dep := range c.Dependencies {
deps = append(
deps,
Expand All @@ -95,13 +95,13 @@ func normalizeBowerComponents(parent module.ImportPath, c bowerListManifest) []m
)...)
}

return append(deps, module.Dependency{
return append(deps, Imported{
Locator: module.Locator{
Fetcher: "bower",
Project: c.PkgMeta.Name,
Revision: c.PkgMeta.Version,
},
Via: []module.ImportPath{parent},
From: parent,
})
}

Expand All @@ -121,7 +121,7 @@ func (builder *BowerBuilder) Analyze(m module.Module, allowUnresolved bool) ([]m
return nil, errors.Wrap(err, "could not parse `bower ls --json` output")
}

var depList []module.Dependency
var depList []Imported
for _, dep := range output.Dependencies {
depList = append(
depList,
Expand Down
9 changes: 7 additions & 2 deletions builders/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,20 @@ func which(versionFlags string, cmds ...string) (string, string, error) {
})
}

type Imported struct {
module.Locator
From module.ImportPath
}

// Utilities for computing import paths
func computeImportPaths(deps []module.Dependency) []module.Dependency {
func computeImportPaths(deps []Imported) []module.Dependency {
pathsSet := make(map[module.Locator]map[module.ImportPathString]bool)
for _, dep := range deps {
_, ok := pathsSet[dep.Locator]
if !ok {
pathsSet[dep.Locator] = make(map[module.ImportPathString]bool)
}
pathsSet[dep.Locator][dep.Via[0].String()] = true
pathsSet[dep.Locator][dep.From.String()] = true
}

var out []module.Dependency
Expand Down
13 changes: 7 additions & 6 deletions builders/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ func (builder *ComposerBuilder) Analyze(m module.Module, allowUnresolved bool) (
if err != nil {
return nil, fmt.Errorf("could not get dependency list from Composer: %s", err.Error())
}
var depList []module.Dependency
depContext := module.ImportPath{module.Locator{
var depList []Imported
root := module.Locator{
Fetcher: "root",
Project: "root",
Revision: "root",
}}
}
depContext := module.ImportPath{root}
lastDepth := 0
lines := strings.Split(treeOutput, "\n")
for _, line := range lines {
Expand All @@ -120,7 +121,7 @@ func (builder *ComposerBuilder) Analyze(m module.Module, allowUnresolved bool) (
Project: parts[0],
Revision: "revision-placeholder",
}
depContext = []module.Locator{locator}
depContext = module.ImportPath{root, locator}
depth = 0
} else {
// We're somewhere in the tree.
Expand All @@ -145,9 +146,9 @@ func (builder *ComposerBuilder) Analyze(m module.Module, allowUnresolved bool) (
} else {
depContext = depContext[:depth/3+1]
}
depList = append(depList, module.Dependency{
depList = append(depList, Imported{
Locator: locator,
Via: []module.ImportPath{depContext},
From: depContext,
})
lastDepth = depth
}
Expand Down
Loading

0 comments on commit c21dc4c

Please sign in to comment.