@@ -33,7 +33,6 @@ import (
33
33
"errors"
34
34
"regexp"
35
35
"strconv"
36
- "time"
37
36
38
37
"arduino.cc/builder/builder_utils"
39
38
"arduino.cc/builder/constants"
@@ -52,9 +51,6 @@ func (s *Sizer) Run(ctx *types.Context) error {
52
51
53
52
err := checkSize (buildProperties , verbose , warningsLevel , logger )
54
53
if err != nil {
55
- // HACK: we are bailing out badly and we just wrote on stdout,
56
- // wait 200 ms to let the IDE's MessageSiphon flush
57
- time .Sleep (200 * time .Millisecond )
58
54
return i18n .WrapError (err )
59
55
}
60
56
@@ -66,15 +62,13 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
66
62
properties := buildProperties .Clone ()
67
63
properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + warningsLevel ]
68
64
69
- maxTextSizeString := properties ["upload.maximum_size" ]
70
- maxDataSizeString := properties ["upload.maximum_data_size" ]
65
+ maxTextSizeString := properties [constants . PROPERTY_UPLOAD_MAX_SIZE ]
66
+ maxDataSizeString := properties [constants . PROPERTY_UPLOAD_MAX_DATA_SIZE ]
71
67
72
68
if maxTextSizeString == "" {
73
69
return nil
74
70
}
75
71
76
- logLevel := constants .LOG_LEVEL_INFO
77
-
78
72
maxTextSize , _ := strconv .Atoi (maxTextSizeString )
79
73
maxDataSize := - 1
80
74
@@ -89,29 +83,29 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
89
83
return err
90
84
}
91
85
92
- logger .Println (logLevel , "Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes." , strconv .Itoa (textSize ), strconv .Itoa (maxTextSize ), strconv .Itoa (textSize * 100 / maxTextSize ))
86
+ logger .Println (constants . LOG_LEVEL_INFO , constants . MSG_SIZER_TEXT_FULL , strconv .Itoa (textSize ), strconv .Itoa (maxTextSize ), strconv .Itoa (textSize * 100 / maxTextSize ))
93
87
if dataSize > 0 {
94
88
if maxDataSize > 0 {
95
- logger .Println (logLevel , "Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes." , strconv .Itoa (dataSize ), strconv .Itoa (maxDataSize ), strconv .Itoa (dataSize * 100 / maxDataSize ), strconv .Itoa (maxDataSize - dataSize ))
89
+ logger .Println (constants . LOG_LEVEL_INFO , constants . MSG_SIZER_DATA_FULL , strconv .Itoa (dataSize ), strconv .Itoa (maxDataSize ), strconv .Itoa (dataSize * 100 / maxDataSize ), strconv .Itoa (maxDataSize - dataSize ))
96
90
} else {
97
- logger .Println (logLevel , "Global variables use {0} bytes of dynamic memory." , strconv .Itoa (dataSize ))
91
+ logger .Println (constants . LOG_LEVEL_INFO , constants . MSG_SIZER_DATA , strconv .Itoa (dataSize ))
98
92
}
99
93
}
100
94
101
95
if textSize > maxTextSize {
102
- i18n . ErrorfWithLogger ( logger , "Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it." )
96
+ logger . Println ( constants . LOG_LEVEL_ERROR , constants . MSG_SIZER_TEXT_TOO_BIG )
103
97
return errors .New ("" )
104
98
}
105
99
106
100
if maxDataSize > 0 && dataSize > maxDataSize {
107
- i18n . ErrorfWithLogger ( logger , "Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint." )
101
+ logger . Println ( constants . LOG_LEVEL_ERROR , constants . MSG_SIZER_DATA_TOO_BIG )
108
102
return errors .New ("" )
109
103
}
110
104
111
- if properties ["build.warn_data_percentage" ] != "" {
112
- warnDataPercentage , _ := strconv .Atoi (properties ["build.warn_data_percentage" ])
105
+ if properties [constants . PROPERTY_WARN_DATA_PERCENT ] != "" {
106
+ warnDataPercentage , _ := strconv .Atoi (properties [constants . PROPERTY_WARN_DATA_PERCENT ])
113
107
if maxDataSize > 0 && dataSize > maxDataSize * warnDataPercentage / 100 {
114
- logger .Println (logLevel , "Low memory available, stability problems may occur." )
108
+ logger .Println (constants . LOG_LEVEL_WARN , constants . MSG_SIZER_LOW_MEMORY )
115
109
}
116
110
}
117
111
@@ -123,14 +117,14 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
123
117
out , err := builder_utils .ExecRecipe (properties , constants .RECIPE_SIZE_PATTERN , false , false , false , logger )
124
118
125
119
if err != nil {
126
- i18n .ErrorfWithLogger (logger , "Couldn't determine program size" )
120
+ i18n .ErrorfWithLogger (logger , constants . MSG_SIZER_ERROR_NO_RULE )
127
121
return errors .New ("" )
128
122
}
129
123
130
124
// force multiline match prepending "(?m)" to the actual regexp
131
125
132
- if len (properties ["recipe.size.regex" ]) > 0 {
133
- textRegexp := regexp .MustCompile ("(?m)" + properties ["recipe.size.regex" ])
126
+ if len (properties [constants . RECIPE_SIZE_REGEXP ]) > 0 {
127
+ textRegexp := regexp .MustCompile ("(?m)" + properties [constants . RECIPE_SIZE_REGEXP ])
134
128
result := textRegexp .FindAllSubmatch (out , - 1 )
135
129
for _ , b := range result {
136
130
for _ , c := range b {
@@ -140,8 +134,8 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
140
134
}
141
135
}
142
136
143
- if len (properties ["recipe.size.regex.data" ]) > 0 {
144
- dataRegexp := regexp .MustCompile ("(?m)" + properties ["recipe.size.regex.data" ])
137
+ if len (properties [constants . RECIPE_SIZE_REGEXP_DATA ]) > 0 {
138
+ dataRegexp := regexp .MustCompile ("(?m)" + properties [constants . RECIPE_SIZE_REGEXP_DATA ])
145
139
result := dataRegexp .FindAllSubmatch (out , - 1 )
146
140
for _ , b := range result {
147
141
for _ , c := range b {
@@ -151,8 +145,8 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
151
145
}
152
146
}
153
147
154
- if len (properties ["recipe.size.regex.eeprom" ]) > 0 {
155
- eepromRegexp := regexp .MustCompile ("(?m)" + properties ["recipe.size.regex.eeprom" ])
148
+ if len (properties [constants . RECIPE_SIZE_REGEXP_EEPROM ]) > 0 {
149
+ eepromRegexp := regexp .MustCompile ("(?m)" + properties [constants . RECIPE_SIZE_REGEXP_EEPROM ])
156
150
result := eepromRegexp .FindAllSubmatch (out , - 1 )
157
151
for _ , b := range result {
158
152
for _ , c := range b {
0 commit comments