-
Notifications
You must be signed in to change notification settings - Fork 14
Match and Compare platforms with OSFeatures #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,10 @@ type Matcher interface { | |
| // functionality. | ||
| // | ||
| // Applications should opt to use `Match` over directly parsing specifiers. | ||
| // | ||
| // For OSFeatures, this matcher will match if the platform to match has | ||
| // OSFeatures which are a subset of the OSFeatures of the platform | ||
| // provided to NewMatcher. | ||
| func NewMatcher(platform specs.Platform) Matcher { | ||
| m := &matcher{ | ||
| Platform: Normalize(platform), | ||
|
|
@@ -177,10 +181,39 @@ type matcher struct { | |
|
|
||
| func (m *matcher) Match(platform specs.Platform) bool { | ||
| normalized := Normalize(platform) | ||
| return m.OS == normalized.OS && | ||
| if m.OS == normalized.OS && | ||
| m.Architecture == normalized.Architecture && | ||
| m.Variant == normalized.Variant && | ||
| m.matchOSVersion(platform) | ||
| m.matchOSVersion(platform) { | ||
| if len(normalized.OSFeatures) == 0 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iiuc this is backwards.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway, what I can think out is that I think we could differentiate which kinds of But all
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise, if no |
||
| return true | ||
| } | ||
| if len(m.OSFeatures) >= len(normalized.OSFeatures) { | ||
| // Ensure that normalized.OSFeatures is a subset of | ||
| // m.OSFeatures | ||
| j := 0 | ||
| for _, feature := range normalized.OSFeatures { | ||
| found := false | ||
| for ; j < len(m.OSFeatures); j++ { | ||
| if feature == m.OSFeatures[j] { | ||
| found = true | ||
| j++ | ||
| break | ||
| } | ||
| // Since both lists are ordered, if the feature is less | ||
| // than what is seen, it is not in the list | ||
| if feature < m.OSFeatures[j] { | ||
| return false | ||
| } | ||
| } | ||
| if !found { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (m *matcher) matchOSVersion(platform specs.Platform) bool { | ||
|
|
@@ -350,6 +383,11 @@ func FormatAll(platform specs.Platform) string { | |
| func Normalize(platform specs.Platform) specs.Platform { | ||
| platform.OS = normalizeOS(platform.OS) | ||
| platform.Architecture, platform.Variant = normalizeArch(platform.Architecture, platform.Variant) | ||
| if len(platform.OSFeatures) > 0 { | ||
| platform.OSFeatures = slices.Clone(platform.OSFeatures) | ||
| slices.Sort(platform.OSFeatures) | ||
| platform.OSFeatures = slices.Compact(platform.OSFeatures) | ||
| } | ||
|
|
||
| return platform | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.