@@ -9,10 +9,26 @@ import (
9
9
10
10
// LockSatisfaction holds the compound result of LockSatisfiesInputs, allowing
11
11
// the caller to inspect each of several orthogonal possible types of failure.
12
+ //
13
+ // The zero value assumes that there was no input lock, which necessarily means
14
+ // the inputs were not satisfied. This zero value means we err on the side of
15
+ // failure.
12
16
type LockSatisfaction struct {
13
- nolock bool
14
- missingPkgs , excessPkgs []string
15
- badovr , badconstraint map [gps.ProjectRoot ]ConstraintMismatch
17
+ // If LockExisted is false, it indicates that a nil gps.Lock was passed to
18
+ // LockSatisfiesInputs().
19
+ LockExisted bool
20
+ // MissingImports is the set of import paths that were present in the
21
+ // inputs but missing in the Lock.
22
+ MissingImports []string
23
+ // ExcessImports is the set of import paths that were present in the Lock
24
+ // but absent from the inputs.
25
+ ExcessImports []string
26
+ // UnmatchedConstraints reports any normal, non-override constraint rules that
27
+ // were not satisfied by the corresponding LockedProject in the Lock.
28
+ UnmetConstraints map [gps.ProjectRoot ]ConstraintMismatch
29
+ // UnmatchedOverrides reports any override rules that were not satisfied by the
30
+ // corresponding LockedProject in the Lock.
31
+ UnmetOverrides map [gps.ProjectRoot ]ConstraintMismatch
16
32
}
17
33
18
34
// ConstraintMismatch is a two-tuple of a gps.Version, and a gps.Constraint that
@@ -30,9 +46,15 @@ type ConstraintMismatch struct {
30
46
// compute package imports that may have been removed. Figuring out that
31
47
// negative space would require exploring the entire graph to ensure there are
32
48
// no in-edges for particular imports.
33
- func LockSatisfiesInputs (l gps.Lock , m gps.RootManifest , rpt pkgtree.PackageTree ) LockSatisfaction {
49
+ func LockSatisfiesInputs (l gps.Lock , m gps.RootManifest , ptree pkgtree.PackageTree ) LockSatisfaction {
34
50
if l == nil {
35
- return LockSatisfaction {nolock : true }
51
+ return LockSatisfaction {}
52
+ }
53
+
54
+ lsat := LockSatisfaction {
55
+ LockExisted : true ,
56
+ UnmetOverrides : make (map [gps.ProjectRoot ]ConstraintMismatch ),
57
+ UnmetConstraints : make (map [gps.ProjectRoot ]ConstraintMismatch ),
36
58
}
37
59
38
60
var ig * pkgtree.IgnoredRuleset
@@ -42,7 +64,7 @@ func LockSatisfiesInputs(l gps.Lock, m gps.RootManifest, rpt pkgtree.PackageTree
42
64
req = m .RequiredPackages ()
43
65
}
44
66
45
- rm , _ := rpt .ToReachMap (true , true , false , ig )
67
+ rm , _ := ptree .ToReachMap (true , true , false , ig )
46
68
reach := rm .FlattenFn (paths .IsStandardImportPath )
47
69
48
70
inlock := make (map [string ]bool , len (l .InputImports ()))
@@ -68,11 +90,6 @@ func LockSatisfiesInputs(l gps.Lock, m gps.RootManifest, rpt pkgtree.PackageTree
68
90
inlock [imp ] = true
69
91
}
70
92
71
- lsat := LockSatisfaction {
72
- badovr : make (map [gps.ProjectRoot ]ConstraintMismatch ),
73
- badconstraint : make (map [gps.ProjectRoot ]ConstraintMismatch ),
74
- }
75
-
76
93
for ip := range ininputs {
77
94
if ! inlock [ip ] {
78
95
pkgDiff [ip ] = missingFromLock
@@ -96,9 +113,9 @@ func LockSatisfiesInputs(l gps.Lock, m gps.RootManifest, rpt pkgtree.PackageTree
96
113
97
114
for ip , typ := range pkgDiff {
98
115
if typ == missingFromLock {
99
- lsat .missingPkgs = append (lsat .missingPkgs , ip )
116
+ lsat .MissingImports = append (lsat .MissingImports , ip )
100
117
} else {
101
- lsat .excessPkgs = append (lsat .excessPkgs , ip )
118
+ lsat .ExcessImports = append (lsat .ExcessImports , ip )
102
119
}
103
120
}
104
121
@@ -110,7 +127,7 @@ func LockSatisfiesInputs(l gps.Lock, m gps.RootManifest, rpt pkgtree.PackageTree
110
127
111
128
if pp , has := ovr [pr ]; has {
112
129
if ! pp .Constraint .Matches (lp .Version ()) {
113
- lsat .badovr [pr ] = ConstraintMismatch {
130
+ lsat .UnmetOverrides [pr ] = ConstraintMismatch {
114
131
C : pp .Constraint ,
115
132
V : lp .Version (),
116
133
}
@@ -121,7 +138,7 @@ func LockSatisfiesInputs(l gps.Lock, m gps.RootManifest, rpt pkgtree.PackageTree
121
138
}
122
139
123
140
if pp , has := constraints [pr ]; has && eff [string (pr )] && ! pp .Constraint .Matches (lp .Version ()) {
124
- lsat .badconstraint [pr ] = ConstraintMismatch {
141
+ lsat .UnmetConstraints [pr ] = ConstraintMismatch {
125
142
C : pp .Constraint ,
126
143
V : lp .Version (),
127
144
}
@@ -131,57 +148,33 @@ func LockSatisfiesInputs(l gps.Lock, m gps.RootManifest, rpt pkgtree.PackageTree
131
148
return lsat
132
149
}
133
150
134
- // Passed is a shortcut method that indicates whether there were any ways in
135
- // which the Lock did not satisfy the inputs. It will return true only if no
136
- // problems were found .
137
- func (ls LockSatisfaction ) Passed () bool {
138
- if ls .nolock {
151
+ // Satisfied is a shortcut method that indicates whether there were any ways in
152
+ // which the Lock did not satisfy the inputs. It will return true only if the
153
+ // Lock was satisfactory in all respects vis-a-vis the inputs .
154
+ func (ls LockSatisfaction ) Satisfied () bool {
155
+ if ! ls .LockExisted {
139
156
return false
140
157
}
141
158
142
- if len (ls .missingPkgs ) > 0 {
159
+ if len (ls .MissingImports ) > 0 {
143
160
return false
144
161
}
145
162
146
- if len (ls .excessPkgs ) > 0 {
163
+ if len (ls .ExcessImports ) > 0 {
147
164
return false
148
165
}
149
166
150
- if len (ls .badovr ) > 0 {
167
+ if len (ls .UnmetOverrides ) > 0 {
151
168
return false
152
169
}
153
170
154
- if len (ls .badconstraint ) > 0 {
171
+ if len (ls .UnmetConstraints ) > 0 {
155
172
return false
156
173
}
157
174
158
175
return true
159
176
}
160
177
161
- // MissingImports reports the set of import paths that were present in the
162
- // inputs but missing in the Lock.
163
- func (ls LockSatisfaction ) MissingImports () []string {
164
- return ls .missingPkgs
165
- }
166
-
167
- // ExcessImports reports the set of import paths that were present in the Lock
168
- // but absent from the inputs.
169
- func (ls LockSatisfaction ) ExcessImports () []string {
170
- return ls .excessPkgs
171
- }
172
-
173
- // UnmatchedOverrides reports any override rules that were not satisfied by the
174
- // corresponding LockedProject in the Lock.
175
- func (ls LockSatisfaction ) UnmatchedOverrides () map [gps.ProjectRoot ]ConstraintMismatch {
176
- return ls .badovr
177
- }
178
-
179
- // UnmatchedConstraints reports any normal, non-override constraint rules that
180
- // were not satisfied by the corresponding LockedProject in the Lock.
181
- func (ls LockSatisfaction ) UnmatchedConstraints () map [gps.ProjectRoot ]ConstraintMismatch {
182
- return ls .badconstraint
183
- }
184
-
185
178
func findEffectualConstraints (m gps.Manifest , imports map [string ]bool ) map [string ]bool {
186
179
eff := make (map [string ]bool )
187
180
xt := radix .New ()
0 commit comments