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

Commit

Permalink
Encompass both internal and external in ReachMaps
Browse files Browse the repository at this point in the history
Rather than splitting the data into two separate map return values, this
makes ReachMaps' value a struct containing both the internal package
import and external import path list information.
  • Loading branch information
sdboyer committed Feb 13, 2017
1 parent 722997a commit 852064d
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 224 deletions.
47 changes: 27 additions & 20 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,16 @@ type PackageOrErr struct {
Err error
}

// ReachMap maps a set of import paths (keys) to the set of external packages
// transitively reachable from the packages at those import paths.
// ReachMap maps a set of import paths (keys) to the sets of transitively
// reachable tree-internal packages, and all the tree-external reachable through
// those internal packages.
//
// See PackageTree.ExternalReach() for more information.
type ReachMap map[string][]string
// See PackageTree.ToReachMap() for more information.
type ReachMap map[string]struct {
Internal, External []string
}

// ToReachMaps looks through a PackageTree and computes the list of external
// ToReachMap looks through a PackageTree and computes the list of external
// import statements (that is, import statements pointing to packages that are
// not logical children of PackageTree.ImportRoot) that are transitively
// imported by the internal packages in the tree.
Expand Down Expand Up @@ -403,7 +406,7 @@ type ReachMap map[string][]string
//
// When backprop is false, errors in internal packages are functionally
// identical to ignoring that package.
func (t PackageTree) ToReachMaps(main, tests bool, ignore map[string]bool) (ex ReachMap, in ReachMap) {
func (t PackageTree) ToReachMap(main, tests bool, ignore map[string]bool) ReachMap {
if ignore == nil {
ignore = make(map[string]bool)
}
Expand Down Expand Up @@ -477,7 +480,7 @@ func (t PackageTree) ToReachMaps(main, tests bool, ignore map[string]bool) (ex R
//
// The basedir string, with a trailing slash ensured, will be stripped from the
// keys of the returned map.
func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
func wmToReach(workmap map[string]wm) ReachMap {
// Uses depth-first exploration to compute reachability into external
// packages, dropping any internal packages on "poisoned paths" - a path
// containing a package with an error, or with a dep on an internal package
Expand Down Expand Up @@ -510,10 +513,6 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
// stack of parent packages we've visited to get to pkg. The return value
// indicates whether the level completed successfully (true) or if it was
// poisoned (false).
//
// TODO(sdboyer) some deft improvements could probably be made by passing the list of
// parent reachsets, rather than a list of parent package string names.
// might be able to eliminate the use of exrsets map-of-maps entirely.
dfe = func(pkg string, path []string) bool {
// white is the zero value of uint8, which is what we want if the pkg
// isn't in the colors map, so this works fine
Expand Down Expand Up @@ -660,12 +659,16 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
dfe(pkg, path)
}

// Flatten exrsets into the final external reachmap
rm := make(map[string][]string)
type ie struct {
Internal, External []string
}

// Flatten exrsets into reachmap
rm := make(ReachMap)
for pkg, rs := range exrsets {
rlen := len(rs)
if rlen == 0 {
rm[pkg] = nil
rm[pkg] = ie{}
continue
}

Expand All @@ -675,15 +678,16 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
}

sort.Strings(edeps)
rm[pkg] = edeps

sets := rm[pkg]
sets.External = edeps
rm[pkg] = sets
}

// Flatten inrsets into the final internal reachmap
irm := make(map[string][]string)
// Flatten inrsets into reachmap
for pkg, rs := range inrsets {
rlen := len(rs)
if rlen == 0 {
irm[pkg] = nil
continue
}

Expand All @@ -693,10 +697,13 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
}

sort.Strings(ideps)
irm[pkg] = ideps

sets := rm[pkg]
sets.Internal = ideps
rm[pkg] = sets
}

return rm, irm
return rm
}

// ListExternalImports computes a sorted, deduplicated list of all the external
Expand Down
Loading

0 comments on commit 852064d

Please sign in to comment.