-
Notifications
You must be signed in to change notification settings - Fork 148
/
build.go
108 lines (93 loc) · 2.17 KB
/
build.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
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
package binaries
import (
"encoding/json"
"fmt"
"os"
"sync"
"github.com/onsi/gomega/gexec"
)
type BuildPaths struct {
Router string `json:"router"`
TrafficController string `json:"traffic_controller"`
RLP string `json:"rlp"`
RLPGateway string `json:"rlp_gateway"`
}
func (bp BuildPaths) Marshal() ([]byte, error) {
return json.Marshal(bp)
}
func (bp *BuildPaths) Unmarshal(text []byte) error {
return json.Unmarshal(text, bp)
}
func (bp BuildPaths) SetEnv() {
os.Setenv("ROUTER_BUILD_PATH", bp.Router)
os.Setenv("TRAFFIC_CONTROLLER_BUILD_PATH", bp.TrafficController)
os.Setenv("RLP_BUILD_PATH", bp.RLP)
os.Setenv("RLP_GATEWAY_BUILD_PATH", bp.RLPGateway)
}
func Build() (BuildPaths, chan error) {
var bp BuildPaths
errors := make(chan error, 100)
defer close(errors)
if os.Getenv("SKIP_BUILD") != "" {
fmt.Println("Skipping building of binaries")
bp.Router = os.Getenv("ROUTER_BUILD_PATH")
bp.TrafficController = os.Getenv("TRAFFIC_CONTROLLER_BUILD_PATH")
bp.RLP = os.Getenv("RLP_BUILD_PATH")
bp.RLPGateway = os.Getenv("RLP_GATEWAY_BUILD_PATH")
return bp, errors
}
var (
mu sync.Mutex
wg sync.WaitGroup
)
wg.Add(4)
go func() {
defer wg.Done()
path, err := gexec.Build("code.cloudfoundry.org/loggregator-release/src/router", "-race")
if err != nil {
errors <- err
return
}
mu.Lock()
defer mu.Unlock()
bp.Router = path
}()
go func() {
defer wg.Done()
path, err := gexec.Build("code.cloudfoundry.org/loggregator-release/src/trafficcontroller", "-race")
if err != nil {
errors <- err
return
}
mu.Lock()
defer mu.Unlock()
bp.TrafficController = path
}()
go func() {
defer wg.Done()
path, err := gexec.Build("code.cloudfoundry.org/loggregator-release/src/rlp", "-race")
if err != nil {
errors <- err
return
}
mu.Lock()
defer mu.Unlock()
bp.RLP = path
}()
go func() {
defer wg.Done()
path, err := gexec.Build("code.cloudfoundry.org/loggregator-release/src/rlp-gateway", "-race")
if err != nil {
errors <- err
return
}
mu.Lock()
defer mu.Unlock()
bp.RLPGateway = path
}()
wg.Wait()
return bp, errors
}
func Cleanup() {
gexec.CleanupBuildArtifacts()
}