This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dist.go
71 lines (49 loc) · 1.35 KB
/
dist.go
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
package packager
import (
"encoding/json"
)
type distribution struct {
GOOS string `json:"GOOS"`
GOARCH string `json:"GOARCH"`
}
func (d distribution) ShouldBuild() bool {
if d.GOOS != "linux" && d.GOOS != "darwin" && d.GOOS != "windows" {
return false
}
if d.GOARCH != "386" && d.GOARCH != "amd64" {
return false
}
return true
}
func (d distribution) String() string {
return d.GOOS + "/" + d.GOARCH
}
func (d distribution) DirName() string {
return d.GOOS + "_" + d.GOARCH
}
func (packager Packager) allDistributionsToBuild() ([]distribution, error) {
buildDistributions := []distribution{}
allDistributions, err := packager.allPossibleDistributions()
if err != nil {
return buildDistributions, err
}
for _, distribution := range allDistributions {
if !distribution.ShouldBuild() {
continue
}
buildDistributions = append(buildDistributions, distribution)
}
return buildDistributions, nil
}
func (packager Packager) allPossibleDistributions() ([]distribution, error) {
allDistributions := []distribution{}
cmd := []string{"go", "tool", "dist", "list", "--json"}
output, err := packager.RunReturnOutput(cmd, "", map[string]string{})
if err != nil {
return allDistributions, err
}
if err := json.Unmarshal([]byte(output), &allDistributions); err != nil {
return allDistributions, err
}
return allDistributions, nil
}