@@ -33,7 +33,6 @@ import (
3333 "errors"
3434 "regexp"
3535 "strconv"
36- "time"
3736
3837 "arduino.cc/builder/builder_utils"
3938 "arduino.cc/builder/constants"
@@ -52,9 +51,6 @@ func (s *Sizer) Run(ctx *types.Context) error {
5251
5352 err := checkSize (buildProperties , verbose , warningsLevel , logger )
5453 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 )
5854 return i18n .WrapError (err )
5955 }
6056
@@ -66,15 +62,13 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
6662 properties := buildProperties .Clone ()
6763 properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + warningsLevel ]
6864
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 ]
7167
7268 if maxTextSizeString == "" {
7369 return nil
7470 }
7571
76- logLevel := constants .LOG_LEVEL_INFO
77-
7872 maxTextSize , _ := strconv .Atoi (maxTextSizeString )
7973 maxDataSize := - 1
8074
@@ -89,29 +83,29 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
8983 return err
9084 }
9185
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 ))
9387 if dataSize > 0 {
9488 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 ))
9690 } 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 ))
9892 }
9993 }
10094
10195 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 )
10397 return errors .New ("" )
10498 }
10599
106100 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 )
108102 return errors .New ("" )
109103 }
110104
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 ])
113107 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 )
115109 }
116110 }
117111
@@ -123,14 +117,14 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
123117 out , err := builder_utils .ExecRecipe (properties , constants .RECIPE_SIZE_PATTERN , false , false , false , logger )
124118
125119 if err != nil {
126- i18n .ErrorfWithLogger (logger , "Couldn't determine program size" )
120+ i18n .ErrorfWithLogger (logger , constants . MSG_SIZER_ERROR_NO_RULE )
127121 return errors .New ("" )
128122 }
129123
130124 // force multiline match prepending "(?m)" to the actual regexp
131125
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 ])
134128 result := textRegexp .FindAllSubmatch (out , - 1 )
135129 for _ , b := range result {
136130 for _ , c := range b {
@@ -140,8 +134,8 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
140134 }
141135 }
142136
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 ])
145139 result := dataRegexp .FindAllSubmatch (out , - 1 )
146140 for _ , b := range result {
147141 for _ , c := range b {
@@ -151,8 +145,8 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
151145 }
152146 }
153147
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 ])
156150 result := eepromRegexp .FindAllSubmatch (out , - 1 )
157151 for _ , b := range result {
158152 for _ , c := range b {
0 commit comments