Skip to content

Commit cead778

Browse files
committed
Incorporate requires in input hashing
Fixes golang#121
1 parent e79bb7c commit cead778

File tree

3 files changed

+98
-7
lines changed

3 files changed

+98
-7
lines changed

hash.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,26 @@ func (s *solver) HashInputs() []byte {
5858
}
5959
}
6060

61-
// Add the package ignores, if any.
61+
// Write any require packages given in the root manifest.
62+
if len(s.req) > 0 {
63+
// Dump and sort the reqnores
64+
req := make([]string, 0, len(s.req))
65+
for pkg := range s.req {
66+
req = append(req, pkg)
67+
}
68+
sort.Strings(req)
69+
70+
for _, reqp := range req {
71+
buf.WriteString(reqp)
72+
}
73+
}
74+
75+
// Add the ignored packages, if any.
6276
if len(s.ig) > 0 {
6377
// Dump and sort the ignores
64-
ig := make([]string, len(s.ig))
65-
k := 0
78+
ig := make([]string, 0, len(s.ig))
6679
for pkg := range s.ig {
67-
ig[k] = pkg
68-
k++
80+
ig = append(ig, pkg)
6981
}
7082
sort.Strings(ig)
7183

hash_test.go

+81-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestHashInputs(t *testing.T) {
4646
}
4747
}
4848

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

5252
rm := fix.rootmanifest().(simpleRootManifest).dup()
@@ -93,6 +93,86 @@ func TestHashInputsIgnores(t *testing.T) {
9393
if !bytes.Equal(dig, correct) {
9494
t.Errorf("Hashes are not equal")
9595
}
96+
97+
// Add requires
98+
rm.req = map[string]bool{
99+
"baz": true,
100+
"qux": true,
101+
}
102+
103+
params.Manifest = rm
104+
105+
s, err = Prepare(params, newdepspecSM(fix.ds, nil))
106+
if err != nil {
107+
t.Errorf("Unexpected error while prepping solver: %s", err)
108+
t.FailNow()
109+
}
110+
111+
dig = s.HashInputs()
112+
h = sha256.New()
113+
114+
elems = []string{
115+
"a",
116+
"1.0.0",
117+
"b",
118+
"1.0.0",
119+
"root",
120+
"",
121+
"root",
122+
"a",
123+
"b",
124+
"baz",
125+
"qux",
126+
"bar",
127+
"foo",
128+
"depspec-sm-builtin",
129+
"1.0.0",
130+
}
131+
for _, v := range elems {
132+
h.Write([]byte(v))
133+
}
134+
correct = h.Sum(nil)
135+
136+
if !bytes.Equal(dig, correct) {
137+
t.Errorf("Hashes are not equal")
138+
}
139+
140+
// remove ignores, just test requires alone
141+
rm.ig = nil
142+
params.Manifest = rm
143+
144+
s, err = Prepare(params, newdepspecSM(fix.ds, nil))
145+
if err != nil {
146+
t.Errorf("Unexpected error while prepping solver: %s", err)
147+
t.FailNow()
148+
}
149+
150+
dig = s.HashInputs()
151+
h = sha256.New()
152+
153+
elems = []string{
154+
"a",
155+
"1.0.0",
156+
"b",
157+
"1.0.0",
158+
"root",
159+
"",
160+
"root",
161+
"a",
162+
"b",
163+
"baz",
164+
"qux",
165+
"depspec-sm-builtin",
166+
"1.0.0",
167+
}
168+
for _, v := range elems {
169+
h.Write([]byte(v))
170+
}
171+
correct = h.Sum(nil)
172+
173+
if !bytes.Equal(dig, correct) {
174+
t.Errorf("Hashes are not equal")
175+
}
96176
}
97177

98178
func TestHashInputsOverrides(t *testing.T) {

solver.go

-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ func (s *solver) getImportsAndConstraintsOf(a atomWithPackages) ([]completeDep,
613613
// are available, or Any() where they are not.
614614
func (s *solver) intersectConstraintsWithImports(deps []workingConstraint, reach []string) ([]completeDep, error) {
615615
// Create a radix tree with all the projects we know from the manifest
616-
// TODO(sdboyer) make this smarter once we allow non-root inputs as 'projects'
617616
xt := radix.New()
618617
for _, dep := range deps {
619618
xt.Insert(string(dep.Ident.ProjectRoot), dep)

0 commit comments

Comments
 (0)