@@ -356,13 +356,16 @@ type PackageOrErr struct {
356
356
Err error
357
357
}
358
358
359
- // ReachMap maps a set of import paths (keys) to the set of external packages
360
- // transitively reachable from the packages at those import paths.
359
+ // ReachMap maps a set of import paths (keys) to the sets of transitively
360
+ // reachable tree-internal packages, and all the tree-external reachable through
361
+ // those internal packages.
361
362
//
362
- // See PackageTree.ExternalReach() for more information.
363
- type ReachMap map [string ][]string
363
+ // See PackageTree.ToReachMap() for more information.
364
+ type ReachMap map [string ]struct {
365
+ Internal , External []string
366
+ }
364
367
365
- // ToReachMaps looks through a PackageTree and computes the list of external
368
+ // ToReachMap looks through a PackageTree and computes the list of external
366
369
// import statements (that is, import statements pointing to packages that are
367
370
// not logical children of PackageTree.ImportRoot) that are transitively
368
371
// imported by the internal packages in the tree.
@@ -434,7 +437,7 @@ type ReachMap map[string][]string
434
437
//
435
438
// When backprop is false, errors in internal packages are functionally
436
439
// identical to ignoring that package.
437
- func (t PackageTree ) ToReachMaps (main , tests bool , ignore map [string ]bool ) ( ex ReachMap , in ReachMap ) {
440
+ func (t PackageTree ) ToReachMap (main , tests bool , ignore map [string ]bool ) ReachMap {
438
441
if ignore == nil {
439
442
ignore = make (map [string ]bool )
440
443
}
@@ -508,7 +511,7 @@ func (t PackageTree) ToReachMaps(main, tests bool, ignore map[string]bool) (ex R
508
511
//
509
512
// The basedir string, with a trailing slash ensured, will be stripped from the
510
513
// keys of the returned map.
511
- func wmToReach (workmap map [string ]wm ) ( ex ReachMap , in ReachMap ) {
514
+ func wmToReach (workmap map [string ]wm ) ReachMap {
512
515
// Uses depth-first exploration to compute reachability into external
513
516
// packages, dropping any internal packages on "poisoned paths" - a path
514
517
// containing a package with an error, or with a dep on an internal package
@@ -541,10 +544,6 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
541
544
// stack of parent packages we've visited to get to pkg. The return value
542
545
// indicates whether the level completed successfully (true) or if it was
543
546
// poisoned (false).
544
- //
545
- // TODO(sdboyer) some deft improvements could probably be made by passing the list of
546
- // parent reachsets, rather than a list of parent package string names.
547
- // might be able to eliminate the use of exrsets map-of-maps entirely.
548
547
dfe = func (pkg string , path []string ) bool {
549
548
// white is the zero value of uint8, which is what we want if the pkg
550
549
// isn't in the colors map, so this works fine
@@ -691,12 +690,16 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
691
690
dfe (pkg , path )
692
691
}
693
692
694
- // Flatten exrsets into the final external reachmap
695
- rm := make (map [string ][]string )
693
+ type ie struct {
694
+ Internal , External []string
695
+ }
696
+
697
+ // Flatten exrsets into reachmap
698
+ rm := make (ReachMap )
696
699
for pkg , rs := range exrsets {
697
700
rlen := len (rs )
698
701
if rlen == 0 {
699
- rm [pkg ] = nil
702
+ rm [pkg ] = ie {}
700
703
continue
701
704
}
702
705
@@ -706,15 +709,16 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
706
709
}
707
710
708
711
sort .Strings (edeps )
709
- rm [pkg ] = edeps
712
+
713
+ sets := rm [pkg ]
714
+ sets .External = edeps
715
+ rm [pkg ] = sets
710
716
}
711
717
712
- // Flatten inrsets into the final internal reachmap
713
- irm := make (map [string ][]string )
718
+ // Flatten inrsets into reachmap
714
719
for pkg , rs := range inrsets {
715
720
rlen := len (rs )
716
721
if rlen == 0 {
717
- irm [pkg ] = nil
718
722
continue
719
723
}
720
724
@@ -724,10 +728,13 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
724
728
}
725
729
726
730
sort .Strings (ideps )
727
- irm [pkg ] = ideps
731
+
732
+ sets := rm [pkg ]
733
+ sets .Internal = ideps
734
+ rm [pkg ] = sets
728
735
}
729
736
730
- return rm , irm
737
+ return rm
731
738
}
732
739
733
740
// ListExternalImports computes a sorted, deduplicated list of all the external
0 commit comments