Skip to content

Commit

Permalink
Incorporate requires in input hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed Dec 15, 2016
1 parent e79bb7c commit cead778
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
22 changes: 17 additions & 5 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,26 @@ func (s *solver) HashInputs() []byte {
}
}

// Add the package ignores, if any.
// Write any require packages given in the root manifest.
if len(s.req) > 0 {
// Dump and sort the reqnores
req := make([]string, 0, len(s.req))
for pkg := range s.req {
req = append(req, pkg)
}
sort.Strings(req)

for _, reqp := range req {
buf.WriteString(reqp)
}
}

// Add the ignored packages, if any.
if len(s.ig) > 0 {
// Dump and sort the ignores
ig := make([]string, len(s.ig))
k := 0
ig := make([]string, 0, len(s.ig))
for pkg := range s.ig {
ig[k] = pkg
k++
ig = append(ig, pkg)
}
sort.Strings(ig)

Expand Down
82 changes: 81 additions & 1 deletion hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestHashInputs(t *testing.T) {
}
}

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

rm := fix.rootmanifest().(simpleRootManifest).dup()
Expand Down Expand Up @@ -93,6 +93,86 @@ func TestHashInputsIgnores(t *testing.T) {
if !bytes.Equal(dig, correct) {
t.Errorf("Hashes are not equal")
}

// Add requires
rm.req = map[string]bool{
"baz": true,
"qux": true,
}

params.Manifest = rm

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

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

elems = []string{
"a",
"1.0.0",
"b",
"1.0.0",
"root",
"",
"root",
"a",
"b",
"baz",
"qux",
"bar",
"foo",
"depspec-sm-builtin",
"1.0.0",
}
for _, v := range elems {
h.Write([]byte(v))
}
correct = h.Sum(nil)

if !bytes.Equal(dig, correct) {
t.Errorf("Hashes are not equal")
}

// remove ignores, just test requires alone
rm.ig = nil
params.Manifest = rm

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

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

elems = []string{
"a",
"1.0.0",
"b",
"1.0.0",
"root",
"",
"root",
"a",
"b",
"baz",
"qux",
"depspec-sm-builtin",
"1.0.0",
}
for _, v := range elems {
h.Write([]byte(v))
}
correct = h.Sum(nil)

if !bytes.Equal(dig, correct) {
t.Errorf("Hashes are not equal")
}
}

func TestHashInputsOverrides(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ func (s *solver) getImportsAndConstraintsOf(a atomWithPackages) ([]completeDep,
// are available, or Any() where they are not.
func (s *solver) intersectConstraintsWithImports(deps []workingConstraint, reach []string) ([]completeDep, error) {
// Create a radix tree with all the projects we know from the manifest
// TODO(sdboyer) make this smarter once we allow non-root inputs as 'projects'
xt := radix.New()
for _, dep := range deps {
xt.Insert(string(dep.Ident.ProjectRoot), dep)
Expand Down

0 comments on commit cead778

Please sign in to comment.