Skip to content

Commit e74320a

Browse files
committed
Adopting ordered properties map
1 parent bb7d413 commit e74320a

35 files changed

+278
-281
lines changed

add_build_board_property_if_missing.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ func (*AddBuildBoardPropertyIfMissing) Run(ctx *types.Context) error {
4747
for _, platform := range aPackage.Platforms {
4848
for _, platformRelease := range platform.Releases {
4949
for _, board := range platformRelease.Boards {
50-
if board.Properties["build.board"] == "" {
51-
board.Properties["build.board"] = strings.ToUpper(platform.Architecture + "_" + board.BoardID)
50+
if board.Properties.Get("build.board") == "" {
51+
board.Properties.Set("build.board", strings.ToUpper(platform.Architecture+"_"+board.BoardID))
5252
logger.Fprintln(
5353
os.Stdout,
5454
constants.LOG_LEVEL_WARN,
5555
constants.MSG_MISSING_BUILD_BOARD,
5656
aPackage.Name,
5757
platform.Architecture,
5858
board.BoardID,
59-
board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD])
59+
board.Properties.Get(constants.BUILD_PROPERTIES_BUILD_BOARD))
6060
}
6161
}
6262
}

arduino-builder/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import (
5050
"github.com/arduino/arduino-builder/types"
5151
"github.com/arduino/arduino-cli/arduino/cores"
5252
"github.com/arduino/go-paths-helper"
53-
"github.com/arduino/go-properties-map"
53+
"github.com/arduino/go-properties-orderedmap"
5454
"github.com/go-errors/errors"
5555
)
5656

@@ -240,7 +240,7 @@ func main() {
240240
}
241241

242242
if *buildOptionsFileFlag != "" {
243-
buildOptions := make(properties.Map)
243+
buildOptions := properties.NewMap()
244244
if _, err := os.Stat(*buildOptionsFileFlag); err == nil {
245245
data, err := ioutil.ReadFile(*buildOptionsFileFlag)
246246
if err != nil {

builder_utils/utils.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"github.com/arduino/arduino-builder/types"
4343
"github.com/arduino/arduino-builder/utils"
4444
"github.com/arduino/go-paths-helper"
45-
"github.com/arduino/go-properties-map"
45+
"github.com/arduino/go-properties-orderedmap"
4646
)
4747

4848
func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
@@ -58,7 +58,7 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
5858
}
5959
}
6060

61-
func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties properties.Map, includes []string) (paths.PathList, error) {
61+
func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
6262
objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes)
6363
if err != nil {
6464
return nil, i18n.WrapError(err)
@@ -80,7 +80,7 @@ func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath
8080
return objectFiles, nil
8181
}
8282

83-
func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties properties.Map, includes []string) (paths.PathList, error) {
83+
func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
8484
sObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN)
8585
if err != nil {
8686
return nil, i18n.WrapError(err)
@@ -100,7 +100,7 @@ func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buil
100100
return objectFiles, nil
101101
}
102102

103-
func compileFilesWithExtensionWithRecipe(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties properties.Map, includes []string, extension string, recipe string) (paths.PathList, error) {
103+
func compileFilesWithExtensionWithRecipe(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string, extension string, recipe string) (paths.PathList, error) {
104104
sources, err := findFilesInFolder(sourcePath, extension, recurse)
105105
if err != nil {
106106
return nil, i18n.WrapError(err)
@@ -164,7 +164,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
164164
return sources, nil
165165
}
166166

167-
func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources paths.PathList, buildPath *paths.Path, buildProperties properties.Map, includes []string, recipe string) (paths.PathList, error) {
167+
func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources paths.PathList, buildPath *paths.Path, buildProperties *properties.Map, includes []string, recipe string) (paths.PathList, error) {
168168
objectFiles := paths.NewPathList()
169169
if len(sources) == 0 {
170170
return objectFiles, nil
@@ -212,19 +212,19 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
212212
}
213213
}
214214

215-
func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *paths.Path, buildPath *paths.Path, buildProperties properties.Map, includes []string, recipe string) (*paths.Path, error) {
215+
func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string, recipe string) (*paths.Path, error) {
216216
logger := ctx.GetLogger()
217217
properties := buildProperties.Clone()
218-
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel]
219-
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
220-
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source.String()
218+
properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel))
219+
properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includes, constants.SPACE))
220+
properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source)
221221
relativeSource, err := sourcePath.RelTo(source)
222222
if err != nil {
223223
return nil, i18n.WrapError(err)
224224
}
225-
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = buildPath.JoinPath(relativeSource).String() + ".o"
225+
properties.Set(constants.BUILD_PROPERTIES_OBJECT_FILE, buildPath.JoinPath(relativeSource).String()+".o")
226226

227-
err = paths.New(properties[constants.BUILD_PROPERTIES_OBJECT_FILE]).Parent().MkdirAll()
227+
err = properties.GetPath(constants.BUILD_PROPERTIES_OBJECT_FILE).Parent().MkdirAll()
228228
if err != nil {
229229
return nil, i18n.WrapError(err)
230230
}
@@ -240,10 +240,10 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
240240
return nil, i18n.WrapError(err)
241241
}
242242
} else if ctx.Verbose {
243-
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
243+
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties.Get(constants.BUILD_PROPERTIES_OBJECT_FILE))
244244
}
245245

246-
return paths.New(properties[constants.BUILD_PROPERTIES_OBJECT_FILE]), nil
246+
return properties.GetPath(constants.BUILD_PROPERTIES_OBJECT_FILE), nil
247247
}
248248

249249
func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFile *paths.Path) (bool, error) {
@@ -430,7 +430,7 @@ func TXTBuildRulesHaveChanged(corePath, targetCorePath, targetFile *paths.Path)
430430
return true
431431
}
432432

433-
func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile *paths.Path, objectFilesToArchive paths.PathList, buildProperties properties.Map) (*paths.Path, error) {
433+
func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile *paths.Path, objectFilesToArchive paths.PathList, buildProperties *properties.Map) (*paths.Path, error) {
434434
logger := ctx.GetLogger()
435435
archiveFilePath := buildPath.JoinPath(archiveFile)
436436

@@ -463,9 +463,9 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
463463

464464
for _, objectFile := range objectFilesToArchive {
465465
properties := buildProperties.Clone()
466-
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = archiveFilePath.Base()
467-
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath.String()
468-
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile.String()
466+
properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE, archiveFilePath.Base())
467+
properties.SetPath(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, archiveFilePath)
468+
properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile)
469469

470470
_, _, err := ExecRecipe(ctx, properties, constants.RECIPE_AR_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show)
471471
if err != nil {
@@ -476,7 +476,7 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
476476
return archiveFilePath, nil
477477
}
478478

479-
func ExecRecipe(ctx *types.Context, buildProperties properties.Map, recipe string, removeUnsetProperties bool, stdout int, stderr int) ([]byte, []byte, error) {
479+
func ExecRecipe(ctx *types.Context, buildProperties *properties.Map, recipe string, removeUnsetProperties bool, stdout int, stderr int) ([]byte, []byte, error) {
480480
// See util.ExecCommand for stdout/stderr arguments
481481
command, err := PrepareCommandForRecipe(ctx, buildProperties, recipe, removeUnsetProperties)
482482
if err != nil {
@@ -488,9 +488,9 @@ func ExecRecipe(ctx *types.Context, buildProperties properties.Map, recipe strin
488488

489489
const COMMANDLINE_LIMIT = 30000
490490

491-
func PrepareCommandForRecipe(ctx *types.Context, buildProperties properties.Map, recipe string, removeUnsetProperties bool) (*exec.Cmd, error) {
491+
func PrepareCommandForRecipe(ctx *types.Context, buildProperties *properties.Map, recipe string, removeUnsetProperties bool) (*exec.Cmd, error) {
492492
logger := ctx.GetLogger()
493-
pattern := buildProperties[recipe]
493+
pattern := buildProperties.Get(recipe)
494494
if pattern == "" {
495495
return nil, i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe)
496496
}
@@ -504,7 +504,7 @@ func PrepareCommandForRecipe(ctx *types.Context, buildProperties properties.Map,
504504
relativePath := ""
505505

506506
if len(commandLine) > COMMANDLINE_LIMIT {
507-
relativePath = buildProperties["build.path"]
507+
relativePath = buildProperties.Get("build.path")
508508
}
509509

510510
command, err := utils.PrepareCommand(commandLine, logger, relativePath)

container_build_options.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ func (s *ContainerBuildOptions) Run(ctx *types.Context) error {
5353
}
5454

5555
return nil
56-
5756
}

container_find_includes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
130130
cache := readCache(cachePath)
131131

132132
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH))
133-
if ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH] != "" {
133+
if ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) != "" {
134134
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH))
135135
}
136136

create_build_options_map.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package builder
3131

3232
import (
3333
"encoding/json"
34+
3435
"github.com/arduino/arduino-builder/i18n"
3536
"github.com/arduino/arduino-builder/types"
3637
)

create_cmake_rule.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
8787
}
8888
// Remove stray folders contining incompatible libraries
8989
staticLibsExtensions := func(ext string) bool { return DOTAEXTENSION[ext] }
90-
mcu := ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_MCU]
90+
mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU)
9191
var files []string
9292
utils.FindFilesInFolder(&files, libDir.Join("src").String(), staticLibsExtensions, true)
9393
for _, file := range files {
@@ -98,11 +98,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
9898
}
9999

100100
// Copy core + variant in use + preprocessed sketch in the correct folders
101-
err := utils.CopyDir(ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_CORE_PATH], coreFolder.String(), extensions)
101+
err := utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_CORE_PATH), coreFolder.String(), extensions)
102102
if err != nil {
103103
fmt.Println(err)
104104
}
105-
err = utils.CopyDir(ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH], coreFolder.Join("variant").String(), extensions)
105+
err = utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH), coreFolder.Join("variant").String(), extensions)
106106
if err != nil {
107107
fmt.Println(err)
108108
}
@@ -202,7 +202,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
202202
}
203203

204204
func canExportCmakeProject(ctx *types.Context) bool {
205-
return ctx.BuildProperties["compiler.export_cmake"] != ""
205+
return ctx.BuildProperties.Get("compiler.export_cmake") != ""
206206
}
207207

208208
func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, linkerflags, linkDirectories *[]string, logger i18n.Logger) {

ctags/ctags_properties.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
package ctags
3131

32-
import properties "github.com/arduino/go-properties-map"
32+
import properties "github.com/arduino/go-properties-orderedmap"
3333

3434
// CtagsProperties are the platform properties needed to run ctags
35-
var CtagsProperties = properties.Map{
35+
var CtagsProperties = properties.NewFromHashmap(map[string]string{
3636
// Ctags
3737
"tools.ctags.path": "{runtime.tools.ctags.path}",
3838
"tools.ctags.cmd.path": "{path}/ctags",
@@ -44,4 +44,4 @@ var CtagsProperties = properties.Map{
4444
"preproc.macros.flags": "-w -x c++ -E -CC",
4545
//"preproc.macros.compatibility_flags": `{build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}`,
4646
//"recipe.preproc.macros": `"{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} {preproc.macros.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {preproc.macros.compatibility_flags} {includes} "{source_file}" -o "{preprocessed_file_path}"`,
47-
}
47+
})

ctags_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *CTagsRunner) Run(ctx *types.Context) error {
4848
properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS))
4949
properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, ctagsTargetFilePath)
5050

51-
pattern := properties[constants.BUILD_PROPERTIES_PATTERN]
51+
pattern := properties.Get(constants.BUILD_PROPERTIES_PATTERN)
5252
if pattern == constants.EMPTY_STRING {
5353
return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, constants.CTAGS)
5454
}

dump_build_properties.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (s *DumpBuildProperties) Run(ctx *types.Context) error {
4545
sort.Strings(keys)
4646

4747
for _, key := range keys {
48-
fmt.Println(key + "=" + buildProperties[key])
48+
fmt.Println(key + "=" + buildProperties.Get(key))
4949
}
5050

5151
return nil

0 commit comments

Comments
 (0)