Chromium Code Reviews| Index: vpython/spec/match.go |
| diff --git a/vpython/spec/match.go b/vpython/spec/match.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e425cfa5d580c6a5d90daea1c1f601893a4878c6 |
| --- /dev/null |
| +++ b/vpython/spec/match.go |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2017 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package spec |
| + |
| +import ( |
| + "github.com/luci/luci-go/vpython/api/vpython" |
| +) |
| + |
| +// PackageMatches returns true if any of the match qualifiers in the supplied |
| +// package match the supplied PEP425 tags. |
|
qyearsley
2017/06/05 20:20:08
... match any of the supplied PEP425 tags.
dnj
2017/06/06 13:59:10
Done.
|
| +// |
| +// As a special case, if the package doesn't specify any match tags, it will |
| +// always match regardless of the supplied PEP425 tags. |
| +// |
| +// See PEP425Matches for more information. |
| +func PackageMatches(pkg *vpython.Spec_Package, tags []*vpython.Pep425Tag) bool { |
| + if len(pkg.MatchTag) == 0 { |
| + return true |
| + } |
| + |
| + for _, matchTag := range pkg.MatchTag { |
| + if PEP425Matches(matchTag, tags) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// PEP425Matches returns true if match matches at least one of the tags in tags. |
| +// |
| +// A match is determined if the non-zero fields in match equal the equivalent |
| +// fields in a tag. |
| +func PEP425Matches(match *vpython.Pep425Tag, tags []*vpython.Pep425Tag) bool { |
|
qyearsley
2017/06/05 20:20:08
For consistency, this could be called Pep425Matche
dnj
2017/06/06 13:59:10
The type is called "Pep425Tag" b/c it is derived f
|
| + // Special case: empty match matches nothing. |
| + if match.IsZero() { |
| + return false |
| + } |
| + |
| + for _, tag := range tags { |
| + if v := match.Version; v != "" && tag.Version != v { |
| + continue |
| + } |
| + if v := match.Abi; v != "" && tag.Abi != v { |
| + continue |
| + } |
| + if v := match.Arch; v != "" && tag.Arch != v { |
| + continue |
|
qyearsley
2017/06/05 20:20:08
Another Go question:
Is this equivalent to:
i
dnj
2017/06/06 13:59:10
Yes. Idiomatic Go is pretty cool with abbreviated
dnj
2017/06/06 13:59:10
Yes. Idiomatic Go is pretty cool with abbreviated
|
| + } |
| + return true |
| + } |
| + |
| + return false |
| +} |