Skip to content

Commit bb14a23

Browse files
committed
Merge branch 'refactorings_part_1'
Signed-off-by: Cristian Maglie <[email protected]>
2 parents 1372f3c + c205ecd commit bb14a23

37 files changed

+439
-402
lines changed

src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,22 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/props"
3435
"arduino.cc/builder/types"
35-
"arduino.cc/builder/utils"
3636
)
3737

3838
type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{}
3939

4040
func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}) error {
4141
packages := context[constants.CTX_HARDWARE].(*types.Packages)
4242
targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package)
43-
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
43+
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
4444

45-
buildProperties = utils.MergeMapsOfStrings(make(map[string]string), packages.Properties, targetPackage.Properties, buildProperties)
45+
newBuildProperties := packages.Properties.Clone()
46+
newBuildProperties.Merge(targetPackage.Properties)
47+
newBuildProperties.Merge(buildProperties)
4648

47-
context[constants.CTX_BUILD_PROPERTIES] = buildProperties
49+
context[constants.CTX_BUILD_PROPERTIES] = newBuildProperties
4850

4951
return nil
5052
}

src/arduino.cc/builder/builder_utils/utils.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"strings"
4343
)
4444

45-
func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties map[string]string, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
45+
func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
4646
objectFiles, err := CompileFiles(objectFiles, sourcePath, false, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
4747
if err != nil {
4848
return nil, utils.WrapError(err)
@@ -63,7 +63,7 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
6363
return objectFiles, nil
6464
}
6565

66-
func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties map[string]string, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
66+
func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
6767
objectFiles, err := compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN, verbose, warningsLevel, logger)
6868
if err != nil {
6969
return nil, utils.WrapError(err)
@@ -79,7 +79,7 @@ func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPa
7979
return objectFiles, nil
8080
}
8181

82-
func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties map[string]string, includes []string, extension string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
82+
func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties props.PropertiesMap, includes []string, extension string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
8383
sources, err := findFilesInFolder(sourcePath, extension, recurse)
8484
if err != nil {
8585
return nil, utils.WrapError(err)
@@ -115,7 +115,7 @@ func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]str
115115
return sources, nil
116116
}
117117

118-
func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
118+
func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties props.PropertiesMap, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
119119
for _, source := range sources {
120120
objectFile, err := compileFileWithRecipe(sourcePath, source, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger)
121121
if err != nil {
@@ -127,8 +127,8 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s
127127
return objectFiles, nil
128128
}
129129

130-
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
131-
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
130+
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties props.PropertiesMap, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
131+
properties := buildProperties.Clone()
132132
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
133133
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
134134
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source
@@ -255,7 +255,7 @@ func nonEmptyString(s string) bool {
255255
return s != constants.EMPTY_STRING
256256
}
257257

258-
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties map[string]string, verbose bool, logger i18n.Logger) (string, error) {
258+
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties props.PropertiesMap, verbose bool, logger i18n.Logger) (string, error) {
259259
archiveFilePath := filepath.Join(buildPath, archiveFile)
260260
if _, err := os.Stat(archiveFilePath); err == nil {
261261
err = os.Remove(archiveFilePath)
@@ -265,7 +265,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
265265
}
266266

267267
for _, objectFile := range objectFiles {
268-
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
268+
properties := buildProperties.Clone()
269269
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(archiveFilePath)
270270
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath
271271
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile
@@ -279,7 +279,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
279279
return archiveFilePath, nil
280280
}
281281

282-
func ExecRecipe(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) {
282+
func ExecRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) {
283283
command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
284284
if err != nil {
285285
return nil, utils.WrapError(err)
@@ -300,14 +300,14 @@ func ExecRecipe(properties map[string]string, recipe string, removeUnsetProperti
300300
return bytes, utils.WrapError(err)
301301
}
302302

303-
func PrepareCommandForRecipe(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
303+
func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
304304
pattern := properties[recipe]
305305
if pattern == constants.EMPTY_STRING {
306306
return nil, utils.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe)
307307
}
308308

309309
var err error
310-
commandLine := props.ExpandPropsInString(properties, pattern)
310+
commandLine := properties.ExpandPropsInString(pattern)
311311
if removeUnsetProperties {
312312
commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine)
313313
if err != nil {
@@ -327,7 +327,7 @@ func PrepareCommandForRecipe(properties map[string]string, recipe string, remove
327327
return command, nil
328328
}
329329

330-
func ExecRecipeCollectStdErr(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) {
330+
func ExecRecipeCollectStdErr(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) {
331331
command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
332332
if err != nil {
333333
return "", utils.WrapError(err)
@@ -339,6 +339,6 @@ func ExecRecipeCollectStdErr(properties map[string]string, recipe string, remove
339339
return string(buffer.Bytes()), nil
340340
}
341341

342-
func RemoveHyphenMDDFlagFromGCCCommandLine(properties map[string]string) {
342+
func RemoveHyphenMDDFlagFromGCCCommandLine(properties props.PropertiesMap) {
343343
properties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS] = strings.Replace(properties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS], "-MMD", "", -1)
344344
}

src/arduino.cc/builder/coan_runner.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ func (s *CoanRunner) Run(context map[string]interface{}) error {
6060
return utils.WrapError(err)
6161
}
6262

63-
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
64-
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties, props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.COAN))
63+
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
64+
properties := buildProperties.Clone()
65+
properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.COAN))
6566
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = coanTargetFileName
6667

6768
pattern := properties[constants.BUILD_PROPERTIES_PATTERN]
@@ -70,7 +71,7 @@ func (s *CoanRunner) Run(context map[string]interface{}) error {
7071
}
7172

7273
logger := context[constants.CTX_LOGGER].(i18n.Logger)
73-
commandLine := props.ExpandPropsInString(properties, pattern)
74+
commandLine := properties.ExpandPropsInString(pattern)
7475
command, err := utils.PrepareCommandFilteredArgs(commandLine, filterAllowedArg, logger)
7576

7677
if verbose {

src/arduino.cc/builder/collect_ctags_from_sketch_files.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}) error
4242
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
4343
sketchFileNames := collectSketchFileNamesFrom(sketch)
4444

45-
ctags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
45+
allCtags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
4646
ctagsOfSketch := []*types.CTag{}
47-
for _, ctag := range ctags {
47+
for _, ctag := range allCtags {
4848
if utils.SliceContains(sketchFileNames, strings.Replace(ctag.Filename, "\\\\", "\\", -1)) {
4949
ctagsOfSketch = append(ctagsOfSketch, ctag)
5050
}

src/arduino.cc/builder/container_add_prototypes.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/ctags"
3435
"arduino.cc/builder/types"
3536
"arduino.cc/builder/utils"
3637
)
@@ -42,10 +43,10 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}) error {
4243
&GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
4344
&ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE},
4445
&CTagsTargetFileSaver{SourceField: constants.CTX_GCC_MINUS_E_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
45-
&CTagsRunner{},
46-
&CTagsParser{},
46+
&ctags.CTagsRunner{},
47+
&ctags.CTagsParser{},
4748
&CollectCTagsFromSketchFiles{},
48-
&CTagsToPrototypes{},
49+
&ctags.CTagsToPrototypes{},
4950
&PrototypesAdder{},
5051
&SketchSaver{},
5152
}

src/arduino.cc/builder/container_find_includes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
5555
foldersWithSources.Push(types.SourceFolder{Folder: context[constants.CTX_SKETCH_BUILD_PATH].(string), Recurse: true})
5656
if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
5757
for _, library := range context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) {
58-
sourceFolders := utils.LibraryToSourceFolder(library)
58+
sourceFolders := types.LibraryToSourceFolder(library)
5959
for _, sourceFolder := range sourceFolders {
6060
foldersWithSources.Push(sourceFolder)
6161
}

src/arduino.cc/builder/ctags_parser.go renamed to src/arduino.cc/builder/ctags/ctags_parser.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
2828
*/
2929

30-
package builder
30+
package ctags
3131

3232
import (
3333
"arduino.cc/builder/constants"
@@ -67,7 +67,6 @@ func (s *CTagsParser) Run(context map[string]interface{}) error {
6767

6868
skipTagsWhere(tags, tagIsUnknown, context)
6969
skipTagsWhere(tags, tagIsUnhandled, context)
70-
skipTagsWhere(tags, signatureContainsDefaultArg, context)
7170
addPrototypes(tags)
7271
removeDefinedProtypes(tags, context)
7372
removeDuplicate(tags)
@@ -87,7 +86,7 @@ func addPrototypes(tags []*types.CTag) {
8786
}
8887

8988
func addPrototype(tag *types.CTag) {
90-
if strings.Index(tag.Returntype, TEMPLATE) == 0 || strings.Index(tag.Code, TEMPLATE) == 0 {
89+
if strings.Index(tag.Prototype, TEMPLATE) == 0 || strings.Index(tag.Code, TEMPLATE) == 0 {
9190
code := tag.Code
9291
if strings.Contains(code, "{") {
9392
code = code[:strings.Index(code, "{")]
@@ -98,8 +97,6 @@ func addPrototype(tag *types.CTag) {
9897
return
9998
}
10099

101-
tag.Prototype = tag.Returntype + " " + tag.FunctionName + tag.Signature + ";"
102-
103100
tag.PrototypeModifiers = ""
104101
if strings.Index(tag.Code, STATIC+" ") != -1 {
105102
tag.PrototypeModifiers = tag.PrototypeModifiers + " " + STATIC
@@ -151,10 +148,6 @@ func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string
151148
}
152149
}
153150

154-
func signatureContainsDefaultArg(tag *types.CTag) bool {
155-
return strings.Contains(tag.Signature, "=")
156-
}
157-
158151
func prototypeAndCodeDontMatch(tag *types.CTag) bool {
159152
if tag.SkipMe {
160153
return true
@@ -207,6 +200,8 @@ func parseTag(row string) *types.CTag {
207200

208201
parts = parts[2:]
209202

203+
signature := ""
204+
returntype := ""
210205
for _, part := range parts {
211206
if strings.Contains(part, ":") {
212207
colon := strings.Index(part, ":")
@@ -222,9 +217,9 @@ func parseTag(row string) *types.CTag {
222217
case "typeref":
223218
tag.Typeref = value
224219
case "signature":
225-
tag.Signature = value
220+
signature = value
226221
case "returntype":
227-
tag.Returntype = value
222+
returntype = value
228223
case "class":
229224
tag.Class = value
230225
case "struct":
@@ -234,6 +229,7 @@ func parseTag(row string) *types.CTag {
234229
}
235230
}
236231
}
232+
tag.Prototype = returntype + " " + tag.FunctionName + signature + ";"
237233

238234
if strings.Contains(row, "/^") && strings.Contains(row, "$/;") {
239235
tag.Code = row[strings.Index(row, "/^")+2 : strings.Index(row, "$/;")]

src/arduino.cc/builder/ctags_runner.go renamed to src/arduino.cc/builder/ctags/ctags_runner.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
2828
*/
2929

30-
package builder
30+
package ctags
3131

3232
import (
3333
"arduino.cc/builder/constants"
@@ -40,19 +40,20 @@ import (
4040
type CTagsRunner struct{}
4141

4242
func (s *CTagsRunner) Run(context map[string]interface{}) error {
43-
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
43+
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
4444
ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string)
4545
logger := context[constants.CTX_LOGGER].(i18n.Logger)
4646

47-
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties, props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.CTAGS))
47+
properties := buildProperties.Clone()
48+
properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS))
4849
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = ctagsTargetFilePath
4950

5051
pattern := properties[constants.BUILD_PROPERTIES_PATTERN]
5152
if pattern == constants.EMPTY_STRING {
5253
return utils.Errorf(context, constants.MSG_PATTERN_MISSING, constants.CTAGS)
5354
}
5455

55-
commandLine := props.ExpandPropsInString(properties, pattern)
56+
commandLine := properties.ExpandPropsInString(pattern)
5657
command, err := utils.PrepareCommand(commandLine, logger)
5758
if err != nil {
5859
return utils.WrapError(err)

src/arduino.cc/builder/ctags_to_prototypes.go renamed to src/arduino.cc/builder/ctags/ctags_to_prototypes.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
2828
*/
2929

30-
package builder
30+
package ctags
3131

3232
import (
3333
"arduino.cc/builder/constants"
@@ -108,6 +108,9 @@ func firstFunctionAtLine(tags []*types.CTag) int {
108108
func toPrototypes(tags []*types.CTag) []*types.Prototype {
109109
prototypes := []*types.Prototype{}
110110
for _, tag := range tags {
111+
if strings.TrimSpace(tag.Prototype) == "" {
112+
continue
113+
}
111114
if !tag.SkipMe {
112115
prototype := &types.Prototype{
113116
FunctionName: tag.FunctionName,

src/arduino.cc/builder/dump_build_properties.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/props"
3435
"arduino.cc/builder/utils"
3536
"fmt"
3637
"sort"
@@ -39,7 +40,7 @@ import (
3940
type DumpBuildProperties struct{}
4041

4142
func (s *DumpBuildProperties) Run(context map[string]interface{}) error {
42-
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
43+
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
4344

4445
keys := utils.KeysOfMapOfString(buildProperties)
4546
sort.Strings(keys)

src/arduino.cc/builder/gcc_preproc_runner.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"arduino.cc/builder/builder_utils"
3434
"arduino.cc/builder/constants"
3535
"arduino.cc/builder/i18n"
36+
"arduino.cc/builder/props"
3637
"arduino.cc/builder/types"
3738
"arduino.cc/builder/utils"
3839
"path/filepath"
@@ -86,7 +87,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac
8687
return nil
8788
}
8889

89-
func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (map[string]string, string, error) {
90+
func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) {
9091
if targetFilePath != utils.NULLFile() {
9192
preprocPath := context[constants.CTX_PREPROC_PATH].(string)
9293
err := utils.EnsureFolderExists(preprocPath)
@@ -96,8 +97,10 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFil
9697
targetFilePath = filepath.Join(preprocPath, targetFilePath)
9798
}
9899

99-
buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
100-
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
100+
properties := make(props.PropertiesMap)
101+
if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok {
102+
properties = p.(props.PropertiesMap).Clone()
103+
}
101104

102105
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = sourceFilePath
103106
properties[constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH] = targetFilePath

0 commit comments

Comments
 (0)