Skip to content

Commit a6b718f

Browse files
committed
Remove some constants indirection
1 parent ec376de commit a6b718f

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

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

-7
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,12 @@ const PLATFORM_REWRITE_NEW = "new"
8989
const PLATFORM_REWRITE_OLD = "old"
9090
const PLATFORM_URL = "url"
9191
const PLATFORM_VERSION = "version"
92-
const PROPERTY_WARN_DATA_PERCENT = "build.warn_data_percentage"
93-
const PROPERTY_UPLOAD_MAX_SIZE = "upload.maximum_size"
94-
const PROPERTY_UPLOAD_MAX_DATA_SIZE = "upload.maximum_data_size"
9592
const RECIPE_AR_PATTERN = "recipe.ar.pattern"
9693
const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern"
9794
const RECIPE_C_PATTERN = "recipe.c.o.pattern"
9895
const RECIPE_CPP_PATTERN = "recipe.cpp.o.pattern"
99-
const RECIPE_SIZE_PATTERN = "recipe.size.pattern"
10096
const RECIPE_PREPROC_MACROS = "recipe.preproc.macros"
10197
const RECIPE_S_PATTERN = "recipe.S.o.pattern"
102-
const RECIPE_SIZE_REGEXP = "recipe.size.regex"
103-
const RECIPE_SIZE_REGEXP_DATA = "recipe.size.regex.data"
104-
const RECIPE_SIZE_REGEXP_EEPROM = "recipe.size.regex.eeprom"
10598
const REWRITING_DISABLED = "disabled"
10699
const REWRITING = "rewriting"
107100
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

+16-17
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"strconv"
2222

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

5655
properties := buildProperties.Clone()
57-
properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel))
56+
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+ctx.WarningsLevel))
5857

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

6261
if maxTextSizeString == "" {
6362
return nil
@@ -78,25 +77,25 @@ func checkSize(ctx *types.Context, buildProperties *properties.Map) error {
7877

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

85-
logger.Println(constants.LOG_LEVEL_INFO,
84+
logger.Println("info",
8685
tr("Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes."),
8786
strconv.Itoa(textSize),
8887
strconv.Itoa(maxTextSize),
8988
strconv.Itoa(textSize*100/maxTextSize))
9089
if dataSize >= 0 {
9190
if maxDataSize > 0 {
92-
logger.Println(constants.LOG_LEVEL_INFO,
91+
logger.Println("info",
9392
tr("Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes."),
9493
strconv.Itoa(dataSize),
9594
strconv.Itoa(maxDataSize),
9695
strconv.Itoa(dataSize*100/maxDataSize),
9796
strconv.Itoa(maxDataSize-dataSize))
9897
} else {
99-
logger.Println(constants.LOG_LEVEL_INFO,
98+
logger.Println("info",
10099
tr("Global variables use {0} bytes of dynamic memory."), strconv.Itoa(dataSize))
101100
}
102101
}
@@ -117,32 +116,32 @@ func checkSize(ctx *types.Context, buildProperties *properties.Map) error {
117116
}
118117

119118
if textSize > maxTextSize {
120-
logger.Println(constants.LOG_LEVEL_ERROR,
119+
logger.Println("error",
121120
tr("Sketch too big; see %s for tips on reducing it.", "https://support.arduino.cc/hc/en-us/articles/360013825179"))
122121
return errors.New(tr("text section exceeds available space in board"))
123122
}
124123

125124
if maxDataSize > 0 && dataSize > maxDataSize {
126-
logger.Println(constants.LOG_LEVEL_ERROR,
125+
logger.Println("error",
127126
tr("Not enough memory; see %s for tips on reducing your footprint.", "https://support.arduino.cc/hc/en-us/articles/360013825179"))
128127
return errors.New(tr("data section exceeds available space in board"))
129128
}
130129

131-
if properties.Get(constants.PROPERTY_WARN_DATA_PERCENT) != "" {
132-
warnDataPercentage, err := strconv.Atoi(properties.Get(constants.PROPERTY_WARN_DATA_PERCENT))
130+
if w := properties.Get("build.warn_data_percentage"); w != "" {
131+
warnDataPercentage, err := strconv.Atoi(w)
133132
if err != nil {
134133
return err
135134
}
136135
if maxDataSize > 0 && dataSize > maxDataSize*warnDataPercentage/100 {
137-
logger.Println(constants.LOG_LEVEL_WARN, tr("Low memory available, stability problems may occur."))
136+
logger.Println("warn", tr("Low memory available, stability problems may occur."))
138137
}
139138
}
140139

141140
return nil
142141
}
143142

144143
func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize int, dataSize int, eepromSize int, resErr error) {
145-
command, err := builder_utils.PrepareCommandForRecipe(properties, constants.RECIPE_SIZE_PATTERN, false)
144+
command, err := builder_utils.PrepareCommandForRecipe(properties, "recipe.size.pattern", false)
146145
if err != nil {
147146
resErr = fmt.Errorf(tr("Error while determining sketch size: %s"), err)
148147
return
@@ -157,7 +156,7 @@ func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize in
157156
// force multiline match prepending "(?m)" to the actual regexp
158157
// return an error if RECIPE_SIZE_REGEXP doesn't exist
159158

160-
textSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP), out)
159+
textSize, err = computeSize(properties.Get("recipe.size.regex"), out)
161160
if err != nil {
162161
resErr = fmt.Errorf(tr("Invalid size regexp: %s"), err)
163162
return
@@ -167,13 +166,13 @@ func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize in
167166
return
168167
}
169168

170-
dataSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP_DATA), out)
169+
dataSize, err = computeSize(properties.Get("recipe.size.regex.data"), out)
171170
if err != nil {
172171
resErr = fmt.Errorf(tr("Invalid data size regexp: %s"), err)
173172
return
174173
}
175174

176-
eepromSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP_EEPROM), out)
175+
eepromSize, err = computeSize(properties.Get("recipe.size.regex.eeprom"), out)
177176
if err != nil {
178177
resErr = fmt.Errorf(tr("Invalid eeprom size regexp: %s"), err)
179178
return

0 commit comments

Comments
 (0)