-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathversion.go
More file actions
136 lines (110 loc) · 3.64 KB
/
version.go
File metadata and controls
136 lines (110 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package bond
import (
"fmt"
"strings"
"sync"
"github.com/pkg/errors"
)
// ArtifactVersion represents a document in the Version field of the
// MongoDB build information feed. See
// http://downloads.mongodb.org/full.json for an example download
type ArtifactVersion struct {
Version string
Downloads []ArtifactDownload
GitHash string
ProductionRelease bool `json:"production_release"`
DevelopmentRelease bool `json:"development_release"`
LTSRelease bool `json:"lts_release"`
ContinuousRelease bool `json:"continuous_release"`
Current bool `json:"current"`
table map[BuildOptions]ArtifactDownload
mutex sync.RWMutex
}
func (version *ArtifactVersion) refresh() {
version.mutex.Lock()
defer version.mutex.Unlock()
version.table = make(map[BuildOptions]ArtifactDownload)
for _, dl := range version.Downloads {
version.table[dl.GetBuildOptions()] = dl
}
}
func (version *ArtifactVersion) isDevelopmentSeries() (bool, error) {
parsedVersion, err := CreateMongoDBVersion(version.Version)
if err != nil {
return false, errors.Wrap(err, "parsing version")
}
return parsedVersion.IsDevelopmentSeries(), nil
}
// GetDownload returns a matching ArtifactDownload object
// given a BuildOptions object.
func (version *ArtifactVersion) GetDownload(key BuildOptions) (ArtifactDownload, error) {
version.mutex.RLock()
defer version.mutex.RLock()
// TODO: this is the place to fix handling for the Base edition, which is not necessarily intuitive.
if key.Edition == Base {
if key.Target == "linux" {
key.Target += "_" + string(key.Arch)
}
}
// For OSX, the target depends on the version. Before 4.1, OSX targets are
// "osx". However, starting in 4.1.1, OSX targets are "macos".
if key.Target == "osx" {
parsedVersion, err := CreateMongoDBVersion(version.Version)
if err != nil {
return ArtifactDownload{}, errors.Wrap(err, "parsing version")
}
macosVersion, err := CreateMongoDBVersion("4.1.1")
if err != nil {
return ArtifactDownload{}, errors.Wrap(err, "parsing comparison version")
}
if parsedVersion.IsGreaterThanOrEqualTo(macosVersion) {
key.Target = "macos"
}
}
// we look for debug builds later in the process, but as map
// keys, debug is always false.
key.Debug = false
dl, ok := version.table[key]
if !ok {
return ArtifactDownload{}, errors.Errorf("there is no build for '%s' ('%s') in edition '%s'", key.Target, key.Arch, key.Edition)
}
return dl, nil
}
// GetBuildTypes builds, from an ArtifactsVersion object a BuildTypes
// object that reports on the available builds for this version.
func (version *ArtifactVersion) GetBuildTypes() *BuildTypes {
out := BuildTypes{}
seenTargets := make(map[string]struct{})
seenEditions := make(map[MongoDBEdition]struct{})
seenArchitectures := make(map[MongoDBArch]struct{})
for _, dl := range version.Downloads {
out.Version = version.Version
if dl.Edition == "source" {
continue
}
if _, ok := seenTargets[dl.Target]; !ok {
seenTargets[dl.Target] = struct{}{}
out.Targets = append(out.Targets, dl.Target)
}
if _, ok := seenEditions[dl.Edition]; !ok {
seenEditions[dl.Edition] = struct{}{}
out.Editions = append(out.Editions, dl.Edition)
}
if _, ok := seenArchitectures[dl.Arch]; !ok {
seenArchitectures[dl.Arch] = struct{}{}
out.Architectures = append(out.Architectures, dl.Arch)
}
}
return &out
}
func (version *ArtifactVersion) String() string {
out := []string{version.Version}
for _, dl := range version.Downloads {
if dl.Edition == "source" {
continue
}
out = append(out, fmt.Sprintf("\t target='%s', edition='%v', arch='%v'",
dl.Target, dl.Edition, dl.Arch))
}
return strings.Join(out, "\n")
}