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

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

Issue 2971403002: [vpython] Enable base wheels, spec merging. (Closed)
Patch Set: fix comment Created 3 years, 5 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/options.go ('k') | vpython/spec/spec_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
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package spec 5 package spec
6 6
7 import ( 7 import (
8 "crypto/sha256" 8 "crypto/sha256"
9 "encoding/hex" 9 "encoding/hex"
10 "fmt" 10 "fmt"
(...skipping 24 matching lines...) Expand all
35 env.Runtime = &vpython.Runtime{} 35 env.Runtime = &vpython.Runtime{}
36 } 36 }
37 37
38 sort.Sort(pep425TagSlice(env.Pep425Tag)) 38 sort.Sort(pep425TagSlice(env.Pep425Tag))
39 return nil 39 return nil
40 } 40 }
41 41
42 // NormalizeSpec normalizes the specification Message such that two messages 42 // NormalizeSpec normalizes the specification Message such that two messages
43 // with identical meaning will have identical representation. 43 // with identical meaning will have identical representation.
44 // 44 //
45 // If multiple wheel entries exist for the same package name, they must also
46 // share a version. If they don't, an error will be returned. Otherwise, they
47 // will be merged into a single wheel entry.
48 //
45 // NormalizeSpec will prune any Wheel entries that don't match the specified 49 // NormalizeSpec will prune any Wheel entries that don't match the specified
46 // tags, and will remove the match entries from any remaining Wheel entries. 50 // tags, and will remove the match entries from any remaining Wheel entries.
47 func NormalizeSpec(spec *vpython.Spec, tags []*vpython.PEP425Tag) error { 51 func NormalizeSpec(spec *vpython.Spec, tags []*vpython.PEP425Tag) error {
48 » if spec.Virtualenv != nil && len(spec.Virtualenv.MatchTag) > 0 { 52 » // If we have a VirtualEnv package, validate and normalize it.
49 » » // The VirtualEnv package may not specify a match tag. 53 » if pkg := spec.Virtualenv; pkg != nil {
50 » » spec.Virtualenv.MatchTag = nil 54 » » if len(pkg.MatchTag) > 0 {
55 » » » // The VirtualEnv package may not specify a match tag.
56 » » » pkg.MatchTag = nil
57 » » }
51 } 58 }
52 59
53 // Apply match filters, prune any entries that don't match, and clear th e 60 // Apply match filters, prune any entries that don't match, and clear th e
54 // MatchTag entries for those that do. 61 // MatchTag entries for those that do.
62 //
63 // Make sure the VirtualEnv package isn't listed in the wheels list.
64 //
65 // Track the versions for each package and assert that any duplicate pac kages
66 // don't share a version.
55 pos := 0 67 pos := 0
56 » for _, wheel := range spec.Wheel { 68 » packageVersions := make(map[string]string, len(spec.Wheel))
57 » » if !PackageMatches(wheel, tags) { 69 » for _, w := range spec.Wheel {
70 » » if spec.Virtualenv != nil && spec.Virtualenv.Name == w.Name {
71 » » » return errors.Reason("wheel %q cannot be the VirtualEnv package", w.Name).Err()
72 » » }
73
74 » » // If this package has already been included, assert version con sistency.
75 » » if v, ok := packageVersions[w.Name]; ok {
76 » » » if v != w.Version {
77 » » » » return errors.Reason("multiple versions for pack age %q: %q != %q", w.Name, w.Version, v).Err()
78 » » » }
79
80 » » » // This package has already been included, so we can ign ore it.
58 continue 81 continue
59 } 82 }
60 83
61 » » wheel.MatchTag = nil 84 » » // If this package doesn't match the tag set, skip it.
62 » » spec.Wheel[pos] = wheel 85 » » if !PackageMatches(w, tags) {
86 » » » continue
87 » » }
88
89 » » // Mark that this package was included, so we can assert version consistency
90 » » // and avoid duplicates.
91 » » packageVersions[w.Name] = w.Version
92 » » w.MatchTag = nil
93 » » spec.Wheel[pos] = w
63 pos++ 94 pos++
64 } 95 }
65 spec.Wheel = spec.Wheel[:pos] 96 spec.Wheel = spec.Wheel[:pos]
66
67 sort.Sort(specPackageSlice(spec.Wheel)) 97 sort.Sort(specPackageSlice(spec.Wheel))
68
69 // No duplicate packages. Since we're sorted, we can just check for no
70 // immediate repetitions.
71 for i, pkg := range spec.Wheel {
72 if i > 0 && pkg.Name == spec.Wheel[i-1].Name {
73 return errors.Reason("duplicate spec entries for package %q", pkg.Name).Err()
74 }
75 }
76
77 return nil 98 return nil
78 } 99 }
79 100
80 // Hash hashes the contents of the supplied "spec" and "rt" and returns the 101 // Hash hashes the contents of the supplied "spec" and "rt" and returns the
81 // result as a hex-encoded string. 102 // result as a hex-encoded string.
82 // 103 //
83 // If not empty, the contents of extra are prefixed to hash string. This can 104 // If not empty, the contents of extra are prefixed to hash string. This can
84 // be used to factor additional influences into the spec hash. 105 // be used to factor additional influences into the spec hash.
85 func Hash(spec *vpython.Spec, rt *vpython.Runtime, extra string) string { 106 func Hash(spec *vpython.Spec, rt *vpython.Runtime, extra string) string {
86 mustMarshal := func(msg proto.Message) []byte { 107 mustMarshal := func(msg proto.Message) []byte {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 func (s pep425TagSlice) Len() int { return len(s) } 148 func (s pep425TagSlice) Len() int { return len(s) }
128 func (s pep425TagSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 149 func (s pep425TagSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
129 150
130 func (s pep425TagSlice) Less(i, j int) bool { 151 func (s pep425TagSlice) Less(i, j int) bool {
131 return sortby.Chain{ 152 return sortby.Chain{
132 func(i, j int) bool { return s[i].Python < s[j].Python }, 153 func(i, j int) bool { return s[i].Python < s[j].Python },
133 func(i, j int) bool { return s[i].Abi < s[j].Abi }, 154 func(i, j int) bool { return s[i].Abi < s[j].Abi },
134 func(i, j int) bool { return s[i].Platform < s[j].Platform }, 155 func(i, j int) bool { return s[i].Platform < s[j].Platform },
135 }.Use(i, j) 156 }.Use(i, j)
136 } 157 }
OLDNEW
« no previous file with comments | « vpython/options.go ('k') | vpython/spec/spec_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698