-
Notifications
You must be signed in to change notification settings - Fork 69
/
buildsettings.go
145 lines (139 loc) · 3.94 KB
/
buildsettings.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
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
137
138
139
140
141
142
143
144
145
package config
import (
"log"
"github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/laher/goxc/typeutils"
)
type BuildSettings struct {
//GoRoot string `json:"-"` //Made *not* settable in settings file. Only at runtime.
//GoVersion string `json:",omitempty"` //hmm. Should I encourage this?
Processors *int `json:",omitempty"`
Race *bool `json:",omitempty"`
Verbose *bool `json:",omitempty"`
PrintCommands *bool `json:",omitempty"`
CcFlags *string `json:",omitempty"`
Compiler *string `json:",omitempty"`
GccGoFlags *string `json:",omitempty"`
GcFlags *string `json:",omitempty"`
InstallSuffix *string `json:",omitempty"`
LdFlags *string `json:",omitempty"`
LdFlagsXVars *map[string]interface{} `json:",omitempty"`
Tags *string `json:",omitempty"`
ExtraArgs []string `json:",omitempty"`
}
func (this BuildSettings) Equals(that BuildSettings) bool {
return this.Processors == that.Processors &&
this.Race == that.Race &&
this.Verbose == that.Verbose &&
this.PrintCommands == that.PrintCommands &&
this.CcFlags == that.CcFlags &&
this.Compiler == that.Compiler &&
this.GccGoFlags == that.GccGoFlags &&
this.GcFlags == that.GcFlags &&
this.InstallSuffix == that.InstallSuffix &&
this.LdFlags == that.LdFlags &&
this.Tags == that.Tags &&
typeutils.StringSliceEquals(this.ExtraArgs, that.ExtraArgs) &&
((this.LdFlagsXVars == nil && that.LdFlagsXVars == nil) ||
(this.LdFlagsXVars != nil && that.LdFlagsXVars != nil && typeutils.AreMapsEqual(*this.LdFlagsXVars, *that.LdFlagsXVars)))
}
func (this BuildSettings) IsEmpty() bool {
bs := BuildSettings{}
if bs.Equals(this) {
return true
}
//defaults can also be considered 'empty'
FillBuildSettingsDefaults(&bs)
return bs.Equals(this)
}
func buildSettingsFromMap(m map[string]interface{}) (*BuildSettings, error) {
var err error
bs := BuildSettings{}
FillBuildSettingsDefaults(&bs)
for k, v := range m {
switch k {
//case "GoRoot":
// bs.GoRoot, err = typeutils.ToString(v, k)
case "Processors":
var fp float64
fp, err = typeutils.ToFloat64(v, k)
if err == nil {
processors := int(fp)
bs.Processors = &processors
}
case "Race":
var race bool
race, err = typeutils.ToBool(v, k)
if err == nil {
bs.Race = &race
}
case "Verbose":
var verbose bool
verbose, err = typeutils.ToBool(v, k)
if err == nil {
bs.Verbose = &verbose
}
case "PrintCommands":
var printCommands bool
printCommands, err = typeutils.ToBool(v, k)
if err == nil {
bs.PrintCommands = &printCommands
}
case "CcFlags":
var ccFlags string
ccFlags, err = typeutils.ToString(v, k)
if err == nil {
bs.CcFlags = &ccFlags
}
case "Compiler":
var s string
s, err = typeutils.ToString(v, k)
if err == nil {
bs.Compiler = &s
}
case "GccGoFlags":
var s string
s, err = typeutils.ToString(v, k)
if err == nil {
bs.GccGoFlags = &s
}
case "GcFlags":
var s string
s, err = typeutils.ToString(v, k)
if err == nil {
bs.GcFlags = &s
}
case "InstallSuffix":
var s string
s, err = typeutils.ToString(v, k)
if err == nil {
bs.InstallSuffix = &s
}
case "LdFlags":
var s string
s, err = typeutils.ToString(v, k)
if err == nil {
bs.LdFlags = &s
}
case "Tags":
var s string
s, err = typeutils.ToString(v, k)
if err == nil {
bs.Tags = &s
}
case "LdFlagsXVars":
var xVars map[string]interface{}
xVars, err = typeutils.ToMap(v, k)
if err == nil {
bs.LdFlagsXVars = &xVars
}
case "ExtraArgs":
bs.ExtraArgs, err = typeutils.ToStringSlice(v, k)
default:
log.Printf("Warning!! Unrecognised Setting '%s' (value %v)", k, v)
}
if err != nil {
return &bs, err
}
}
return &bs, err
}