/
osx.go
100 lines (75 loc) · 1.86 KB
/
osx.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
package compile
import (
"os"
"os/exec"
"strings"
"github.com/go-errors/errors"
"github.com/mgutz/ansi"
"github.com/markelog/eclectica/cmd/print"
)
var (
// OSXDependencies is a list of OSX system dependencies
OSXDependencies = []string{
"openssl", "libyaml", "automake",
}
// XCodeDependencies is a list of XCode dependencies
XCodeDependencies = []string{
"xcrun", "make", "gcc",
}
)
func checkXCodeDependencies() bool {
for _, dep := range XCodeDependencies {
_, err := exec.Command(dep, "--version").CombinedOutput()
if err != nil {
return false
}
}
return true
}
func checkOSXDependencies() (has bool, deps []string, err error) {
out, err := exec.Command("brew", "list").Output()
if err != nil {
err = errors.New(err)
return
}
output := string(out)
for _, dep := range OSXDependencies {
if strings.Contains(output, dep) == false {
deps = append(deps, dep)
}
}
if len(deps) > 0 {
has = true
}
return
}
func printErrForOSXDependencies(deps []string) {
message := `Ruby cannot be installed without external dependencies,
please execute following command before trying it again (you need to do it only ` + ansi.Color("once", "red") + "):"
command := "brew update && brew install " + strings.Join(deps, " ")
print.Warning(message, command)
os.Exit(1)
}
func printErrForXCodeDependencies() {
message := `Ruby cannot be installed without Xcode,
please download it from https://developer.apple.com/download/
before trying it again (you need to do it only ` + ansi.Color("once", "red") + "):"
print.Warning(message, "")
os.Exit(1)
}
func dealWithOSXShell() error {
has := checkXCodeDependencies()
if has == false {
printErrForXCodeDependencies()
return nil
}
has, deps, err := checkOSXDependencies()
if err != nil {
return err
}
if has == false {
return nil
}
printErrForOSXDependencies(deps)
return nil
}