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

Commit

Permalink
gps: no ineffectual wildcard igs in hash inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Sep 28, 2017
1 parent 893b197 commit 68ac3c2
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions internal/gps/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import (
"sort"
"strconv"
"strings"

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

const wcIgnoreSuffix = "*"

// string headers used to demarcate sections in hash input creation
const (
hhConstraints = "-CONSTRAINTS-"
Expand Down Expand Up @@ -81,10 +85,24 @@ func (s *solver) writeHashingInputs(w io.Writer) {
writeString(hhIgnores)
ig := make([]string, 0, len(s.rd.ig))
for pkg := range s.rd.ig {
// Skip wildcard ignore. They are handled separately below.
if strings.HasSuffix(pkg, wcIgnoreSuffix) {
continue
}

if !strings.HasPrefix(pkg, s.rd.rpt.ImportRoot) || !isPathPrefixOrEqual(s.rd.rpt.ImportRoot, pkg) {
ig = append(ig, pkg)
}
}

// Add wildcard ignores to ignore list.
if s.rd.igpfx != nil {
s.rd.igpfx.Walk(radix.WalkFn(func(s string, v interface{}) bool {
ig = append(ig, s+"*")
return false
}))
}

sort.Strings(ig)

for _, igp := range ig {
Expand Down
91 changes: 91 additions & 0 deletions internal/gps/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,94 @@ func diffHashingInputs(s Solver, wnt []string) string {
tw.Flush()
return buf.String()
}

func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
fix := basicFixtures["shared dependency with overlapping constraints"]

rm := fix.rootmanifest().(simpleRootManifest).dup()

params := SolveParameters{
RootDir: string(fix.ds[0].n),
RootPackageTree: fix.rootTree(),
Manifest: rm,
ProjectAnalyzer: naiveAnalyzer{},
stdLibFn: func(string) bool { return false },
mkBridgeFn: overrideMkBridge,
}

cases := []struct {
name string
ignoreMap map[string]bool
elems []string
}{
{
name: "no wildcard ignores",
elems: []string{
hhConstraints,
"a",
"sv-1.0.0",
"b",
"sv-1.0.0",
hhImportsReqs,
"a",
"b",
hhIgnores,
hhOverrides,
hhAnalyzer,
"naive-analyzer",
"1",
},
},
{
name: "different wildcard ignores",
ignoreMap: map[string]bool{
"foobar*": true,
"foobarbaz*": true,
"foozapbar*": true,
},
elems: []string{
hhConstraints,
"a",
"sv-1.0.0",
"b",
"sv-1.0.0",
hhImportsReqs,
"a",
"b",
hhIgnores,
"foobar*",
"foozapbar*",
hhOverrides,
hhAnalyzer,
"naive-analyzer",
"1",
},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

rm.ig = c.ignoreMap

params.Manifest = rm

s, err := Prepare(params, newdepspecSM(fix.ds, nil))
if err != nil {
t.Fatalf("Unexpected error while prepping solver: %s", err)
}

dig := s.HashInputs()
h := sha256.New()

for _, v := range c.elems {
h.Write([]byte(v))
}
correct := h.Sum(nil)

if !bytes.Equal(dig, correct) {
t.Errorf("Hashes are not equal. Inputs:\n%s", diffHashingInputs(s, c.elems))
}
})
}
}

0 comments on commit 68ac3c2

Please sign in to comment.