1 Star 0 Fork 0

liboxwz / dep

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
reachmap.go 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
tamal 提交于 2017-11-03 06:05 . Move gps package out of internal
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pkgtree
import (
"sort"
"strings"
)
// ReachMap maps a set of import paths (keys) to the sets of transitively
// reachable tree-internal packages, and all the tree-external packages
// reachable through those internal packages.
//
// See PackageTree.ToReachMap() for more information.
type ReachMap map[string]struct {
Internal, External []string
}
// Eliminate import paths with any elements having leading dots, leading
// underscores, or testdata. If these are internally reachable (which is
// a no-no, but possible), any external imports will have already been
// pulled up through ExternalReach. The key here is that we don't want
// to treat such packages as themselves being sources.
func pkgFilter(pkg string) bool {
for _, elem := range strings.Split(pkg, "/") {
if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" {
return false
}
}
return true
}
// FlattenFn flattens a reachmap into a sorted, deduplicated list of all the
// external imports named by its contained packages, but excludes imports coming
// from packages with disallowed patterns in their names: any path element with
// a leading dot, a leading underscore, with the name "testdata".
//
// Imports for which exclude returns true will be left out.
func (rm ReachMap) FlattenFn(exclude func(string) bool) []string {
exm := make(map[string]struct{})
for pkg, ie := range rm {
if pkgFilter(pkg) {
for _, ex := range ie.External {
if exclude != nil && exclude(ex) {
continue
}
exm[ex] = struct{}{}
}
}
}
if len(exm) == 0 {
return []string{}
}
ex := make([]string, 0, len(exm))
for p := range exm {
ex = append(ex, p)
}
sort.Strings(ex)
return ex
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liboxwz/dep.git
git@gitee.com:liboxwz/dep.git
liboxwz
dep
dep
v0.5.3

搜索帮助

344bd9b3 5694891 D2dac590 5694891