Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
fix(gps): add recursive ignore support
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Sep 12, 2017
1 parent 7430198 commit 2ead833
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
20 changes: 20 additions & 0 deletions internal/gps/pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ import (
"strconv"
"strings"
"unicode"

radix "github.com/armon/go-radix"
)

// recursive ignore suffix
const recIgnoreSuffix = "/*"

// Package represents a Go package. It contains a subset of the information
// go/build.Package does.
type Package struct {
Expand Down Expand Up @@ -445,6 +450,15 @@ func (t PackageTree) ToReachMap(main, tests, backprop bool, ignore map[string]bo
ignore = make(map[string]bool)
}

// Create a radix tree for ignore prefixes
xt := radix.New()
for i := range ignore {
if strings.HasSuffix(i, recIgnoreSuffix) {
i = strings.TrimSuffix(i, recIgnoreSuffix)
xt.Insert(i, true)
}
}

// world's simplest adjacency list
workmap := make(map[string]wm)

Expand All @@ -467,6 +481,12 @@ func (t PackageTree) ToReachMap(main, tests, backprop bool, ignore map[string]bo
continue
}

// Skip ignored packages prefix matches
_, _, ok := xt.LongestPrefix(ip)
if ok {
continue
}

// TODO (kris-nova) Disable to get staticcheck passing
//imps = imps[:0]

Expand Down
16 changes: 16 additions & 0 deletions internal/gps/rootdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type rootdata struct {
// Map of packages to ignore.
ig map[string]bool

// Radix tree of ignore prefixes.
igpfx *radix.Tree

// Map of packages to require.
req map[string]bool

Expand Down Expand Up @@ -202,3 +205,16 @@ func (rd rootdata) rootAtom() atomWithPackages {
pl: list,
}
}

// isIgnored checks if a given path is ignored, comparing with the list of
// ignore packages and ignore prefixes.
func (rd rootdata) isIgnored(path string) bool {
// Check if the path is present in ignore packages.
if rd.ig[path] {
return true
}

// Check if the path matches any of the ignore prefixes.
_, _, ok := rd.igpfx.LongestPrefix(path)
return ok
}
23 changes: 22 additions & 1 deletion internal/gps/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/golang/dep/internal/gps/pkgtree"
)

// recursive ignore suffix
const recIgnoreSuffix = "/*"

var rootRev = Revision("")

// SolveParameters hold all arguments to a solver run.
Expand Down Expand Up @@ -262,6 +265,9 @@ func (params SolveParameters) toRootdata() (rootdata, error) {
rd.chng[p] = struct{}{}
}

// Create ignore prefix tree using the provided ignore packages
rd.igpfx = createIgnorePrefixTree(rd.ig)

return rd, nil
}

Expand Down Expand Up @@ -657,7 +663,7 @@ func (s *solver) getImportsAndConstraintsOf(a atomWithPackages) ([]string, []com
// explicitly listed in the atom
for _, pkg := range a.pl {
// Skip ignored packages
if s.rd.ig[pkg] {
if s.rd.isIgnored(pkg) {
continue
}

Expand Down Expand Up @@ -1337,3 +1343,18 @@ func pa2lp(pa atom, pkgs map[string]struct{}) LockedProject {

return lp
}

func createIgnorePrefixTree(ig map[string]bool) *radix.Tree {
xt := radix.New()

for i := range ig {
// Check if it's a recursive ignore
if strings.HasSuffix(i, recIgnoreSuffix) {
// Create the ignore prefix and insert in the radix tree
i = strings.TrimSuffix(i, recIgnoreSuffix)
xt.Insert(i, true)
}
}

return xt
}

0 comments on commit 2ead833

Please sign in to comment.