Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: vpython/spec/match.go

Issue 2921133002: [vpython] Add conditional packages based on PEP425 (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package spec
6
7 import (
8 "github.com/luci/luci-go/vpython/api/vpython"
9 )
10
11 // PackageMatches returns true if any of the match qualifiers in the supplied
12 // 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.
13 //
14 // As a special case, if the package doesn't specify any match tags, it will
15 // always match regardless of the supplied PEP425 tags.
16 //
17 // See PEP425Matches for more information.
18 func PackageMatches(pkg *vpython.Spec_Package, tags []*vpython.Pep425Tag) bool {
19 if len(pkg.MatchTag) == 0 {
20 return true
21 }
22
23 for _, matchTag := range pkg.MatchTag {
24 if PEP425Matches(matchTag, tags) {
25 return true
26 }
27 }
28 return false
29 }
30
31 // PEP425Matches returns true if match matches at least one of the tags in tags.
32 //
33 // A match is determined if the non-zero fields in match equal the equivalent
34 // fields in a tag.
35 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
36 // Special case: empty match matches nothing.
37 if match.IsZero() {
38 return false
39 }
40
41 for _, tag := range tags {
42 if v := match.Version; v != "" && tag.Version != v {
43 continue
44 }
45 if v := match.Abi; v != "" && tag.Abi != v {
46 continue
47 }
48 if v := match.Arch; v != "" && tag.Arch != v {
49 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
50 }
51 return true
52 }
53
54 return false
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698