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

Commit 1e70d28

Browse files
committed
gps: no ineffectual wildcard igs in hash inputs
1 parent 62401a7 commit 1e70d28

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

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

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/gps/hash.go

+18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import (
1111
"sort"
1212
"strconv"
1313
"strings"
14+
15+
"github.com/armon/go-radix"
1416
)
1517

18+
const wcIgnoreSuffix = "*"
19+
1620
// string headers used to demarcate sections in hash input creation
1721
const (
1822
hhConstraints = "-CONSTRAINTS-"
@@ -81,10 +85,24 @@ func (s *solver) writeHashingInputs(w io.Writer) {
8185
writeString(hhIgnores)
8286
ig := make([]string, 0, len(s.rd.ig))
8387
for pkg := range s.rd.ig {
88+
// Skip wildcard ignore. They are handled separately below.
89+
if strings.HasSuffix(pkg, wcIgnoreSuffix) {
90+
continue
91+
}
92+
8493
if !strings.HasPrefix(pkg, s.rd.rpt.ImportRoot) || !isPathPrefixOrEqual(s.rd.rpt.ImportRoot, pkg) {
8594
ig = append(ig, pkg)
8695
}
8796
}
97+
98+
// Add wildcard ignores to ignore list.
99+
if s.rd.igpfx != nil {
100+
s.rd.igpfx.Walk(radix.WalkFn(func(s string, v interface{}) bool {
101+
ig = append(ig, s+"*")
102+
return false
103+
}))
104+
}
105+
88106
sort.Strings(ig)
89107

90108
for _, igp := range ig {

internal/gps/hash_test.go

+91
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,94 @@ func diffHashingInputs(s Solver, wnt []string) string {
594594
tw.Flush()
595595
return buf.String()
596596
}
597+
598+
func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
599+
fix := basicFixtures["shared dependency with overlapping constraints"]
600+
601+
rm := fix.rootmanifest().(simpleRootManifest).dup()
602+
603+
params := SolveParameters{
604+
RootDir: string(fix.ds[0].n),
605+
RootPackageTree: fix.rootTree(),
606+
Manifest: rm,
607+
ProjectAnalyzer: naiveAnalyzer{},
608+
stdLibFn: func(string) bool { return false },
609+
mkBridgeFn: overrideMkBridge,
610+
}
611+
612+
cases := []struct {
613+
name string
614+
ignoreMap map[string]bool
615+
elems []string
616+
}{
617+
{
618+
name: "no wildcard ignores",
619+
elems: []string{
620+
hhConstraints,
621+
"a",
622+
"sv-1.0.0",
623+
"b",
624+
"sv-1.0.0",
625+
hhImportsReqs,
626+
"a",
627+
"b",
628+
hhIgnores,
629+
hhOverrides,
630+
hhAnalyzer,
631+
"naive-analyzer",
632+
"1",
633+
},
634+
},
635+
{
636+
name: "different wildcard ignores",
637+
ignoreMap: map[string]bool{
638+
"foobar*": true,
639+
"foobarbaz*": true,
640+
"foozapbar*": true,
641+
},
642+
elems: []string{
643+
hhConstraints,
644+
"a",
645+
"sv-1.0.0",
646+
"b",
647+
"sv-1.0.0",
648+
hhImportsReqs,
649+
"a",
650+
"b",
651+
hhIgnores,
652+
"foobar*",
653+
"foozapbar*",
654+
hhOverrides,
655+
hhAnalyzer,
656+
"naive-analyzer",
657+
"1",
658+
},
659+
},
660+
}
661+
662+
for _, c := range cases {
663+
t.Run(c.name, func(t *testing.T) {
664+
665+
rm.ig = c.ignoreMap
666+
667+
params.Manifest = rm
668+
669+
s, err := Prepare(params, newdepspecSM(fix.ds, nil))
670+
if err != nil {
671+
t.Fatalf("Unexpected error while prepping solver: %s", err)
672+
}
673+
674+
dig := s.HashInputs()
675+
h := sha256.New()
676+
677+
for _, v := range c.elems {
678+
h.Write([]byte(v))
679+
}
680+
correct := h.Sum(nil)
681+
682+
if !bytes.Equal(dig, correct) {
683+
t.Errorf("Hashes are not equal. Inputs:\n%s", diffHashingInputs(s, c.elems))
684+
}
685+
})
686+
}
687+
}

0 commit comments

Comments
 (0)