Skip to content

Commit 04a0f25

Browse files
committed
Moved props.PropertiesMap into his own package properties.Map
Also moved tests. Signed-off-by: Cristian Maglie <[email protected]>
1 parent 0b55777 commit 04a0f25

25 files changed

+234
-218
lines changed

src/arduino.cc/arduino-builder/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import (
4343
"arduino.cc/builder"
4444
"arduino.cc/builder/gohasissues"
4545
"arduino.cc/builder/i18n"
46-
"arduino.cc/builder/props"
4746
"arduino.cc/builder/types"
4847
"arduino.cc/builder/utils"
48+
"arduino.cc/properties"
4949
"github.com/go-errors/errors"
5050
)
5151

@@ -172,7 +172,7 @@ func main() {
172172
ctx := &types.Context{}
173173

174174
if *buildOptionsFileFlag != "" {
175-
buildOptions := make(props.PropertiesMap)
175+
buildOptions := make(properties.Map)
176176
if _, err := os.Stat(*buildOptionsFileFlag); err == nil {
177177
data, err := ioutil.ReadFile(*buildOptionsFileFlag)
178178
if err != nil {

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

+20-19
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@
3030
package builder_utils
3131

3232
import (
33-
"arduino.cc/builder/constants"
34-
"arduino.cc/builder/i18n"
35-
"arduino.cc/builder/props"
36-
"arduino.cc/builder/utils"
3733
"bytes"
3834
"fmt"
3935
"os"
4036
"os/exec"
4137
"path/filepath"
4238
"strings"
39+
40+
"arduino.cc/builder/constants"
41+
"arduino.cc/builder/i18n"
42+
"arduino.cc/builder/utils"
43+
"arduino.cc/properties"
4344
)
4445

45-
func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
46+
func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties properties.Map, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
4647
objectFiles, err := CompileFiles(objectFiles, sourcePath, false, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
4748
if err != nil {
4849
return nil, i18n.WrapError(err)
@@ -63,7 +64,7 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
6364
return objectFiles, nil
6465
}
6566

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) {
67+
func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties properties.Map, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
6768
objectFiles, err := compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN, verbose, warningsLevel, logger)
6869
if err != nil {
6970
return nil, i18n.WrapError(err)
@@ -79,7 +80,7 @@ func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPa
7980
return objectFiles, nil
8081
}
8182

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) {
83+
func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties properties.Map, includes []string, extension string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
8384
sources, err := findFilesInFolder(sourcePath, extension, recurse)
8485
if err != nil {
8586
return nil, i18n.WrapError(err)
@@ -115,7 +116,7 @@ func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]str
115116
return sources, nil
116117
}
117118

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) {
119+
func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties properties.Map, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
119120
for _, source := range sources {
120121
objectFile, err := compileFileWithRecipe(sourcePath, source, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger)
121122
if err != nil {
@@ -127,7 +128,7 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s
127128
return objectFiles, nil
128129
}
129130

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+
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties properties.Map, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
131132
properties := buildProperties.Clone()
132133
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
133134
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
@@ -257,7 +258,7 @@ func nonEmptyString(s string) bool {
257258
return s != constants.EMPTY_STRING
258259
}
259260

260-
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties props.PropertiesMap, verbose bool, logger i18n.Logger) (string, error) {
261+
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties properties.Map, verbose bool, logger i18n.Logger) (string, error) {
261262
archiveFilePath := filepath.Join(buildPath, archiveFile)
262263
if _, err := os.Stat(archiveFilePath); err == nil {
263264
err = os.Remove(archiveFilePath)
@@ -281,7 +282,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
281282
return archiveFilePath, nil
282283
}
283284

284-
func ExecRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) {
285+
func ExecRecipe(properties properties.Map, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) {
285286
command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
286287
if err != nil {
287288
return nil, i18n.WrapError(err)
@@ -302,16 +303,16 @@ func ExecRecipe(properties props.PropertiesMap, recipe string, removeUnsetProper
302303
return bytes, i18n.WrapError(err)
303304
}
304305

305-
func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
306-
pattern := properties[recipe]
306+
func PrepareCommandForRecipe(buildProperties properties.Map, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
307+
pattern := buildProperties[recipe]
307308
if pattern == constants.EMPTY_STRING {
308309
return nil, i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe)
309310
}
310311

311312
var err error
312-
commandLine := properties.ExpandPropsInString(pattern)
313+
commandLine := buildProperties.ExpandPropsInString(pattern)
313314
if removeUnsetProperties {
314-
commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine)
315+
commandLine, err = properties.DeleteUnexpandedPropsFromString(commandLine)
315316
if err != nil {
316317
return nil, i18n.WrapError(err)
317318
}
@@ -329,8 +330,8 @@ func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, remo
329330
return command, nil
330331
}
331332

332-
func ExecRecipeCollectStdErr(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) {
333-
command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
333+
func ExecRecipeCollectStdErr(buildProperties properties.Map, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) {
334+
command, err := PrepareCommandForRecipe(buildProperties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger)
334335
if err != nil {
335336
return "", i18n.WrapError(err)
336337
}
@@ -341,6 +342,6 @@ func ExecRecipeCollectStdErr(properties props.PropertiesMap, recipe string, remo
341342
return string(buffer.Bytes()), nil
342343
}
343344

344-
func RemoveHyphenMDDFlagFromGCCCommandLine(properties props.PropertiesMap) {
345-
properties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS] = strings.Replace(properties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS], "-MMD", "", -1)
345+
func RemoveHyphenMDDFlagFromGCCCommandLine(buildProperties properties.Map) {
346+
buildProperties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS] = strings.Replace(buildProperties[constants.BUILD_PROPERTIES_COMPILER_CPP_FLAGS], "-MMD", "", -1)
346347
}

src/arduino.cc/builder/gcc_preproc_runner.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
package builder
3131

3232
import (
33+
"path/filepath"
34+
"strings"
35+
3336
"arduino.cc/builder/builder_utils"
3437
"arduino.cc/builder/constants"
3538
"arduino.cc/builder/i18n"
36-
"arduino.cc/builder/props"
3739
"arduino.cc/builder/types"
3840
"arduino.cc/builder/utils"
39-
"path/filepath"
40-
"strings"
41+
"arduino.cc/properties"
4142
)
4243

4344
type GCCPreprocRunner struct {
@@ -98,7 +99,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(ctx *types.Context) error {
9899
return nil
99100
}
100101

101-
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) {
102+
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string) (properties.Map, string, error) {
102103
if targetFilePath != utils.NULLFile() {
103104
preprocPath := ctx.PreprocPath
104105
err := utils.EnsureFolderExists(preprocPath)

src/arduino.cc/builder/hardware_loader.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
package builder
3131

3232
import (
33+
"os"
34+
"path/filepath"
35+
3336
"arduino.cc/builder/constants"
3437
"arduino.cc/builder/i18n"
35-
"arduino.cc/builder/props"
3638
"arduino.cc/builder/types"
3739
"arduino.cc/builder/utils"
38-
"os"
39-
"path/filepath"
40+
"arduino.cc/properties"
4041
)
4142

4243
type HardwareLoader struct{}
@@ -63,7 +64,7 @@ func (s *HardwareLoader) Run(ctx *types.Context) error {
6364
return i18n.ErrorfWithLogger(logger, constants.MSG_MUST_BE_A_FOLDER, folder)
6465
}
6566

66-
hardwarePlatformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
67+
hardwarePlatformTxt, err := properties.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
6768
if err != nil {
6869
return i18n.WrapError(err)
6970
}
@@ -111,7 +112,7 @@ func getOrCreatePackage(packages *types.Packages, packageId string) *types.Packa
111112
}
112113

113114
func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger) error {
114-
packagePlatformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
115+
packagePlatformTxt, err := properties.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
115116
if err != nil {
116117
return i18n.WrapError(err)
117118
}
@@ -161,7 +162,7 @@ func getOrCreatePlatform(platforms map[string]*types.Platform, platformId string
161162
targetPlatform.PlatformId = platformId
162163
targetPlatform.Boards = make(map[string]*types.Board)
163164
targetPlatform.Properties = make(map[string]string)
164-
targetPlatform.Programmers = make(map[string]props.PropertiesMap)
165+
targetPlatform.Programmers = make(map[string]properties.Map)
165166

166167
return &targetPlatform
167168
}
@@ -185,12 +186,12 @@ func loadPlatform(targetPlatform *types.Platform, packageId string, folder strin
185186

186187
assignDefaultBoardToPlatform(targetPlatform)
187188

188-
platformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
189+
platformTxt, err := properties.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
189190
if err != nil {
190191
return i18n.WrapError(err)
191192
}
192193

193-
localPlatformProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_LOCAL_TXT), logger)
194+
localPlatformProperties, err := properties.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_LOCAL_TXT), logger)
194195
if err != nil {
195196
return i18n.WrapError(err)
196197
}
@@ -199,11 +200,11 @@ func loadPlatform(targetPlatform *types.Platform, packageId string, folder strin
199200
targetPlatform.Properties.Merge(platformTxt)
200201
targetPlatform.Properties.Merge(localPlatformProperties)
201202

202-
programmersProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PROGRAMMERS_TXT), logger)
203+
programmersProperties, err := properties.SafeLoad(filepath.Join(folder, constants.FILE_PROGRAMMERS_TXT), logger)
203204
if err != nil {
204205
return i18n.WrapError(err)
205206
}
206-
targetPlatform.Programmers = props.MergeMapsOfProperties(make(map[string]props.PropertiesMap), targetPlatform.Programmers, programmersProperties.FirstLevelOf())
207+
targetPlatform.Programmers = properties.MergeMapsOfProperties(make(map[string]properties.Map), targetPlatform.Programmers, programmersProperties.FirstLevelOf())
207208

208209
return nil
209210
}
@@ -219,26 +220,26 @@ func assignDefaultBoardToPlatform(targetPlatform *types.Platform) {
219220
}
220221

221222
func loadBoards(boards map[string]*types.Board, packageId string, platformId string, folder string, logger i18n.Logger) error {
222-
properties, err := props.Load(filepath.Join(folder, constants.FILE_BOARDS_TXT), logger)
223+
boardsProperties, err := properties.Load(filepath.Join(folder, constants.FILE_BOARDS_TXT), logger)
223224
if err != nil {
224225
return i18n.WrapError(err)
225226
}
226227

227-
localProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_BOARDS_LOCAL_TXT), logger)
228+
localProperties, err := properties.SafeLoad(filepath.Join(folder, constants.FILE_BOARDS_LOCAL_TXT), logger)
228229
if err != nil {
229230
return i18n.WrapError(err)
230231
}
231232

232-
properties = properties.Merge(localProperties)
233+
boardsProperties = boardsProperties.Merge(localProperties)
233234

234-
propertiesByBoardId := properties.FirstLevelOf()
235+
propertiesByBoardId := boardsProperties.FirstLevelOf()
235236
delete(propertiesByBoardId, constants.BOARD_PROPERTIES_MENU)
236237

237-
for boardId, properties := range propertiesByBoardId {
238-
properties[constants.ID] = boardId
239-
board := getOrCreateBoard(boards, boardId)
240-
board.Properties.Merge(properties)
241-
boards[boardId] = board
238+
for boardID, boardProperties := range propertiesByBoardId {
239+
boardProperties[constants.ID] = boardID
240+
board := getOrCreateBoard(boards, boardID)
241+
board.Properties.Merge(boardProperties)
242+
boards[boardID] = board
242243
}
243244

244245
return nil
@@ -251,7 +252,7 @@ func getOrCreateBoard(boards map[string]*types.Board, boardId string) *types.Boa
251252

252253
board := types.Board{}
253254
board.BoardId = boardId
254-
board.Properties = make(props.PropertiesMap)
255+
board.Properties = make(properties.Map)
255256

256257
return &board
257258
}

src/arduino.cc/builder/includes_to_include_folders.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
package builder
3131

3232
import (
33+
"path/filepath"
34+
"strings"
35+
3336
"arduino.cc/builder/constants"
3437
"arduino.cc/builder/i18n"
35-
"arduino.cc/builder/props"
3638
"arduino.cc/builder/types"
3739
"arduino.cc/builder/utils"
38-
"path/filepath"
39-
"strings"
40+
"arduino.cc/properties"
4041
)
4142

4243
type IncludesToIncludeFolders struct{}
@@ -73,7 +74,7 @@ func (s *IncludesToIncludeFolders) Run(ctx *types.Context) error {
7374
return nil
7475
}
7576

76-
func resolveIncludeFolders(importedLibraries []*types.Library, buildProperties props.PropertiesMap, verbose bool) []string {
77+
func resolveIncludeFolders(importedLibraries []*types.Library, buildProperties properties.Map, verbose bool) []string {
7778
var includeFolders []string
7879
includeFolders = append(includeFolders, buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE_PATH])
7980
if buildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH] != constants.EMPTY_STRING {

0 commit comments

Comments
 (0)