Skip to content

Commit e39c110

Browse files
committed
Remove some constants indirection
1 parent 0169954 commit e39c110

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

Diff for: legacy/builder/constants/constants.go

-14
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ const MSG_PROP_IN_LIBRARY = "Missing '{0}' from library in {1}"
107107
const MSG_RUNNING_COMMAND = "Ts: {0} - Running: {1}"
108108
const MSG_RUNNING_RECIPE = "Running recipe: {0}"
109109
const MSG_SETTING_BUILD_PATH = "Setting build path to {0}"
110-
const MSG_SIZER_TEXT_FULL = "Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes."
111-
const MSG_SIZER_DATA_FULL = "Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes."
112-
const MSG_SIZER_DATA = "Global variables use {0} bytes of dynamic memory."
113-
const MSG_SIZER_TEXT_TOO_BIG = "Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it."
114-
const MSG_SIZER_DATA_TOO_BIG = "Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint."
115-
const MSG_SIZER_LOW_MEMORY = "Low memory available, stability problems may occur."
116-
const MSG_SIZER_ERROR_NO_RULE = "Couldn't determine program size"
117110
const MSG_SKETCH_CANT_BE_IN_BUILDPATH = "Sketch cannot be located in build path. Please specify a different build path"
118111
const MSG_UNKNOWN_SKETCH_EXT = "Unknown sketch file extension: {0}"
119112
const MSG_USING_LIBRARY_AT_VERSION = "Using library {0} at version {1} in folder: {2} {3}"
@@ -133,19 +126,12 @@ const PLATFORM_REWRITE_NEW = "new"
133126
const PLATFORM_REWRITE_OLD = "old"
134127
const PLATFORM_URL = "url"
135128
const PLATFORM_VERSION = "version"
136-
const PROPERTY_WARN_DATA_PERCENT = "build.warn_data_percentage"
137-
const PROPERTY_UPLOAD_MAX_SIZE = "upload.maximum_size"
138-
const PROPERTY_UPLOAD_MAX_DATA_SIZE = "upload.maximum_data_size"
139129
const RECIPE_AR_PATTERN = "recipe.ar.pattern"
140130
const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern"
141131
const RECIPE_C_PATTERN = "recipe.c.o.pattern"
142132
const RECIPE_CPP_PATTERN = "recipe.cpp.o.pattern"
143-
const RECIPE_SIZE_PATTERN = "recipe.size.pattern"
144133
const RECIPE_PREPROC_MACROS = "recipe.preproc.macros"
145134
const RECIPE_S_PATTERN = "recipe.S.o.pattern"
146-
const RECIPE_SIZE_REGEXP = "recipe.size.regex"
147-
const RECIPE_SIZE_REGEXP_DATA = "recipe.size.regex.data"
148-
const RECIPE_SIZE_REGEXP_EEPROM = "recipe.size.regex.eeprom"
149135
const REWRITING_DISABLED = "disabled"
150136
const REWRITING = "rewriting"
151137
const SPACE = " "

Diff for: legacy/builder/merge_sketch_with_bootloader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error {
7474

7575
// Ignore merger errors for the first iteration
7676
maximumBinSize := 16000000
77-
if uploadMaxSize, ok := ctx.BuildProperties.GetOk(constants.PROPERTY_UPLOAD_MAX_SIZE); ok {
77+
if uploadMaxSize, ok := ctx.BuildProperties.GetOk("upload.maximum_size"); ok {
7878
maximumBinSize, _ = strconv.Atoi(uploadMaxSize)
7979
maximumBinSize *= 2
8080
}

Diff for: legacy/builder/phases/sizer.go

+22-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"strconv"
2121

2222
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
23-
"github.com/arduino/arduino-cli/legacy/builder/constants"
2423
"github.com/arduino/arduino-cli/legacy/builder/types"
2524
"github.com/arduino/arduino-cli/legacy/builder/utils"
2625
"github.com/arduino/go-properties-orderedmap"
@@ -53,10 +52,10 @@ func checkSize(ctx *types.Context, buildProperties *properties.Map) error {
5352
logger := ctx.GetLogger()
5453

5554
properties := buildProperties.Clone()
56-
properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel))
55+
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+ctx.WarningsLevel))
5756

58-
maxTextSizeString := properties.Get(constants.PROPERTY_UPLOAD_MAX_SIZE)
59-
maxDataSizeString := properties.Get(constants.PROPERTY_UPLOAD_MAX_DATA_SIZE)
57+
maxTextSizeString := properties.Get("upload.maximum_size")
58+
maxDataSizeString := properties.Get("upload.maximum_data_size")
6059

6160
if maxTextSizeString == "" {
6261
return nil
@@ -77,16 +76,22 @@ func checkSize(ctx *types.Context, buildProperties *properties.Map) error {
7776

7877
textSize, dataSize, _, err := execSizeRecipe(ctx, properties)
7978
if err != nil {
80-
logger.Println(constants.LOG_LEVEL_WARN, constants.MSG_SIZER_ERROR_NO_RULE)
79+
logger.Println("warn", "Couldn't determine program size")
8180
return nil
8281
}
8382

84-
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_SIZER_TEXT_FULL, strconv.Itoa(textSize), strconv.Itoa(maxTextSize), strconv.Itoa(textSize*100/maxTextSize))
83+
logger.Println("info",
84+
"Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes.",
85+
strconv.Itoa(textSize), strconv.Itoa(maxTextSize), strconv.Itoa(textSize*100/maxTextSize))
8586
if dataSize >= 0 {
8687
if maxDataSize > 0 {
87-
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))
88+
logger.Println("info",
89+
"Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes.",
90+
strconv.Itoa(dataSize), strconv.Itoa(maxDataSize), strconv.Itoa(dataSize*100/maxDataSize), strconv.Itoa(maxDataSize-dataSize))
8891
} else {
89-
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_SIZER_DATA, strconv.Itoa(dataSize))
92+
logger.Println("info",
93+
"Global variables use {0} bytes of dynamic memory.",
94+
strconv.Itoa(dataSize))
9095
}
9196
}
9297

@@ -106,30 +111,30 @@ func checkSize(ctx *types.Context, buildProperties *properties.Map) error {
106111
}
107112

108113
if textSize > maxTextSize {
109-
logger.Println(constants.LOG_LEVEL_ERROR, constants.MSG_SIZER_TEXT_TOO_BIG)
114+
logger.Println("error", "Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.")
110115
return errors.New("text section exceeds available space in board")
111116
}
112117

113118
if maxDataSize > 0 && dataSize > maxDataSize {
114-
logger.Println(constants.LOG_LEVEL_ERROR, constants.MSG_SIZER_DATA_TOO_BIG)
119+
logger.Println("error", "Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint.")
115120
return errors.New("data section exceeds available space in board")
116121
}
117122

118-
if properties.Get(constants.PROPERTY_WARN_DATA_PERCENT) != "" {
119-
warnDataPercentage, err := strconv.Atoi(properties.Get(constants.PROPERTY_WARN_DATA_PERCENT))
123+
if w := properties.Get("build.warn_data_percentage"); w != "" {
124+
warnDataPercentage, err := strconv.Atoi(w)
120125
if err != nil {
121126
return err
122127
}
123128
if maxDataSize > 0 && dataSize > maxDataSize*warnDataPercentage/100 {
124-
logger.Println(constants.LOG_LEVEL_WARN, constants.MSG_SIZER_LOW_MEMORY)
129+
logger.Println("warn", "Low memory available, stability problems may occur.")
125130
}
126131
}
127132

128133
return nil
129134
}
130135

131136
func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize int, dataSize int, eepromSize int, resErr error) {
132-
command, err := builder_utils.PrepareCommandForRecipe(properties, constants.RECIPE_SIZE_PATTERN, false)
137+
command, err := builder_utils.PrepareCommandForRecipe(properties, "recipe.size.pattern", false)
133138
if err != nil {
134139
resErr = errors.New("Error while determining sketch size: " + err.Error())
135140
return
@@ -144,7 +149,7 @@ func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize in
144149
// force multiline match prepending "(?m)" to the actual regexp
145150
// return an error if RECIPE_SIZE_REGEXP doesn't exist
146151

147-
textSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP), out)
152+
textSize, err = computeSize(properties.Get("recipe.size.regex"), out)
148153
if err != nil {
149154
resErr = errors.New("Invalid size regexp: " + err.Error())
150155
return
@@ -154,13 +159,13 @@ func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize in
154159
return
155160
}
156161

157-
dataSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP_DATA), out)
162+
dataSize, err = computeSize(properties.Get("recipe.size.regex.data"), out)
158163
if err != nil {
159164
resErr = errors.New("Invalid data size regexp: " + err.Error())
160165
return
161166
}
162167

163-
eepromSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP_EEPROM), out)
168+
eepromSize, err = computeSize(properties.Get("recipe.size.regex.eeprom"), out)
164169
if err != nil {
165170
resErr = errors.New("Invalid eeprom size regexp: " + err.Error())
166171
return

0 commit comments

Comments
 (0)