Rename VersionSet to Constraints
VersionSet is a wrapper around version.Contraints, so rename it it as such.
This commit is contained in:
parent
718ede0636
commit
7d2d951f27
|
@ -94,7 +94,7 @@ func providersCommandPopulateTreeNode(node treeprint.Tree, deps *moduledeps.Modu
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
dep := deps.Providers[moduledeps.ProviderInstance(name)]
|
dep := deps.Providers[moduledeps.ProviderInstance(name)]
|
||||||
versionsStr := dep.Versions.String()
|
versionsStr := dep.Constraints.String()
|
||||||
if versionsStr != "" {
|
if versionsStr != "" {
|
||||||
versionsStr = " " + versionsStr
|
versionsStr = " " + versionsStr
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ type Providers map[ProviderInstance]ProviderDependency
|
||||||
// instance, including both the set of allowed versions and the reason for
|
// instance, including both the set of allowed versions and the reason for
|
||||||
// the dependency.
|
// the dependency.
|
||||||
type ProviderDependency struct {
|
type ProviderDependency struct {
|
||||||
Versions discovery.VersionSet
|
Constraints discovery.Constraints
|
||||||
Reason ProviderDependencyReason
|
Reason ProviderDependencyReason
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProviderDependencyReason is an enumeration of reasons why a dependency might be
|
// ProviderDependencyReason is an enumeration of reasons why a dependency might be
|
||||||
|
|
|
@ -114,9 +114,9 @@ func (m *Module) PluginRequirements() discovery.PluginRequirements {
|
||||||
// by using Intersection to merge the version sets.
|
// by using Intersection to merge the version sets.
|
||||||
pty := inst.Type()
|
pty := inst.Type()
|
||||||
if existing, exists := ret[pty]; exists {
|
if existing, exists := ret[pty]; exists {
|
||||||
ret[pty] = existing.Intersection(dep.Versions)
|
ret[pty] = existing.Intersection(dep.Constraints)
|
||||||
} else {
|
} else {
|
||||||
ret[pty] = dep.Versions
|
ret[pty] = dep.Constraints
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
@ -163,7 +163,7 @@ func (m *Module) Equal(other *Module) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't use reflect.DeepEqual on this provider structure because
|
// Can't use reflect.DeepEqual on this provider structure because
|
||||||
// the nested VersionSet objects contain function pointers that
|
// the nested Constraints objects contain function pointers that
|
||||||
// never compare as equal. So we'll need to walk it the long way.
|
// never compare as equal. So we'll need to walk it the long way.
|
||||||
for inst, dep := range m.Providers {
|
for inst, dep := range m.Providers {
|
||||||
if _, exists := other.Providers[inst]; !exists {
|
if _, exists := other.Providers[inst]; !exists {
|
||||||
|
@ -174,10 +174,10 @@ func (m *Module) Equal(other *Module) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionSets are not too easy to compare robustly, so
|
// Constraints are not too easy to compare robustly, so
|
||||||
// we'll just use their string representations as a proxy
|
// we'll just use their string representations as a proxy
|
||||||
// for now.
|
// for now.
|
||||||
if dep.Versions.String() != other.Providers[inst].Versions.String() {
|
if dep.Constraints.String() != other.Providers[inst].Constraints.String() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,13 +192,13 @@ func TestModulePluginRequirements(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: Providers{
|
Providers: Providers{
|
||||||
"foo": ProviderDependency{
|
"foo": ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||||
},
|
},
|
||||||
"foo.bar": ProviderDependency{
|
"foo.bar": ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||||
},
|
},
|
||||||
"baz": ProviderDependency{
|
"baz": ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=3.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=3.0.0").MustParse(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ package discovery
|
||||||
// kind) that are required to exist and have versions within the given
|
// kind) that are required to exist and have versions within the given
|
||||||
// corresponding sets.
|
// corresponding sets.
|
||||||
//
|
//
|
||||||
// PluginRequirements is a map from plugin name to VersionSet.
|
// PluginRequirements is a map from plugin name to Constraints.
|
||||||
type PluginRequirements map[string]VersionSet
|
type PluginRequirements map[string]Constraints
|
||||||
|
|
||||||
// Merge takes the contents of the receiver and the other given requirements
|
// Merge takes the contents of the receiver and the other given requirements
|
||||||
// object and merges them together into a single requirements structure
|
// object and merges them together into a single requirements structure
|
||||||
|
|
|
@ -9,18 +9,18 @@ import (
|
||||||
// obtain a real Constraint object, or discover that it is invalid.
|
// obtain a real Constraint object, or discover that it is invalid.
|
||||||
type ConstraintStr string
|
type ConstraintStr string
|
||||||
|
|
||||||
// Parse transforms a ConstraintStr into a VersionSet if it is
|
// Parse transforms a ConstraintStr into a Constraints if it is
|
||||||
// syntactically valid. If it isn't then an error is returned instead.
|
// syntactically valid. If it isn't then an error is returned instead.
|
||||||
func (s ConstraintStr) Parse() (VersionSet, error) {
|
func (s ConstraintStr) Parse() (Constraints, error) {
|
||||||
raw, err := version.NewConstraint(string(s))
|
raw, err := version.NewConstraint(string(s))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return VersionSet{}, err
|
return Constraints{}, err
|
||||||
}
|
}
|
||||||
return VersionSet{raw}, nil
|
return Constraints{raw}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustParse is like Parse but it panics if the constraint string is invalid.
|
// MustParse is like Parse but it panics if the constraint string is invalid.
|
||||||
func (s ConstraintStr) MustParse() VersionSet {
|
func (s ConstraintStr) MustParse() Constraints {
|
||||||
ret, err := s.Parse()
|
ret, err := s.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -28,33 +28,30 @@ func (s ConstraintStr) MustParse() VersionSet {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionSet represents a set of versions which any given Version is either
|
// Constraints represents a set of versions which any given Version is either
|
||||||
// a member of or not.
|
// a member of or not.
|
||||||
type VersionSet struct {
|
type Constraints struct {
|
||||||
// Internally a version set is actually a list of constraints that
|
|
||||||
// *remove* versions from the set. Thus a VersionSet with an empty
|
|
||||||
// Constraints list would be one that contains *all* versions.
|
|
||||||
raw version.Constraints
|
raw version.Constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllVersions is a VersionSet containing all versions
|
// AllVersions is a Constraints containing all versions
|
||||||
var AllVersions VersionSet
|
var AllVersions Constraints
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
AllVersions = VersionSet{
|
AllVersions = Constraints{
|
||||||
raw: make(version.Constraints, 0),
|
raw: make(version.Constraints, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has returns true if the given version is in the receiving set.
|
// Has returns true if the given version is in the receiving set.
|
||||||
func (s VersionSet) Has(v Version) bool {
|
func (s Constraints) Has(v Version) bool {
|
||||||
return s.raw.Check(v.raw)
|
return s.raw.Check(v.raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intersection combines the receving set with the given other set to produce a
|
// Intersection combines the receiving set with the given other set to produce
|
||||||
// set that is the intersection of both sets, which is to say that it contains
|
// a set that is the intersection of both sets, which is to say that resulting
|
||||||
// only the versions that are members of both sets.
|
// constraints contain only the versions that are members of both.
|
||||||
func (s VersionSet) Intersection(other VersionSet) VersionSet {
|
func (s Constraints) Intersection(other Constraints) Constraints {
|
||||||
raw := make(version.Constraints, 0, len(s.raw)+len(other.raw))
|
raw := make(version.Constraints, 0, len(s.raw)+len(other.raw))
|
||||||
|
|
||||||
// Since "raw" is a list of constraints that remove versions from the set,
|
// Since "raw" is a list of constraints that remove versions from the set,
|
||||||
|
@ -63,11 +60,11 @@ func (s VersionSet) Intersection(other VersionSet) VersionSet {
|
||||||
raw = append(raw, s.raw...)
|
raw = append(raw, s.raw...)
|
||||||
raw = append(raw, other.raw...)
|
raw = append(raw, other.raw...)
|
||||||
|
|
||||||
return VersionSet{raw}
|
return Constraints{raw}
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a string representation of the set members as a set
|
// String returns a string representation of the set members as a set
|
||||||
// of range constraints.
|
// of range constraints.
|
||||||
func (s VersionSet) String() string {
|
func (s Constraints) String() string {
|
||||||
return s.raw.String()
|
return s.raw.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ func moduleTreeConfigDependencies(root *module.Tree, inheritProviders map[string
|
||||||
versionSet = discovery.ConstraintStr(pCfg.Version).MustParse()
|
versionSet = discovery.ConstraintStr(pCfg.Version).MustParse()
|
||||||
}
|
}
|
||||||
providers[inst] = moduledeps.ProviderDependency{
|
providers[inst] = moduledeps.ProviderDependency{
|
||||||
Versions: versionSet,
|
Constraints: versionSet,
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ func moduleTreeConfigDependencies(root *module.Tree, inheritProviders map[string
|
||||||
}
|
}
|
||||||
|
|
||||||
providers[inst] = moduledeps.ProviderDependency{
|
providers[inst] = moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: reason,
|
Reason: reason,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +146,8 @@ func moduleTreeMergeStateDependencies(root *moduledeps.Module, state *State) {
|
||||||
module.Providers = make(moduledeps.Providers)
|
module.Providers = make(moduledeps.Providers)
|
||||||
}
|
}
|
||||||
module.Providers[inst] = moduledeps.ProviderDependency{
|
module.Providers[inst] = moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyFromState,
|
Reason: moduledeps.ProviderDependencyFromState,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
"foo.bar": moduledeps.ProviderDependency{
|
"foo.bar": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: nil,
|
Children: nil,
|
||||||
|
@ -58,8 +58,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: nil,
|
Children: nil,
|
||||||
|
@ -72,12 +72,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyImplicit,
|
Reason: moduledeps.ProviderDependencyImplicit,
|
||||||
},
|
},
|
||||||
"foo.baz": moduledeps.ProviderDependency{
|
"foo.baz": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyImplicit,
|
Reason: moduledeps.ProviderDependencyImplicit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: nil,
|
Children: nil,
|
||||||
|
@ -90,8 +90,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: nil,
|
Children: nil,
|
||||||
|
@ -104,12 +104,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
"bar": moduledeps.ProviderDependency{
|
"bar": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: []*moduledeps.Module{
|
Children: []*moduledeps.Module{
|
||||||
|
@ -117,12 +117,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "child",
|
Name: "child",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyInherited,
|
Reason: moduledeps.ProviderDependencyInherited,
|
||||||
},
|
},
|
||||||
"baz": moduledeps.ProviderDependency{
|
"baz": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyImplicit,
|
Reason: moduledeps.ProviderDependencyImplicit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: []*moduledeps.Module{
|
Children: []*moduledeps.Module{
|
||||||
|
@ -130,12 +130,12 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "grandchild",
|
Name: "grandchild",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
"bar": moduledeps.ProviderDependency{
|
"bar": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyInherited,
|
Reason: moduledeps.ProviderDependencyInherited,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -163,8 +163,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyFromState,
|
Reason: moduledeps.ProviderDependencyFromState,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: nil,
|
Children: nil,
|
||||||
|
@ -209,16 +209,16 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"foo": moduledeps.ProviderDependency{
|
"foo": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
"foo.bar": moduledeps.ProviderDependency{
|
"foo.bar": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
Constraints: discovery.ConstraintStr(">=2.0.0").MustParse(),
|
||||||
Reason: moduledeps.ProviderDependencyExplicit,
|
Reason: moduledeps.ProviderDependencyExplicit,
|
||||||
},
|
},
|
||||||
"baz": moduledeps.ProviderDependency{
|
"baz": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyFromState,
|
Reason: moduledeps.ProviderDependencyFromState,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Children: []*moduledeps.Module{
|
Children: []*moduledeps.Module{
|
||||||
|
@ -229,8 +229,8 @@ func TestModuleTreeDependencies(t *testing.T) {
|
||||||
Name: "grandchild",
|
Name: "grandchild",
|
||||||
Providers: moduledeps.Providers{
|
Providers: moduledeps.Providers{
|
||||||
"banana": moduledeps.ProviderDependency{
|
"banana": moduledeps.ProviderDependency{
|
||||||
Versions: discovery.AllVersions,
|
Constraints: discovery.AllVersions,
|
||||||
Reason: moduledeps.ProviderDependencyFromState,
|
Reason: moduledeps.ProviderDependencyFromState,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
--- FAIL: TestContext2Plan_moduleProviderInherit (0.01s)
|
||||||
|
context_plan_test.go:552: bad: []string{"child"}
|
||||||
|
map[string]dag.Vertex{}
|
||||||
|
"module.middle.null"
|
||||||
|
map[string]dag.Vertex{}
|
||||||
|
"module.middle.module.inner.null"
|
||||||
|
map[string]dag.Vertex{}
|
||||||
|
"aws"
|
||||||
|
FAIL
|
Loading…
Reference in New Issue