Skip to content

Commit 975a84a

Browse files
committed
Move const strings to constant package
1 parent 1b08e44 commit 975a84a

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

src/arduino.cc/builder/constants/constants.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ const MSG_PROP_IN_LIBRARY = "Missing '{0}' from library in {1}"
170170
const MSG_RUNNING_COMMAND = "Ts: {0} - Running: {1}"
171171
const MSG_RUNNING_RECIPE = "Running recipe: {0}"
172172
const MSG_SETTING_BUILD_PATH = "Setting build path to {0}"
173+
const MSG_SIZER_TEXT_FULL = "Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes."
174+
const MSG_SIZER_DATA_FULL = "Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes."
175+
const MSG_SIZER_DATA = "Global variables use {0} bytes of dynamic memory."
176+
const MSG_SIZER_TEXT_TOO_BIG = "Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."
177+
const MSG_SIZER_DATA_TOO_BIG = "Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint."
178+
const MSG_SIZER_LOW_MEMORY = "Low memory available, stability problems may occur."
179+
const MSG_SIZER_ERROR_NO_RULE = "Couldn't determine program size"
173180
const MSG_SKETCH_CANT_BE_IN_BUILDPATH = "Sketch cannot be located in build path. Please specify a different build path"
174181
const MSG_SKIPPING_TAG_ALREADY_DEFINED = "Skipping tag {0} because prototype is already defined"
175182
const MSG_SKIPPING_TAG_BECAUSE_HAS_FIELD = "Skipping tag {0} because it has field {0}"
@@ -197,6 +204,9 @@ const PLATFORM_REWRITE_NEW = "new"
197204
const PLATFORM_REWRITE_OLD = "old"
198205
const PLATFORM_URL = "url"
199206
const PLATFORM_VERSION = "version"
207+
const PROPERTY_WARN_DATA_PERCENT = "build.warn_data_percentage"
208+
const PROPERTY_UPLOAD_MAX_SIZE = "upload.maximum_size"
209+
const PROPERTY_UPLOAD_MAX_DATA_SIZE = "upload.maximum_data_size"
200210
const PROGRAMMER_NAME = "name"
201211
const RECIPE_AR_PATTERN = "recipe.ar.pattern"
202212
const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern"
@@ -206,6 +216,9 @@ const RECIPE_SIZE_PATTERN = "recipe.size.pattern"
206216
const RECIPE_PREPROC_INCLUDES = "recipe.preproc.includes"
207217
const RECIPE_PREPROC_MACROS = "recipe.preproc.macros"
208218
const RECIPE_S_PATTERN = "recipe.S.o.pattern"
219+
const RECIPE_SIZE_REGEXP = "recipe.size.regex"
220+
const RECIPE_SIZE_REGEXP_DATA = "recipe.size.regex.data"
221+
const RECIPE_SIZE_REGEXP_EEPROM = "recipe.size.regex.eeprom"
209222
const REWRITING_DISABLED = "disabled"
210223
const REWRITING = "rewriting"
211224
const SPACE = " "

src/arduino.cc/builder/phases/sizer.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)