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

Commit 2ead833

Browse files
committed
fix(gps): add recursive ignore support
1 parent 7430198 commit 2ead833

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

internal/gps/pkgtree/pkgtree.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import (
1616
"strconv"
1717
"strings"
1818
"unicode"
19+
20+
radix "github.com/armon/go-radix"
1921
)
2022

23+
// recursive ignore suffix
24+
const recIgnoreSuffix = "/*"
25+
2126
// Package represents a Go package. It contains a subset of the information
2227
// go/build.Package does.
2328
type Package struct {
@@ -445,6 +450,15 @@ func (t PackageTree) ToReachMap(main, tests, backprop bool, ignore map[string]bo
445450
ignore = make(map[string]bool)
446451
}
447452

453+
// Create a radix tree for ignore prefixes
454+
xt := radix.New()
455+
for i := range ignore {
456+
if strings.HasSuffix(i, recIgnoreSuffix) {
457+
i = strings.TrimSuffix(i, recIgnoreSuffix)
458+
xt.Insert(i, true)
459+
}
460+
}
461+
448462
// world's simplest adjacency list
449463
workmap := make(map[string]wm)
450464

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

484+
// Skip ignored packages prefix matches
485+
_, _, ok := xt.LongestPrefix(ip)
486+
if ok {
487+
continue
488+
}
489+
470490
// TODO (kris-nova) Disable to get staticcheck passing
471491
//imps = imps[:0]
472492

internal/gps/rootdata.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type rootdata struct {
2020
// Map of packages to ignore.
2121
ig map[string]bool
2222

23+
// Radix tree of ignore prefixes.
24+
igpfx *radix.Tree
25+
2326
// Map of packages to require.
2427
req map[string]bool
2528

@@ -202,3 +205,16 @@ func (rd rootdata) rootAtom() atomWithPackages {
202205
pl: list,
203206
}
204207
}
208+
209+
// isIgnored checks if a given path is ignored, comparing with the list of
210+
// ignore packages and ignore prefixes.
211+
func (rd rootdata) isIgnored(path string) bool {
212+
// Check if the path is present in ignore packages.
213+
if rd.ig[path] {
214+
return true
215+
}
216+
217+
// Check if the path matches any of the ignore prefixes.
218+
_, _, ok := rd.igpfx.LongestPrefix(path)
219+
return ok
220+
}

internal/gps/solver.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import (
1717
"github.com/golang/dep/internal/gps/pkgtree"
1818
)
1919

20+
// recursive ignore suffix
21+
const recIgnoreSuffix = "/*"
22+
2023
var rootRev = Revision("")
2124

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

268+
// Create ignore prefix tree using the provided ignore packages
269+
rd.igpfx = createIgnorePrefixTree(rd.ig)
270+
265271
return rd, nil
266272
}
267273

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

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

13381344
return lp
13391345
}
1346+
1347+
func createIgnorePrefixTree(ig map[string]bool) *radix.Tree {
1348+
xt := radix.New()
1349+
1350+
for i := range ig {
1351+
// Check if it's a recursive ignore
1352+
if strings.HasSuffix(i, recIgnoreSuffix) {
1353+
// Create the ignore prefix and insert in the radix tree
1354+
i = strings.TrimSuffix(i, recIgnoreSuffix)
1355+
xt.Insert(i, true)
1356+
}
1357+
}
1358+
1359+
return xt
1360+
}

0 commit comments

Comments
 (0)