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

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

Issue 2921133002: [vpython] Add conditional packages based on PEP425 (Closed)
Patch Set: rebase 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
« no previous file with comments | « vpython/application/subcommand_verify.go ('k') | vpython/spec/match_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 at least one of the supplied PEP425 tags.
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 {
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
50 }
51 return true
52 }
53
54 return false
55 }
OLDNEW
« no previous file with comments | « vpython/application/subcommand_verify.go ('k') | vpython/spec/match_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698