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

Commit 31dfa52

Browse files
authored
Merge pull request #1268 from sdboyer/ignore-trie
Introduce IgnoredRuleset
2 parents 7d9726b + da9b750 commit 31dfa52

File tree

29 files changed

+463
-333
lines changed

29 files changed

+463
-333
lines changed

cmd/dep/integration_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ func testIntegration(name, relPath, wd string, run integration.RunFunc) func(t *
123123
// Check error raised in final command
124124
testCase.CompareError(err, testProj.GetStderr())
125125

126-
// Check output
127-
testCase.CompareOutput(testProj.GetStdout())
126+
if *test.UpdateGolden {
127+
testCase.UpdateOutput(testProj.GetStdout())
128+
} else {
129+
// Check output
130+
testCase.CompareOutput(testProj.GetStdout())
131+
}
128132

129133
// Check vendor paths
130134
testProj.CompareImportPaths()

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-ignore/final/Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-CONSTRAINTS-
2+
github.com/sdboyer/deptest
3+
b-master
4+
-IMPORTS/REQS-
5+
github.com/sdboyer/deptest
6+
-IGNORES-
7+
-OVERRIDES-
8+
-ANALYZER-
9+
dep
10+
1
11+

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-ignore/testcase.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"commands": [
3-
["ensure"]
3+
["ensure"],
4+
["hash-inputs"]
45
],
56
"error-expected": "",
67
"vendor-final": [

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-other-root/final/Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignored = ["github.com/sdboyer/deptest*", "github.com/golang/notexist/samples*"]

cmd/dep/testdata/harness_tests/ensure/pkg-ignored/wildcard-other-root/initial/Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignored = ["github.com/sdboyer/deptest*", "github.com/golang/notexist/samples*"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package samples
6+
7+
import _ "github.com/sdboyer/deptestdos"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package subsamples
6+
7+
import _ "github.com/sdboyer/dep-test"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-CONSTRAINTS-
2+
-IMPORTS/REQS-
3+
-IGNORES-
4+
github.com/sdboyer/deptest*
5+
-OVERRIDES-
6+
-ANALYZER-
7+
dep
8+
1
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
["ensure"],
4+
["hash-inputs"]
5+
],
6+
"error-expected": "",
7+
"vendor-final": []
8+
}

cmd/dep/testdata/harness_tests/init/glide/case1/final/Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ignored = ["github.com/sdboyer/dep-test","github.com/golang/notexist/samples"]
1+
ignored = ["github.com/golang/notexist/samples","github.com/sdboyer/dep-test"]
22

33
[[constraint]]
44
name = "github.com/carolynvs/deptest-subpkg"

internal/gps/hash.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"strings"
1414
)
1515

16-
const wcIgnoreSuffix = "*"
17-
1816
// string headers used to demarcate sections in hash input creation
1917
const (
2018
hhConstraints = "-CONSTRAINTS-"
@@ -81,30 +79,16 @@ func (s *solver) writeHashingInputs(w io.Writer) {
8179
// those will have already been implicitly incorporated by the import
8280
// lister.
8381
writeString(hhIgnores)
84-
ig := make([]string, 0, len(s.rd.ig))
85-
for pkg := range s.rd.ig {
86-
// Skip wildcard ignore. They are handled separately below.
87-
if strings.HasSuffix(pkg, wcIgnoreSuffix) {
88-
continue
89-
}
90-
91-
if !strings.HasPrefix(pkg, s.rd.rpt.ImportRoot) || !isPathPrefixOrEqual(s.rd.rpt.ImportRoot, pkg) {
92-
ig = append(ig, pkg)
93-
}
94-
}
95-
96-
// Add wildcard ignores to ignore list.
97-
if s.rd.igpfx != nil {
98-
s.rd.igpfx.Walk(func(s string, v interface{}) bool {
99-
ig = append(ig, s+"*")
100-
return false
101-
})
102-
}
10382

83+
ig := s.rd.ir.ToSlice()
10484
sort.Strings(ig)
105-
10685
for _, igp := range ig {
107-
writeString(igp)
86+
// Typical prefix comparison checks will erroneously fail if the wildcard
87+
// is present. Trim it off, if present.
88+
tigp := strings.TrimSuffix(igp, "*")
89+
if !strings.HasPrefix(tigp, s.rd.rpt.ImportRoot) || !isPathPrefixOrEqual(s.rd.rpt.ImportRoot, tigp) {
90+
writeString(igp)
91+
}
10892
}
10993

11094
// Overrides *also* need their own special entry distinct from basic

internal/gps/hash_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"strings"
1212
"testing"
1313
"text/tabwriter"
14+
15+
"github.com/golang/dep/internal/gps/pkgtree"
1416
)
1517

1618
func TestHashInputs(t *testing.T) {
@@ -64,10 +66,7 @@ func TestHashInputsReqsIgs(t *testing.T) {
6466
fix := basicFixtures["shared dependency with overlapping constraints"]
6567

6668
rm := fix.rootmanifest().(simpleRootManifest).dup()
67-
rm.ig = map[string]bool{
68-
"foo": true,
69-
"bar": true,
70-
}
69+
rm.ig = pkgtree.NewIgnoredRuleset([]string{"foo", "bar"})
7170

7271
params := SolveParameters{
7372
RootDir: string(fix.ds[0].n),
@@ -611,7 +610,7 @@ func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
611610

612611
cases := []struct {
613612
name string
614-
ignoreMap map[string]bool
613+
ignoreMap []string
615614
elems []string
616615
}{
617616
{
@@ -634,10 +633,10 @@ func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
634633
},
635634
{
636635
name: "different wildcard ignores",
637-
ignoreMap: map[string]bool{
638-
"foobar*": true,
639-
"foobarbaz*": true,
640-
"foozapbar*": true,
636+
ignoreMap: []string{
637+
"foobar*",
638+
"foobarbaz*",
639+
"foozapbar*",
641640
},
642641
elems: []string{
643642
hhConstraints,
@@ -662,7 +661,7 @@ func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
662661
for _, c := range cases {
663662
t.Run(c.name, func(t *testing.T) {
664663

665-
rm.ig = c.ignoreMap
664+
rm.ig = pkgtree.NewIgnoredRuleset(c.ignoreMap)
666665

667666
params.Manifest = rm
668667

internal/gps/manifest.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package gps
66

7+
import "github.com/golang/dep/internal/gps/pkgtree"
8+
79
// Manifest represents manifest-type data for a project at a particular version.
810
// The constraints expressed in a manifest determine the set of versions that
911
// are acceptable to try for a given project.
@@ -36,14 +38,15 @@ type RootManifest interface {
3638
// them can harm the ecosystem as a whole.
3739
Overrides() ProjectConstraints
3840

39-
// IngoredPackages returns a set of import paths to ignore. These import
40-
// paths can be within the root project, or part of other projects. Ignoring
41-
// a package means that both it and its (unique) imports will be disregarded
42-
// by all relevant solver operations.
41+
// IngoredPackages returns a pkgtree.IgnoredRuleset, which comprises a set
42+
// of import paths, or import path patterns, that are to be ignored during
43+
// solving. These ignored import paths can be within the root project, or
44+
// part of other projects. Ignoring a package means that both it and its
45+
// (unique) imports will be disregarded by all relevant solver operations.
4346
//
4447
// It is an error to include a package in both the ignored and required
4548
// sets.
46-
IgnoredPackages() map[string]bool
49+
IgnoredPackages() *pkgtree.IgnoredRuleset
4750

4851
// RequiredPackages returns a set of import paths to require. These packages
4952
// are required to be present in any solution. The list can include main
@@ -76,8 +79,9 @@ func (m SimpleManifest) DependencyConstraints() ProjectConstraints {
7679
// simpleRootManifest exists so that we have a safe value to swap into solver
7780
// params when a nil Manifest is provided.
7881
type simpleRootManifest struct {
79-
c, ovr ProjectConstraints
80-
ig, req map[string]bool
82+
c, ovr ProjectConstraints
83+
ig *pkgtree.IgnoredRuleset
84+
req map[string]bool
8185
}
8286

8387
func (m simpleRootManifest) DependencyConstraints() ProjectConstraints {
@@ -86,7 +90,7 @@ func (m simpleRootManifest) DependencyConstraints() ProjectConstraints {
8690
func (m simpleRootManifest) Overrides() ProjectConstraints {
8791
return m.ovr
8892
}
89-
func (m simpleRootManifest) IgnoredPackages() map[string]bool {
93+
func (m simpleRootManifest) IgnoredPackages() *pkgtree.IgnoredRuleset {
9094
return m.ig
9195
}
9296
func (m simpleRootManifest) RequiredPackages() map[string]bool {
@@ -96,7 +100,6 @@ func (m simpleRootManifest) dup() simpleRootManifest {
96100
m2 := simpleRootManifest{
97101
c: make(ProjectConstraints, len(m.c)),
98102
ovr: make(ProjectConstraints, len(m.ovr)),
99-
ig: make(map[string]bool, len(m.ig)),
100103
req: make(map[string]bool, len(m.req)),
101104
}
102105

@@ -106,13 +109,13 @@ func (m simpleRootManifest) dup() simpleRootManifest {
106109
for k, v := range m.ovr {
107110
m2.ovr[k] = v
108111
}
109-
for k, v := range m.ig {
110-
m2.ig[k] = v
111-
}
112112
for k, v := range m.req {
113113
m2.req[k] = v
114114
}
115115

116+
// IgnoredRulesets are immutable, and safe to reuse.
117+
m2.ig = m.ig
118+
116119
return m2
117120
}
118121

0 commit comments

Comments
 (0)