diff --git a/Gopkg.lock b/Gopkg.lock index 115a4ce523b..8e09d5d04b5 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,7 +3,7 @@ [[projects]] branch = "cli-inception" - digest = "1:c55e3751a4bb29e7829188f51160472e5242c74a16996f38ac59dd5571c5e4b4" + digest = "1:95d51ed84745c25bb7a9ec3cc9e530cd611cad04645d00c21c5b8a1faccf2e4f" name = "github.com/arduino/arduino-builder" packages = [ ".", @@ -17,7 +17,7 @@ "utils", ] pruneopts = "UT" - revision = "bb7d413ce08a6f05710f4a511680fbb1eee87720" + revision = "eb9e737c5c13f3dc7421e8a953f0414abbbb39a9" source = "github.com/arduino/arduino-builder" [[projects]] @@ -38,11 +38,11 @@ [[projects]] branch = "master" - digest = "1:505743a6b828146f08595c5322781472c2fee0478f0569a4a3a98fe3ab3bbf3c" - name = "github.com/arduino/go-properties-map" + digest = "1:0ee4da82ad4588eec5fff9a3d2b954cfa37ee46fe6c2e6c7ee6da12111583211" + name = "github.com/arduino/go-properties-orderedmap" packages = ["."] pruneopts = "UT" - revision = "ad37f0cfeff29fadeabe6b2f7f852d8db1fb5c41" + revision = "89278049acd3b807d566b8290a71e73b7c12ce3d" [[projects]] branch = "master" @@ -580,7 +580,7 @@ "github.com/arduino/arduino-builder/types", "github.com/arduino/board-discovery", "github.com/arduino/go-paths-helper", - "github.com/arduino/go-properties-map", + "github.com/arduino/go-properties-orderedmap", "github.com/arduino/go-win32-utils", "github.com/bcmi-labs/arduino-modules/sketches", "github.com/bgentry/go-netrc/netrc", diff --git a/Gopkg.toml b/Gopkg.toml index ce1fc99c54f..82a78e5a9b8 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -35,10 +35,6 @@ branch = "master" name = "github.com/arduino/board-discovery" -[[constraint]] - branch = "master" - name = "github.com/arduino/go-properties-map" - [[constraint]] branch = "master" name = "github.com/arduino/go-win32-utils" diff --git a/arduino/cores/board.go b/arduino/cores/board.go index 4700b6601f9..71dc2490526 100644 --- a/arduino/cores/board.go +++ b/arduino/cores/board.go @@ -21,13 +21,13 @@ import ( "fmt" "strings" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) // Board represents a board loaded from an installed platform type Board struct { BoardID string - Properties properties.Map `json:"-"` + Properties *properties.Map `json:"-"` PlatformRelease *PlatformRelease `json:"-"` } @@ -35,8 +35,8 @@ type Board struct { func (b *Board) HasUsbID(reqVid, reqPid string) bool { vids := b.Properties.SubTree("vid") pids := b.Properties.SubTree("pid") - for id, vid := range vids { - if pid, ok := pids[id]; ok { + for id, vid := range vids.AsMap() { + if pid, ok := pids.GetOk(id); ok { if strings.EqualFold(vid, reqVid) && strings.EqualFold(pid, reqPid) { return true } @@ -47,7 +47,7 @@ func (b *Board) HasUsbID(reqVid, reqPid string) bool { // Name returns the board name as defined in boards.txt properties func (b *Board) Name() string { - return b.Properties["name"] + return b.Properties.Get("name") } // FQBN return the Fully-Qualified-Board-Name for the default configuration of this board @@ -62,29 +62,40 @@ func (b *Board) String() string { // GetBuildProperties returns the build properties and the build // platform for the Board with the configuration passed as parameter. -func (b *Board) GetBuildProperties(configs properties.Map) (properties.Map, error) { +func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map, error) { + // Clone user configs because they are destroyed during iteration + userConfigs = userConfigs.Clone() + // Start with board's base properties buildProperties := b.Properties.Clone() - // Add all sub-configurations one by one + // Add all sub-configurations one by one (a config is: option=value) menu := b.Properties.SubTree("menu") - for option, value := range configs { - if option == "" { - return nil, fmt.Errorf("invalid empty option found") - } - + for _, option := range menu.FirstLevelKeys() { optionMenu := menu.SubTree(option) - if len(optionMenu) == 0 { - return nil, fmt.Errorf("invalid option '%s'", option) - } - if _, ok := optionMenu[value]; !ok { - return nil, fmt.Errorf("invalid value '%s' for option '%s'", value, option) + userValue, haveUserValue := userConfigs.GetOk(option) + if haveUserValue { + userConfigs.Remove(option) + if !optionMenu.ContainsKey(userValue) { + return nil, fmt.Errorf("invalid value '%s' for option '%s'", userValue, option) + } + } else { + // apply default + userValue = optionMenu.FirstLevelKeys()[0] } - optionsConf := optionMenu.SubTree(value) + optionsConf := optionMenu.SubTree(userValue) buildProperties.Merge(optionsConf) } + // Check for residual invalid options... + for _, invalidOption := range userConfigs.Keys() { + if invalidOption == "" { + return nil, fmt.Errorf("invalid empty option found") + } + return nil, fmt.Errorf("invalid option '%s'", invalidOption) + } + return buildProperties, nil } @@ -93,7 +104,7 @@ func (b *Board) GetBuildProperties(configs properties.Map) (properties.Map, erro // the full FQBN is "arduino:avr:mega:cpu=atmega2560" the config part must be // "cpu=atmega2560". // FIXME: deprecated, use GetBuildProperties instead -func (b *Board) GeneratePropertiesForConfiguration(config string) (properties.Map, error) { +func (b *Board) GeneratePropertiesForConfiguration(config string) (*properties.Map, error) { fqbn, err := ParseFQBN(b.String() + ":" + config) if err != nil { return nil, fmt.Errorf("parsing fqbn: %s", err) diff --git a/arduino/cores/board_test.go b/arduino/cores/board_test.go index 750edd98d52..4447737077f 100644 --- a/arduino/cores/board_test.go +++ b/arduino/cores/board_test.go @@ -20,13 +20,13 @@ package cores import ( "testing" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" "github.com/stretchr/testify/require" ) var boardUno = &Board{ BoardID: "uno", - Properties: properties.Map{ + Properties: properties.NewFromHashmap(map[string]string{ "name": "Arduino/Genuino Uno", "vid.0": "0x2341", "pid.0": "0x0043", @@ -53,7 +53,7 @@ var boardUno = &Board{ "build.board": "AVR_UNO", "build.core": "arduino", "build.variant": "standard", - }, + }), PlatformRelease: &PlatformRelease{ Platform: &Platform{ Architecture: "avr", @@ -66,7 +66,7 @@ var boardUno = &Board{ var boardMega = &Board{ BoardID: "mega", - Properties: properties.Map{ + Properties: properties.NewFromHashmap(map[string]string{ "name": "Arduino/Genuino Mega or Mega 2560", "vid.0": "0x2341", "pid.0": "0x0010", @@ -108,7 +108,7 @@ var boardMega = &Board{ "menu.cpu.atmega1280.bootloader.file": "atmega/ATmegaBOOT_168_atmega1280.hex", "menu.cpu.atmega1280.build.mcu": "atmega1280", "menu.cpu.atmega1280.build.board": "AVR_MEGA", - }, + }), PlatformRelease: &PlatformRelease{ Platform: &Platform{ Architecture: "avr", @@ -121,7 +121,7 @@ var boardMega = &Board{ var boardWatterottTiny841 = &Board{ BoardID: "attiny841", - Properties: properties.Map{ + Properties: properties.NewFromHashmap(map[string]string{ "name": "ATtiny841 (8 MHz)", "menu.core.arduino": "Standard Arduino", "menu.core.arduino.build.core": "arduino:arduino", @@ -148,7 +148,7 @@ var boardWatterottTiny841 = &Board{ "build.mcu": "attiny841", "build.f_cpu": "8000000L", "build.board": "AVR_ATTINY841", - }, + }), PlatformRelease: &PlatformRelease{ Platform: &Platform{ Architecture: "avr", @@ -188,7 +188,7 @@ func TestBoard(t *testing.T) { } func TestBoardOptions(t *testing.T) { - expConf2560 := properties.Map{ + expConf2560 := properties.NewFromHashmap(map[string]string{ "bootloader.extended_fuses": "0xFD", "bootloader.file": "stk500v2/stk500boot_v2_mega2560.hex", "bootloader.high_fuses": "0xD8", @@ -237,13 +237,13 @@ func TestBoardOptions(t *testing.T) { "vid.3": "0x2A03", "vid.4": "0x2341", "vid.5": "0x2341", - } + }) conf2560, err := boardMega.GeneratePropertiesForConfiguration("cpu=atmega2560") require.NoError(t, err, "generating cpu=atmega2560 configuration") - require.EqualValues(t, expConf2560, conf2560, "configuration for cpu=atmega2560") + require.EqualValues(t, expConf2560.AsMap(), conf2560.AsMap(), "configuration for cpu=atmega2560") - expConf1280 := properties.Map{ + expConf1280 := properties.NewFromHashmap(map[string]string{ "bootloader.extended_fuses": "0xF5", "bootloader.file": "atmega/ATmegaBOOT_168_atmega1280.hex", "bootloader.high_fuses": "0xDA", @@ -292,10 +292,10 @@ func TestBoardOptions(t *testing.T) { "vid.3": "0x2A03", "vid.4": "0x2341", "vid.5": "0x2341", - } + }) conf1280, err := boardMega.GeneratePropertiesForConfiguration("cpu=atmega1280") require.NoError(t, err, "generating cpu=atmega1280 configuration") - require.EqualValues(t, expConf1280, conf1280, "configuration for cpu=atmega1280") + require.EqualValues(t, expConf1280.AsMap(), conf1280.AsMap(), "configuration for cpu=atmega1280") _, err = boardMega.GeneratePropertiesForConfiguration("cpu=atmegassss") require.Error(t, err, "generating cpu=atmegassss configuration") @@ -303,7 +303,7 @@ func TestBoardOptions(t *testing.T) { _, err = boardUno.GeneratePropertiesForConfiguration("cpu=atmega1280") require.Error(t, err, "generating cpu=atmega1280 configuration") - expWatterott := properties.Map{ + expWatterott := properties.NewFromHashmap(map[string]string{ "bootloader.extended_fuses": "0xFE", "bootloader.file": "micronucleus-t841.hex", "bootloader.high_fuses": "0xDD", @@ -332,10 +332,10 @@ func TestBoardOptions(t *testing.T) { "upload.use_1200bps_touch": "false", "upload.wait_for_upload_port": "false", "vid.0": "0x16D0", - } + }) confWatterott, err := boardWatterottTiny841.GeneratePropertiesForConfiguration("core=spencekonde,info=info") require.NoError(t, err, "generating core=spencekonde,info=info configuration") - require.EqualValues(t, expWatterott, confWatterott, "generating core=spencekonde,info=info configuration") + require.EqualValues(t, expWatterott.AsMap(), confWatterott.AsMap(), "generating core=spencekonde,info=info configuration") // data, err := json.MarshalIndent(prop, "", " ") // require.NoError(t, err, "marshaling result") diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index b1e86569402..28a076b7445 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -23,7 +23,7 @@ import ( "github.com/arduino/go-paths-helper" "github.com/arduino/arduino-cli/arduino/resources" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" "go.bug.st/relaxed-semver" ) @@ -44,11 +44,11 @@ type PlatformRelease struct { Dependencies ToolDependencies // The Dependency entries to load tools. Platform *Platform `json:"-"` - Properties properties.Map `json:"-"` - Boards map[string]*Board `json:"-"` - Programmers map[string]properties.Map `json:"-"` - Menus map[string]string `json:"-"` - InstallDir *paths.Path `json:"-"` + Properties *properties.Map `json:"-"` + Boards map[string]*Board `json:"-"` + Programmers map[string]*properties.Map `json:"-"` + Menus *properties.Map `json:"-"` + InstallDir *paths.Path `json:"-"` } // BoardManifest contains information about a board. These metadata are usually @@ -103,8 +103,8 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) (*Platform release := &PlatformRelease{ Version: version, Boards: map[string]*Board{}, - Properties: properties.Map{}, - Programmers: map[string]properties.Map{}, + Properties: properties.NewMap(), + Programmers: map[string]*properties.Map{}, Platform: platform, } platform.Releases[tag] = release @@ -177,7 +177,7 @@ func (release *PlatformRelease) GetOrCreateBoard(boardID string) *Board { } board := &Board{ BoardID: boardID, - Properties: properties.Map{}, + Properties: properties.NewMap(), PlatformRelease: release, } release.Boards[boardID] = board @@ -198,10 +198,10 @@ func (release *PlatformRelease) RequiresToolRelease(toolRelease *ToolRelease) bo } // RuntimeProperties returns the runtime properties for this PlatformRelease -func (release *PlatformRelease) RuntimeProperties() properties.Map { - return properties.Map{ - "runtime.platform.path": release.InstallDir.String(), - } +func (release *PlatformRelease) RuntimeProperties() *properties.Map { + res := properties.NewMap() + res.Set("runtime.platform.path", release.InstallDir.String()) + return res } // GetLibrariesDir returns the path to the core libraries or nil if not diff --git a/arduino/cores/fqbn.go b/arduino/cores/fqbn.go index 3ccf455ec2a..a01f65381ad 100644 --- a/arduino/cores/fqbn.go +++ b/arduino/cores/fqbn.go @@ -19,10 +19,9 @@ package cores import ( "fmt" - "sort" "strings" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" ) // FQBN represents a Board with a specific configuration @@ -30,7 +29,7 @@ type FQBN struct { Package string PlatformArch string BoardID string - Configs properties.Map + Configs *properties.Map } // ParseFQBN extract an FQBN object from the input string @@ -45,12 +44,12 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) { Package: fqbnParts[0], PlatformArch: fqbnParts[1], BoardID: fqbnParts[2], + Configs: properties.NewMap(), } if fqbn.BoardID == "" { return nil, fmt.Errorf("invalid fqbn: empty board identifier") } if len(fqbnParts) > 3 { - fqbn.Configs = properties.Map{} for _, pair := range strings.Split(fqbnParts[3], ",") { parts := strings.SplitN(pair, "=", 2) if len(parts) != 2 { @@ -61,7 +60,7 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) { if k == "" { return nil, fmt.Errorf("invalid fqbn config: %s", pair) } - fqbn.Configs[k] = v + fqbn.Configs.Set(k, v) } } return fqbn, nil @@ -69,12 +68,10 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) { func (fqbn *FQBN) String() string { res := fmt.Sprintf("%s:%s:%s", fqbn.Package, fqbn.PlatformArch, fqbn.BoardID) - if fqbn.Configs != nil { + if fqbn.Configs.Size() > 0 { sep := ":" - keys := fqbn.Configs.Keys() - sort.Strings(keys) - for _, k := range keys { - res += sep + k + "=" + fqbn.Configs[k] + for _, k := range fqbn.Configs.Keys() { + res += sep + k + "=" + fqbn.Configs.Get(k) sep = "," } } diff --git a/arduino/cores/fqbn_test.go b/arduino/cores/fqbn_test.go index 1f998e690b5..93b0e6a75c3 100644 --- a/arduino/cores/fqbn_test.go +++ b/arduino/cores/fqbn_test.go @@ -30,7 +30,7 @@ func TestFQBN(t *testing.T) { require.Equal(t, a.Package, "arduino") require.Equal(t, a.PlatformArch, "avr") require.Equal(t, a.BoardID, "uno") - require.Nil(t, a.Configs) + require.Zero(t, a.Configs.Size()) // Allow empty plaforms or packages b1, err := ParseFQBN("arduino::uno") @@ -39,7 +39,7 @@ func TestFQBN(t *testing.T) { require.Equal(t, b1.Package, "arduino") require.Equal(t, b1.PlatformArch, "") require.Equal(t, b1.BoardID, "uno") - require.Nil(t, b1.Configs) + require.Zero(t, b1.Configs.Size()) b2, err := ParseFQBN(":avr:uno") require.Equal(t, ":avr:uno", b2.String()) @@ -47,7 +47,7 @@ func TestFQBN(t *testing.T) { require.Equal(t, b2.Package, "") require.Equal(t, b2.PlatformArch, "avr") require.Equal(t, b2.BoardID, "uno") - require.Nil(t, b2.Configs) + require.Zero(t, b2.Configs.Size()) b3, err := ParseFQBN("::uno") require.Equal(t, "::uno", b3.String()) @@ -55,7 +55,7 @@ func TestFQBN(t *testing.T) { require.Equal(t, b3.Package, "") require.Equal(t, b3.PlatformArch, "") require.Equal(t, b3.BoardID, "uno") - require.Nil(t, b3.Configs) + require.Zero(t, b3.Configs.Size()) // Do not allow missing board identifier _, err = ParseFQBN("arduino:avr:") @@ -70,7 +70,7 @@ func TestFQBN(t *testing.T) { // Sort keys in fbqn config s, err := ParseFQBN("arduino:avr:uno:d=x,b=x,a=x,e=x,c=x") require.NoError(t, err) - require.Equal(t, "arduino:avr:uno:a=x,b=x,c=x,d=x,e=x", s.String()) + require.Equal(t, "arduino:avr:uno:d=x,b=x,a=x,e=x,c=x", s.String()) // Test configs c, err := ParseFQBN("arduino:avr:uno:cpu=atmega") @@ -114,12 +114,12 @@ func TestFQBN(t *testing.T) { // Allow "=" in config values f, err := ParseFQBN("arduino:avr:uno:cpu=atmega,speed=1000,extra=core=arduino") - require.Equal(t, "arduino:avr:uno:cpu=atmega,extra=core=arduino,speed=1000", f.String()) + require.Equal(t, "arduino:avr:uno:cpu=atmega,speed=1000,extra=core=arduino", f.String()) require.NoError(t, err) require.Equal(t, f.Package, "arduino") require.Equal(t, f.PlatformArch, "avr") require.Equal(t, f.BoardID, "uno") require.Equal(t, - "properties.Map{\n \"cpu\": \"atmega\",\n \"extra\": \"core=arduino\",\n \"speed\": \"1000\",\n}", + "properties.Map{\n \"cpu\": \"atmega\",\n \"speed\": \"1000\",\n \"extra\": \"core=arduino\",\n}", f.Configs.Dump()) } diff --git a/arduino/cores/packagemanager/loader.go b/arduino/cores/packagemanager/loader.go index fa1187ebfdf..488e6b4a9f7 100644 --- a/arduino/cores/packagemanager/loader.go +++ b/arduino/cores/packagemanager/loader.go @@ -26,7 +26,7 @@ import ( "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/configs" "github.com/arduino/go-paths-helper" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" "go.bug.st/relaxed-semver" ) @@ -274,7 +274,7 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p // Create programmers properties if programmersProperties, err := properties.SafeLoad(programmersTxtPath.String()); err == nil { platform.Programmers = properties.MergeMapsOfProperties( - map[string]properties.Map{}, + map[string]*properties.Map{}, platform.Programmers, // TODO: Very weird, why not an empty one? programmersProperties.FirstLevelOf()) } else { @@ -313,7 +313,7 @@ func (pm *PackageManager) loadBoards(platform *cores.PlatformRelease) error { delete(propertiesByBoard, "menu") // TODO: check this one for boardID, boardProperties := range propertiesByBoard { - boardProperties["_id"] = boardID // TODO: What is that for?? + boardProperties.Set("_id", boardID) // TODO: What is that for?? board := platform.GetOrCreateBoard(boardID) board.Properties.Merge(boardProperties) } @@ -419,7 +419,7 @@ func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) er for packager, toolsData := range all.FirstLevelOf() { targetPackage := pm.packages.GetOrCreatePackage(packager) - for toolName, toolVersion := range toolsData { + for toolName, toolVersion := range toolsData.AsMap() { tool := targetPackage.GetOrCreateTool(toolName) version := semver.ParseRelaxed(toolVersion) release := tool.GetOrCreateRelease(version) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 6fc74c9f396..091e3d8b93c 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -27,7 +27,7 @@ import ( "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packageindex" "github.com/arduino/go-paths-helper" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" "github.com/sirupsen/logrus" "go.bug.st/relaxed-semver" ) @@ -144,7 +144,7 @@ func (pm *PackageManager) FindBoardWithFQBN(fqbnIn string) (*cores.Board, error) // returned together with the error. func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) ( *cores.Package, *cores.PlatformRelease, *cores.Board, - properties.Map, *cores.PlatformRelease, error) { + *properties.Map, *cores.PlatformRelease, error) { // Find package targetPackage := pm.packages.Packages[fqbn.Package] @@ -181,7 +181,7 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) ( // Determine the platform used for the build (in case the board refers // to a core contained in another platform) buildPlatformRelease := platformRelease - coreParts := strings.Split(buildProperties["build.core"], ":") + coreParts := strings.Split(buildProperties.Get("build.core"), ":") if len(coreParts) > 1 { referredPackage := coreParts[1] buildPackage := pm.packages.Packages[referredPackage] diff --git a/arduino/cores/tools.go b/arduino/cores/tools.go index 10d718464ad..d80600a1fc7 100644 --- a/arduino/cores/tools.go +++ b/arduino/cores/tools.go @@ -23,7 +23,7 @@ import ( "github.com/arduino/arduino-cli/arduino/resources" "github.com/arduino/go-paths-helper" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" "go.bug.st/relaxed-semver" ) @@ -133,11 +133,11 @@ func (tr *ToolRelease) String() string { } // RuntimeProperties returns the runtime properties for this tool -func (tr *ToolRelease) RuntimeProperties() properties.Map { - return properties.Map{ - "runtime.tools." + tr.Tool.Name + ".path": tr.InstallDir.String(), - "runtime.tools." + tr.Tool.Name + "-" + tr.Version.String() + ".path": tr.InstallDir.String(), - } +func (tr *ToolRelease) RuntimeProperties() *properties.Map { + res := properties.NewMap() + res.Set("runtime.tools."+tr.Tool.Name+".path", tr.InstallDir.String()) + res.Set("runtime.tools."+tr.Tool.Name+"-"+tr.Version.String()+".path", tr.InstallDir.String()) + return res } var ( diff --git a/arduino/libraries/libraries.go b/arduino/libraries/libraries.go index e9340face1a..eb9c86ae9bd 100644 --- a/arduino/libraries/libraries.go +++ b/arduino/libraries/libraries.go @@ -22,6 +22,7 @@ import ( "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/go-paths-helper" + properties "github.com/arduino/go-properties-orderedmap" semver "go.bug.st/relaxed-semver" ) @@ -66,7 +67,7 @@ type Library struct { IsLegacy bool Version *semver.Version License string - Properties map[string]string + Properties *properties.Map } func (library *Library) String() string { diff --git a/arduino/libraries/loader.go b/arduino/libraries/loader.go index 4d2f26e0977..ad4408c4ea4 100644 --- a/arduino/libraries/loader.go +++ b/arduino/libraries/loader.go @@ -22,7 +22,7 @@ import ( "strings" "github.com/arduino/go-paths-helper" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" semver "go.bug.st/relaxed-semver" ) @@ -47,13 +47,13 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library, return nil, fmt.Errorf("loading library.properties: %s", err) } - if libProperties["maintainer"] == "" && libProperties["email"] != "" { - libProperties["maintainer"] = libProperties["email"] + if libProperties.Get("maintainer") == "" && libProperties.Get("email") != "" { + libProperties.Set("maintainer", libProperties.Get("email")) } for _, propName := range MandatoryProperties { - if libProperties[propName] == "" { - libProperties[propName] = "-" + if libProperties.Get(propName) == "" { + libProperties.Set(propName, "-") } } @@ -69,26 +69,26 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library, addUtilityDirectory(library) } - if libProperties["architectures"] == "" { - libProperties["architectures"] = "*" + if libProperties.Get("architectures") == "" { + libProperties.Set("architectures", "*") } library.Architectures = []string{} - for _, arch := range strings.Split(libProperties["architectures"], ",") { + for _, arch := range strings.Split(libProperties.Get("architectures"), ",") { library.Architectures = append(library.Architectures, strings.TrimSpace(arch)) } - libProperties["category"] = strings.TrimSpace(libProperties["category"]) - if !ValidCategories[libProperties["category"]] { - libProperties["category"] = "Uncategorized" + libProperties.Set("category", strings.TrimSpace(libProperties.Get("category"))) + if !ValidCategories[libProperties.Get("category")] { + libProperties.Set("category", "Uncategorized") } - library.Category = libProperties["category"] + library.Category = libProperties.Get("category") - if libProperties["license"] == "" { - libProperties["license"] = "Unspecified" + if libProperties.Get("license") == "" { + libProperties.Set("license", "Unspecified") } - library.License = libProperties["license"] + library.License = libProperties.Get("license") - version := strings.TrimSpace(libProperties["version"]) + version := strings.TrimSpace(libProperties.Get("version")) if v, err := semver.Parse(version); err != nil { // FIXME: do it in linter? //fmt.Printf("invalid version %s for library in %s: %s", version, libraryDir, err) @@ -97,16 +97,16 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library, } library.Name = libraryDir.Base() - library.RealName = strings.TrimSpace(libProperties["name"]) - library.Author = strings.TrimSpace(libProperties["author"]) - library.Maintainer = strings.TrimSpace(libProperties["maintainer"]) - library.Sentence = strings.TrimSpace(libProperties["sentence"]) - library.Paragraph = strings.TrimSpace(libProperties["paragraph"]) - library.Website = strings.TrimSpace(libProperties["url"]) + library.RealName = strings.TrimSpace(libProperties.Get("name")) + library.Author = strings.TrimSpace(libProperties.Get("author")) + library.Maintainer = strings.TrimSpace(libProperties.Get("maintainer")) + library.Sentence = strings.TrimSpace(libProperties.Get("sentence")) + library.Paragraph = strings.TrimSpace(libProperties.Get("paragraph")) + library.Website = strings.TrimSpace(libProperties.Get("url")) library.IsLegacy = false - library.DotALinkage = strings.TrimSpace(libProperties["dot_a_linkage"]) == "true" - library.Precompiled = strings.TrimSpace(libProperties["precompiled"]) == "true" - library.LDflags = strings.TrimSpace(libProperties["ldflags"]) + library.DotALinkage = libProperties.GetBoolean("dot_a_linkage") + library.Precompiled = libProperties.GetBoolean("precompiled") + library.LDflags = strings.TrimSpace(libProperties.Get("ldflags")) library.Properties = libProperties return library, nil diff --git a/commands/commands_test.go b/commands/commands_test.go index 003d3d74120..d1f37f343b2 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -369,6 +369,37 @@ func detectLatestAVRCore(t *testing.T) string { return latest.String() } +func TestCompileCommands(t *testing.T) { + defer makeTempDataDir(t)() + defer makeTempSketchbookDir(t)() + + // Set staging dir to a temporary dir + tmp, err := ioutil.TempDir(os.TempDir(), "test") + require.NoError(t, err, "making temporary staging dir") + defer os.RemoveAll(tmp) + + updateCoreIndex(t) + + // Download latest AVR + exitCode, _ := executeWithArgs(t, "core", "install", "arduino:avr") + require.Zero(t, exitCode, "exit code") + + // Create a test sketch + exitCode, d := executeWithArgs(t, "sketch", "new", "Test1") + require.Zero(t, exitCode, "exit code") + require.Contains(t, string(d), "Sketch created") + + // Build sketch for arduino:avr:uno + exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:uno", currSketchbookDir.Join("Test1").String()) + require.Zero(t, exitCode, "exit code") + require.Contains(t, string(d), "Sketch uses") + + // Build sketch for arduino:avr:nano (without options) + exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:nano", currSketchbookDir.Join("Test1").String()) + require.Zero(t, exitCode, "exit code") + require.Contains(t, string(d), "Sketch uses") +} + func TestCoreCommands(t *testing.T) { defer makeTempDataDir(t)() defer makeTempSketchbookDir(t)() @@ -473,15 +504,6 @@ func TestCoreCommands(t *testing.T) { require.Zero(t, exitCode, "exit code") require.Contains(t, string(d), "arduino:avr") - // Build sketch for arduino:avr:uno - exitCode, d = executeWithArgs(t, "sketch", "new", "Test1") - require.Zero(t, exitCode, "exit code") - require.Contains(t, string(d), "Sketch created") - - exitCode, d = executeWithArgs(t, "compile", "-b", "arduino:avr:uno", currSketchbookDir.Join("Test1").String()) - require.Zero(t, exitCode, "exit code") - require.Contains(t, string(d), "Sketch uses") - // Uninstall arduino:avr exitCode, d = executeWithArgs(t, "core", "uninstall", "arduino:avr") require.Zero(t, exitCode, "exit code") diff --git a/commands/compile/compile.go b/commands/compile/compile.go index b4bfbcdbb01..27cade9108d 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -32,7 +32,7 @@ import ( "github.com/arduino/arduino-cli/commands/core" "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/go-paths-helper" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -215,13 +215,13 @@ func run(cmd *cobra.Command, args []string) { lastIdeSubProperties := ideProperties.SubTree("last").SubTree("ide") // Preferences can contain records from previous IDE versions. Find the latest one. var pathVariants []string - for k := range lastIdeSubProperties { + for k := range lastIdeSubProperties.AsMap() { if strings.HasSuffix(k, ".hardwarepath") { pathVariants = append(pathVariants, k) } } sort.Strings(pathVariants) - ideHardwarePath := lastIdeSubProperties[pathVariants[len(pathVariants)-1]] + ideHardwarePath := lastIdeSubProperties.Get(pathVariants[len(pathVariants)-1]) ideLibrariesPath := filepath.Join(filepath.Dir(ideHardwarePath), "libraries") ctx.BuiltInLibrariesDirs = paths.NewPathList(ideLibrariesPath) } diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 17d379ac572..d1dd9ddf265 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -29,7 +29,7 @@ import ( "github.com/arduino/arduino-cli/common/formatter" "github.com/arduino/arduino-cli/executils" "github.com/arduino/go-paths-helper" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" "github.com/sirupsen/logrus" "github.com/spf13/cobra" serial "go.bug.st/serial.v1" @@ -105,7 +105,7 @@ func run(command *cobra.Command, args []string) { } // Create board configuration - var boardProperties properties.Map + var boardProperties *properties.Map if len(fqbnParts) == 3 { boardProperties = board.Properties } else { @@ -118,7 +118,7 @@ func run(command *cobra.Command, args []string) { } // Load programmer tool - uploadToolID, have := boardProperties["upload.tool"] + uploadToolID, have := boardProperties.GetOk("upload.tool") if !have || uploadToolID == "" { formatter.PrintErrorMessage("The board defines an invalid 'upload.tool': " + uploadToolID) os.Exit(commands.ErrGeneric) @@ -177,27 +177,27 @@ func run(command *cobra.Command, args []string) { // Set properties for verbose upload if flags.verbose { - if v, ok := uploadProperties["upload.params.verbose"]; ok { - uploadProperties["upload.verbose"] = v + if v, ok := uploadProperties.GetOk("upload.params.verbose"); ok { + uploadProperties.Set("upload.verbose", v) } } else { - if v, ok := uploadProperties["upload.params.quiet"]; ok { - uploadProperties["upload.verbose"] = v + if v, ok := uploadProperties.GetOk("upload.params.quiet"); ok { + uploadProperties.Set("upload.verbose", v) } } // Set properties for verify if flags.verify { - uploadProperties["upload.verify"] = uploadProperties["upload.params.verify"] + uploadProperties.Set("upload.verify", uploadProperties.Get("upload.params.verify")) } else { - uploadProperties["upload.verify"] = uploadProperties["upload.params.noverify"] + uploadProperties.Set("upload.verify", uploadProperties.Get("upload.params.noverify")) } // Set path to compiled binary // FIXME: refactor this should be made into a function fqbn = strings.Replace(fqbn, ":", ".", -1) - uploadProperties["build.path"] = sketch.FullPath - uploadProperties["build.project_name"] = sketch.Name + "." + fqbn + uploadProperties.Set("build.path", sketch.FullPath) + uploadProperties.Set("build.project_name", sketch.Name+"."+fqbn) ext := filepath.Ext(uploadProperties.ExpandPropsInString("{recipe.output.tmp_file}")) if _, err := os.Stat(filepath.Join(sketch.FullPath, sketch.Name+"."+fqbn+ext)); err != nil { if os.IsNotExist(err) { @@ -251,15 +251,15 @@ func run(command *cobra.Command, args []string) { } // Set serial port property - uploadProperties["serial.port"] = actualPort + uploadProperties.Set("serial.port", actualPort) if strings.HasPrefix(actualPort, "/dev/") { - uploadProperties["serial.port.file"] = actualPort[5:] + uploadProperties.Set("serial.port.file", actualPort[5:]) } else { - uploadProperties["serial.port.file"] = actualPort + uploadProperties.Set("serial.port.file", actualPort) } // Build recipe for upload - recipe := uploadProperties["upload.pattern"] + recipe := uploadProperties.Get("upload.pattern") cmdLine := uploadProperties.ExpandPropsInString(recipe) cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false) if err != nil { diff --git a/configs/preferences_txt_serializer.go b/configs/preferences_txt_serializer.go index 781dbd6cf23..cee9e71f4e9 100644 --- a/configs/preferences_txt_serializer.go +++ b/configs/preferences_txt_serializer.go @@ -25,7 +25,7 @@ import ( "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" "github.com/sirupsen/logrus" ) @@ -81,10 +81,10 @@ func (config *Configuration) LoadFromDesktopIDEPreferences() error { logrus.WithError(err).Warn("Error during unserialize from IDE preferences") return err } - if dir, has := props["sketchbook.path"]; has { + if dir, has := props.GetOk("sketchbook.path"); has { config.SketchbookDir = paths.New(dir) } - if URLs, has := props["boardsmanager.additional.urls"]; has { + if URLs, has := props.GetOk("boardsmanager.additional.urls"); has { for _, URL := range strings.Split(URLs, ",") { if newURL, err := url.Parse(URL); err == nil { BoardManagerAdditionalUrls = append(BoardManagerAdditionalUrls, newURL) @@ -94,21 +94,21 @@ func (config *Configuration) LoadFromDesktopIDEPreferences() error { return nil } -func proxyConfigsFromIDEPrefs(props properties.Map) error { +func proxyConfigsFromIDEPrefs(props *properties.Map) error { proxy := props.SubTree("proxy") - switch proxy["type"] { + switch proxy.Get("type") { case "auto": // Automatic proxy break case "manual": // Manual proxy configuration manualConfig := proxy.SubTree("manual") - hostname, exists := manualConfig["hostname"] + hostname, exists := manualConfig.GetOk("hostname") if !exists { return errors.New("proxy hostname not found in preferences.txt") } - username := manualConfig["username"] - password := manualConfig["password"] + username := manualConfig.Get("username") + password := manualConfig.Get("password") ProxyType = "manual" ProxyHostname = hostname diff --git a/vendor/github.com/arduino/arduino-builder/.travis.yml b/vendor/github.com/arduino/arduino-builder/.travis.yml index 910c086e01c..5e65b5f49eb 100644 --- a/vendor/github.com/arduino/arduino-builder/.travis.yml +++ b/vendor/github.com/arduino/arduino-builder/.travis.yml @@ -10,7 +10,7 @@ install: - go get golang.org/x/tools/cmd/cover - go get github.com/mattn/goveralls - go get github.com/wadey/gocovmerge - - go get github.com/arduino/go-properties-map + - go get github.com/arduino/go-properties-orderedmap - go get github.com/arduino/go-timeutils script: diff --git a/vendor/github.com/arduino/arduino-builder/README.md b/vendor/github.com/arduino/arduino-builder/README.md index ddd8efc2d22..275ca796928 100644 --- a/vendor/github.com/arduino/arduino-builder/README.md +++ b/vendor/github.com/arduino/arduino-builder/README.md @@ -63,7 +63,7 @@ To build, run the following commands: go get github.com/go-errors/errors go get github.com/stretchr/testify go get github.com/jstemmer/go-junit-report -go get -u github.com/arduino/go-properties-map +go get -u github.com/arduino/go-properties-orderedmap go get -u github.com/arduino/go-timeutils go get google.golang.org/grpc go get github.com/golang/protobuf/proto diff --git a/vendor/github.com/arduino/arduino-builder/add_build_board_property_if_missing.go b/vendor/github.com/arduino/arduino-builder/add_build_board_property_if_missing.go index 618886933db..c94b7a14a98 100644 --- a/vendor/github.com/arduino/arduino-builder/add_build_board_property_if_missing.go +++ b/vendor/github.com/arduino/arduino-builder/add_build_board_property_if_missing.go @@ -47,8 +47,8 @@ func (*AddBuildBoardPropertyIfMissing) Run(ctx *types.Context) error { for _, platform := range aPackage.Platforms { for _, platformRelease := range platform.Releases { for _, board := range platformRelease.Boards { - if board.Properties["build.board"] == "" { - board.Properties["build.board"] = strings.ToUpper(platform.Architecture + "_" + board.BoardID) + if board.Properties.Get("build.board") == "" { + board.Properties.Set("build.board", strings.ToUpper(platform.Architecture+"_"+board.BoardID)) logger.Fprintln( os.Stdout, constants.LOG_LEVEL_WARN, @@ -56,7 +56,7 @@ func (*AddBuildBoardPropertyIfMissing) Run(ctx *types.Context) error { aPackage.Name, platform.Architecture, board.BoardID, - board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD]) + board.Properties.Get(constants.BUILD_PROPERTIES_BUILD_BOARD)) } } } diff --git a/vendor/github.com/arduino/arduino-builder/builder_utils/utils.go b/vendor/github.com/arduino/arduino-builder/builder_utils/utils.go index 558da29aefd..194dceea7b6 100644 --- a/vendor/github.com/arduino/arduino-builder/builder_utils/utils.go +++ b/vendor/github.com/arduino/arduino-builder/builder_utils/utils.go @@ -42,7 +42,7 @@ import ( "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) { @@ -58,7 +58,7 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) { } } -func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties properties.Map, includes []string) (paths.PathList, error) { +func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes) if err != nil { return nil, i18n.WrapError(err) @@ -80,7 +80,7 @@ func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath return objectFiles, nil } -func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties properties.Map, includes []string) (paths.PathList, error) { +func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { sObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN) if err != nil { return nil, i18n.WrapError(err) @@ -100,7 +100,7 @@ func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buil return objectFiles, nil } -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) { +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) { sources, err := findFilesInFolder(sourcePath, extension, recurse) if err != nil { return nil, i18n.WrapError(err) @@ -164,7 +164,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) { return sources, nil } -func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources paths.PathList, buildPath *paths.Path, buildProperties properties.Map, includes []string, recipe string) (paths.PathList, error) { +func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources paths.PathList, buildPath *paths.Path, buildProperties *properties.Map, includes []string, recipe string) (paths.PathList, error) { objectFiles := paths.NewPathList() if len(sources) == 0 { return objectFiles, nil @@ -212,19 +212,19 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources } } -func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *paths.Path, buildPath *paths.Path, buildProperties properties.Map, includes []string, recipe string) (*paths.Path, error) { +func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string, recipe string) (*paths.Path, error) { logger := ctx.GetLogger() properties := buildProperties.Clone() - properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel] - properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE) - properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source.String() + properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel)) + properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includes, constants.SPACE)) + properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source) relativeSource, err := sourcePath.RelTo(source) if err != nil { return nil, i18n.WrapError(err) } - properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = buildPath.JoinPath(relativeSource).String() + ".o" + properties.Set(constants.BUILD_PROPERTIES_OBJECT_FILE, buildPath.JoinPath(relativeSource).String()+".o") - err = paths.New(properties[constants.BUILD_PROPERTIES_OBJECT_FILE]).Parent().MkdirAll() + err = properties.GetPath(constants.BUILD_PROPERTIES_OBJECT_FILE).Parent().MkdirAll() if err != nil { return nil, i18n.WrapError(err) } @@ -240,10 +240,10 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p return nil, i18n.WrapError(err) } } else if ctx.Verbose { - logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE]) + logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties.Get(constants.BUILD_PROPERTIES_OBJECT_FILE)) } - return paths.New(properties[constants.BUILD_PROPERTIES_OBJECT_FILE]), nil + return properties.GetPath(constants.BUILD_PROPERTIES_OBJECT_FILE), nil } func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFile *paths.Path) (bool, error) { @@ -430,7 +430,7 @@ func TXTBuildRulesHaveChanged(corePath, targetCorePath, targetFile *paths.Path) return true } -func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile *paths.Path, objectFilesToArchive paths.PathList, buildProperties properties.Map) (*paths.Path, error) { +func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile *paths.Path, objectFilesToArchive paths.PathList, buildProperties *properties.Map) (*paths.Path, error) { logger := ctx.GetLogger() archiveFilePath := buildPath.JoinPath(archiveFile) @@ -463,9 +463,9 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile for _, objectFile := range objectFilesToArchive { properties := buildProperties.Clone() - properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = archiveFilePath.Base() - properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath.String() - properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile.String() + properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE, archiveFilePath.Base()) + properties.SetPath(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, archiveFilePath) + properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile) _, _, err := ExecRecipe(ctx, properties, constants.RECIPE_AR_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show) if err != nil { @@ -476,7 +476,7 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile return archiveFilePath, nil } -func ExecRecipe(ctx *types.Context, buildProperties properties.Map, recipe string, removeUnsetProperties bool, stdout int, stderr int) ([]byte, []byte, error) { +func ExecRecipe(ctx *types.Context, buildProperties *properties.Map, recipe string, removeUnsetProperties bool, stdout int, stderr int) ([]byte, []byte, error) { // See util.ExecCommand for stdout/stderr arguments command, err := PrepareCommandForRecipe(ctx, buildProperties, recipe, removeUnsetProperties) if err != nil { @@ -488,9 +488,9 @@ func ExecRecipe(ctx *types.Context, buildProperties properties.Map, recipe strin const COMMANDLINE_LIMIT = 30000 -func PrepareCommandForRecipe(ctx *types.Context, buildProperties properties.Map, recipe string, removeUnsetProperties bool) (*exec.Cmd, error) { +func PrepareCommandForRecipe(ctx *types.Context, buildProperties *properties.Map, recipe string, removeUnsetProperties bool) (*exec.Cmd, error) { logger := ctx.GetLogger() - pattern := buildProperties[recipe] + pattern := buildProperties.Get(recipe) if pattern == "" { return nil, i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe) } @@ -504,7 +504,7 @@ func PrepareCommandForRecipe(ctx *types.Context, buildProperties properties.Map, relativePath := "" if len(commandLine) > COMMANDLINE_LIMIT { - relativePath = buildProperties["build.path"] + relativePath = buildProperties.Get("build.path") } command, err := utils.PrepareCommand(commandLine, logger, relativePath) diff --git a/vendor/github.com/arduino/arduino-builder/container_build_options.go b/vendor/github.com/arduino/arduino-builder/container_build_options.go index d2e22513440..67bd8917cbd 100644 --- a/vendor/github.com/arduino/arduino-builder/container_build_options.go +++ b/vendor/github.com/arduino/arduino-builder/container_build_options.go @@ -53,5 +53,4 @@ func (s *ContainerBuildOptions) Run(ctx *types.Context) error { } return nil - } diff --git a/vendor/github.com/arduino/arduino-builder/container_find_includes.go b/vendor/github.com/arduino/arduino-builder/container_find_includes.go index c469c820f19..e84aaabb353 100644 --- a/vendor/github.com/arduino/arduino-builder/container_find_includes.go +++ b/vendor/github.com/arduino/arduino-builder/container_find_includes.go @@ -130,7 +130,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error { cache := readCache(cachePath) appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH)) - if ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH] != "" { + if ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) != "" { appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH)) } diff --git a/vendor/github.com/arduino/arduino-builder/create_build_options_map.go b/vendor/github.com/arduino/arduino-builder/create_build_options_map.go index 0a11cc29002..f32019c36e8 100644 --- a/vendor/github.com/arduino/arduino-builder/create_build_options_map.go +++ b/vendor/github.com/arduino/arduino-builder/create_build_options_map.go @@ -31,6 +31,7 @@ package builder import ( "encoding/json" + "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" ) diff --git a/vendor/github.com/arduino/arduino-builder/create_cmake_rule.go b/vendor/github.com/arduino/arduino-builder/create_cmake_rule.go index d26fe8fc126..d127ec945d4 100644 --- a/vendor/github.com/arduino/arduino-builder/create_cmake_rule.go +++ b/vendor/github.com/arduino/arduino-builder/create_cmake_rule.go @@ -87,7 +87,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { } // Remove stray folders contining incompatible libraries staticLibsExtensions := func(ext string) bool { return DOTAEXTENSION[ext] } - mcu := ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_MCU] + mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) var files []string utils.FindFilesInFolder(&files, libDir.Join("src").String(), staticLibsExtensions, true) for _, file := range files { @@ -98,11 +98,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { } // Copy core + variant in use + preprocessed sketch in the correct folders - err := utils.CopyDir(ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_CORE_PATH], coreFolder.String(), extensions) + err := utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_CORE_PATH), coreFolder.String(), extensions) if err != nil { fmt.Println(err) } - err = utils.CopyDir(ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH], coreFolder.Join("variant").String(), extensions) + err = utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH), coreFolder.Join("variant").String(), extensions) if err != nil { fmt.Println(err) } @@ -202,7 +202,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { } func canExportCmakeProject(ctx *types.Context) bool { - return ctx.BuildProperties["compiler.export_cmake"] != "" + return ctx.BuildProperties.Get("compiler.export_cmake") != "" } func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, linkerflags, linkDirectories *[]string, logger i18n.Logger) { diff --git a/vendor/github.com/arduino/arduino-builder/ctags/ctags_properties.go b/vendor/github.com/arduino/arduino-builder/ctags/ctags_properties.go index 897e36a8848..38f15ecfe3e 100644 --- a/vendor/github.com/arduino/arduino-builder/ctags/ctags_properties.go +++ b/vendor/github.com/arduino/arduino-builder/ctags/ctags_properties.go @@ -29,10 +29,10 @@ package ctags -import properties "github.com/arduino/go-properties-map" +import properties "github.com/arduino/go-properties-orderedmap" // CtagsProperties are the platform properties needed to run ctags -var CtagsProperties = properties.Map{ +var CtagsProperties = properties.NewFromHashmap(map[string]string{ // Ctags "tools.ctags.path": "{runtime.tools.ctags.path}", "tools.ctags.cmd.path": "{path}/ctags", @@ -44,4 +44,4 @@ var CtagsProperties = properties.Map{ "preproc.macros.flags": "-w -x c++ -E -CC", //"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}`, //"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}"`, -} +}) diff --git a/vendor/github.com/arduino/arduino-builder/ctags_runner.go b/vendor/github.com/arduino/arduino-builder/ctags_runner.go index 037d98b8a45..7933bd415d8 100644 --- a/vendor/github.com/arduino/arduino-builder/ctags_runner.go +++ b/vendor/github.com/arduino/arduino-builder/ctags_runner.go @@ -48,7 +48,7 @@ func (s *CTagsRunner) Run(ctx *types.Context) error { properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS)) properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, ctagsTargetFilePath) - pattern := properties[constants.BUILD_PROPERTIES_PATTERN] + pattern := properties.Get(constants.BUILD_PROPERTIES_PATTERN) if pattern == constants.EMPTY_STRING { return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, constants.CTAGS) } diff --git a/vendor/github.com/arduino/arduino-builder/dump_build_properties.go b/vendor/github.com/arduino/arduino-builder/dump_build_properties.go index 3695916141f..b64caa8ea1f 100644 --- a/vendor/github.com/arduino/arduino-builder/dump_build_properties.go +++ b/vendor/github.com/arduino/arduino-builder/dump_build_properties.go @@ -45,7 +45,7 @@ func (s *DumpBuildProperties) Run(ctx *types.Context) error { sort.Strings(keys) for _, key := range keys { - fmt.Println(key + "=" + buildProperties[key]) + fmt.Println(key + "=" + buildProperties.Get(key)) } return nil diff --git a/vendor/github.com/arduino/arduino-builder/fail_if_imported_library_is_wrong.go b/vendor/github.com/arduino/arduino-builder/fail_if_imported_library_is_wrong.go index 6006814579f..760d0e09b39 100644 --- a/vendor/github.com/arduino/arduino-builder/fail_if_imported_library_is_wrong.go +++ b/vendor/github.com/arduino/arduino-builder/fail_if_imported_library_is_wrong.go @@ -51,7 +51,7 @@ func (s *FailIfImportedLibraryIsWrong) Run(ctx *types.Context) error { return i18n.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED) } for _, propName := range libraries.MandatoryProperties { - if _, ok := library.Properties[propName]; !ok { + if !library.Properties.ContainsKey(propName) { return i18n.ErrorfWithLogger(logger, constants.MSG_PROP_IN_LIBRARY, propName, library.InstallDir) } } diff --git a/vendor/github.com/arduino/arduino-builder/gcc_preproc_runner.go b/vendor/github.com/arduino/arduino-builder/gcc_preproc_runner.go index ade7ee49bd6..e084d8af858 100644 --- a/vendor/github.com/arduino/arduino-builder/gcc_preproc_runner.go +++ b/vendor/github.com/arduino/arduino-builder/gcc_preproc_runner.go @@ -75,11 +75,11 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths properties.SetPath(constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH, targetFilePath) includesStrings := utils.Map(includes.AsStrings(), utils.WrapWithHyphenI) - properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includesStrings, constants.SPACE) + properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includesStrings, constants.SPACE)) - if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING { + if properties.Get(constants.RECIPE_PREPROC_MACROS) == "" { //generate PREPROC_MACROS from RECIPE_CPP_PATTERN - properties[constants.RECIPE_PREPROC_MACROS] = GeneratePreprocPatternFromCompile(properties[constants.RECIPE_CPP_PATTERN]) + properties.Set(constants.RECIPE_PREPROC_MACROS, GeneratePreprocPatternFromCompile(properties.Get(constants.RECIPE_CPP_PATTERN))) } cmd, err := builder_utils.PrepareCommandForRecipe(ctx, properties, constants.RECIPE_PREPROC_MACROS, true) diff --git a/vendor/github.com/arduino/arduino-builder/load_vid_pid_specific_properties.go b/vendor/github.com/arduino/arduino-builder/load_vid_pid_specific_properties.go index df3cc434b29..ea59c60e873 100644 --- a/vendor/github.com/arduino/arduino-builder/load_vid_pid_specific_properties.go +++ b/vendor/github.com/arduino/arduino-builder/load_vid_pid_specific_properties.go @@ -36,7 +36,7 @@ import ( "github.com/arduino/arduino-builder/constants" "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type LoadVIDPIDSpecificProperties struct{} @@ -67,10 +67,10 @@ func (s *LoadVIDPIDSpecificProperties) Run(ctx *types.Context) error { return nil } -func findVIDPIDIndex(buildProperties properties.Map, vid, pid string) (int, error) { - for key, value := range buildProperties.SubTree(constants.BUILD_PROPERTIES_VID) { +func findVIDPIDIndex(buildProperties *properties.Map, vid, pid string) (int, error) { + for key, value := range buildProperties.SubTree(constants.BUILD_PROPERTIES_VID).AsMap() { if !strings.Contains(key, ".") { - if vid == strings.ToLower(value) && pid == strings.ToLower(buildProperties[constants.BUILD_PROPERTIES_PID+"."+key]) { + if vid == strings.ToLower(value) && pid == strings.ToLower(buildProperties.Get(constants.BUILD_PROPERTIES_PID+"."+key)) { return strconv.Atoi(key) } } diff --git a/vendor/github.com/arduino/arduino-builder/merge_sketch_with_bootloader.go b/vendor/github.com/arduino/arduino-builder/merge_sketch_with_bootloader.go index d0fdd5cd89f..0fcc2488ccb 100644 --- a/vendor/github.com/arduino/arduino-builder/merge_sketch_with_bootloader.go +++ b/vendor/github.com/arduino/arduino-builder/merge_sketch_with_bootloader.go @@ -38,14 +38,13 @@ import ( "github.com/arduino/arduino-builder/constants" "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" - "github.com/arduino/arduino-builder/utils" ) type MergeSketchWithBootloader struct{} func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties - if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) && !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) { + if !buildProperties.ContainsKey(constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) && !buildProperties.ContainsKey(constants.BUILD_PROPERTIES_BOOTLOADER_FILE) { return nil } @@ -67,10 +66,10 @@ func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error { } bootloader := constants.EMPTY_STRING - if utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) { - bootloader = buildProperties[constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK] + if bootloaderNoBlink, ok := buildProperties.GetOk(constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK); ok { + bootloader = bootloaderNoBlink } else { - bootloader = buildProperties[constants.BUILD_PROPERTIES_BOOTLOADER_FILE] + bootloader = buildProperties.Get(constants.BUILD_PROPERTIES_BOOTLOADER_FILE) } bootloader = buildProperties.ExpandPropsInString(bootloader) diff --git a/vendor/github.com/arduino/arduino-builder/phases/core_builder.go b/vendor/github.com/arduino/arduino-builder/phases/core_builder.go index 6dafd71cfaa..d3220a1f991 100644 --- a/vendor/github.com/arduino/arduino-builder/phases/core_builder.go +++ b/vendor/github.com/arduino/arduino-builder/phases/core_builder.go @@ -38,7 +38,7 @@ import ( "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type CoreBuilder struct{} @@ -69,7 +69,7 @@ func (s *CoreBuilder) Run(ctx *types.Context) error { return nil } -func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *paths.Path, buildProperties properties.Map) (*paths.Path, paths.PathList, error) { +func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *paths.Path, buildProperties *properties.Map) (*paths.Path, paths.PathList, error) { logger := ctx.GetLogger() coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH) variantFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) @@ -98,7 +98,7 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path var targetArchivedCore *paths.Path if buildCachePath != nil { - archivedCoreName := builder_utils.GetCachedCoreArchiveFileName(buildProperties[constants.BUILD_PROPERTIES_FQBN], realCoreFolder) + archivedCoreName := builder_utils.GetCachedCoreArchiveFileName(buildProperties.Get(constants.BUILD_PROPERTIES_FQBN), realCoreFolder) targetArchivedCore = buildCachePath.Join(archivedCoreName) canUseArchivedCore := !builder_utils.CoreOrReferencedCoreHasChanged(realCoreFolder, targetCoreFolder, targetArchivedCore) diff --git a/vendor/github.com/arduino/arduino-builder/phases/libraries_builder.go b/vendor/github.com/arduino/arduino-builder/phases/libraries_builder.go index a6a2a581621..d9a151cacd0 100644 --- a/vendor/github.com/arduino/arduino-builder/phases/libraries_builder.go +++ b/vendor/github.com/arduino/arduino-builder/phases/libraries_builder.go @@ -40,7 +40,7 @@ import ( "github.com/arduino/arduino-builder/utils" "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map[string]bool{".a": true} @@ -77,7 +77,7 @@ func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libs libraries.List) e if library.Precompiled { // add library src path to compiler.c.elf.extra_flags // use library.Name as lib name and srcPath/{mcpu} as location - mcu := ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_MCU] + mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) path := library.SourceDir.Join(mcu).String() // find all library names in the folder and prepend -l filePaths := []string{} @@ -90,13 +90,15 @@ func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libs libraries.List) e name = strings.Replace(name, "lib", "", 1) libs_cmd += "-l" + name + " " } - ctx.BuildProperties[constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS] += "\"-L" + path + "\" " + libs_cmd + " " + + currLDFlags := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS) + ctx.BuildProperties.Set(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS, currLDFlags+"\"-L"+path+"\" "+libs_cmd+" ") } } return nil } -func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *paths.Path, buildProperties properties.Map, includes []string) (paths.PathList, error) { +func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { objectFiles := paths.NewPathList() for _, library := range libraries { libraryObjectFiles, err := compileLibrary(ctx, library, buildPath, buildProperties, includes) @@ -109,7 +111,7 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p return objectFiles, nil } -func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *paths.Path, buildProperties properties.Map, includes []string) (paths.PathList, error) { +func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { logger := ctx.GetLogger() if ctx.Verbose { logger.Println(constants.LOG_LEVEL_INFO, "Compiling library \"{0}\"", library.Name) @@ -127,7 +129,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p extensions := func(ext string) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext] } filePaths := []string{} - mcu := buildProperties[constants.BUILD_PROPERTIES_BUILD_MCU] + mcu := buildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) err := utils.FindFilesInFolder(&filePaths, library.SourceDir.Join(mcu).String(), extensions, true) if err != nil { return nil, i18n.WrapError(err) diff --git a/vendor/github.com/arduino/arduino-builder/phases/linker.go b/vendor/github.com/arduino/arduino-builder/phases/linker.go index c94419e3810..e3e140ae7db 100644 --- a/vendor/github.com/arduino/arduino-builder/phases/linker.go +++ b/vendor/github.com/arduino/arduino-builder/phases/linker.go @@ -38,7 +38,7 @@ import ( "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type Linker struct{} @@ -70,18 +70,18 @@ func (s *Linker) Run(ctx *types.Context) error { return nil } -func link(ctx *types.Context, objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path, buildProperties properties.Map) error { +func link(ctx *types.Context, objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path, buildProperties *properties.Map) error { optRelax := addRelaxTrickIfATMEGA2560(buildProperties) quotedObjectFiles := utils.Map(objectFiles.AsStrings(), wrapWithDoubleQuotes) objectFileList := strings.Join(quotedObjectFiles, constants.SPACE) properties := buildProperties.Clone() - properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] + optRelax - properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel] - properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = coreDotARelPath.String() - properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = coreArchiveFilePath.String() - properties[constants.BUILD_PROPERTIES_OBJECT_FILES] = objectFileList + properties.Set(constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS)+optRelax) + properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel)) + properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE, coreDotARelPath.String()) + properties.Set(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, coreArchiveFilePath.String()) + properties.Set(constants.BUILD_PROPERTIES_OBJECT_FILES, objectFileList) _, _, err := builder_utils.ExecRecipe(ctx, properties, constants.RECIPE_C_COMBINE_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show) return err @@ -91,8 +91,8 @@ func wrapWithDoubleQuotes(value string) string { return "\"" + value + "\"" } -func addRelaxTrickIfATMEGA2560(buildProperties properties.Map) string { - if buildProperties[constants.BUILD_PROPERTIES_BUILD_MCU] == "atmega2560" { +func addRelaxTrickIfATMEGA2560(buildProperties *properties.Map) string { + if buildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) == "atmega2560" { return ",--relax" } return constants.EMPTY_STRING diff --git a/vendor/github.com/arduino/arduino-builder/phases/sizer.go b/vendor/github.com/arduino/arduino-builder/phases/sizer.go index fa719e1838c..04aa161da2c 100644 --- a/vendor/github.com/arduino/arduino-builder/phases/sizer.go +++ b/vendor/github.com/arduino/arduino-builder/phases/sizer.go @@ -39,7 +39,7 @@ import ( "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type Sizer struct { @@ -62,14 +62,14 @@ func (s *Sizer) Run(ctx *types.Context) error { return nil } -func checkSize(ctx *types.Context, buildProperties properties.Map) error { +func checkSize(ctx *types.Context, buildProperties *properties.Map) error { logger := ctx.GetLogger() properties := buildProperties.Clone() - properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel] + properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel)) - maxTextSizeString := properties[constants.PROPERTY_UPLOAD_MAX_SIZE] - maxDataSizeString := properties[constants.PROPERTY_UPLOAD_MAX_DATA_SIZE] + maxTextSizeString := properties.Get(constants.PROPERTY_UPLOAD_MAX_SIZE) + maxDataSizeString := properties.Get(constants.PROPERTY_UPLOAD_MAX_DATA_SIZE) if maxTextSizeString == "" { return nil @@ -113,8 +113,8 @@ func checkSize(ctx *types.Context, buildProperties properties.Map) error { return errors.New("") } - if properties[constants.PROPERTY_WARN_DATA_PERCENT] != "" { - warnDataPercentage, err := strconv.Atoi(properties[constants.PROPERTY_WARN_DATA_PERCENT]) + if properties.Get(constants.PROPERTY_WARN_DATA_PERCENT) != "" { + warnDataPercentage, err := strconv.Atoi(properties.Get(constants.PROPERTY_WARN_DATA_PERCENT)) if err != nil { return err } @@ -126,7 +126,7 @@ func checkSize(ctx *types.Context, buildProperties properties.Map) error { return nil } -func execSizeRecipe(ctx *types.Context, properties properties.Map) (textSize int, dataSize int, eepromSize int, resErr error) { +func execSizeRecipe(ctx *types.Context, properties *properties.Map) (textSize int, dataSize int, eepromSize int, resErr error) { out, _, err := builder_utils.ExecRecipe(ctx, properties, constants.RECIPE_SIZE_PATTERN, false /* stdout */, utils.Capture /* stderr */, utils.Show) if err != nil { resErr = errors.New("Error while determining sketch size: " + err.Error()) @@ -136,7 +136,7 @@ func execSizeRecipe(ctx *types.Context, properties properties.Map) (textSize int // force multiline match prepending "(?m)" to the actual regexp // return an error if RECIPE_SIZE_REGEXP doesn't exist - textSize, err = computeSize(properties[constants.RECIPE_SIZE_REGEXP], out) + textSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP), out) if err != nil { resErr = errors.New("Invalid size regexp: " + err.Error()) return @@ -146,13 +146,13 @@ func execSizeRecipe(ctx *types.Context, properties properties.Map) (textSize int return } - dataSize, err = computeSize(properties[constants.RECIPE_SIZE_REGEXP_DATA], out) + dataSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP_DATA), out) if err != nil { resErr = errors.New("Invalid data size regexp: " + err.Error()) return } - eepromSize, err = computeSize(properties[constants.RECIPE_SIZE_REGEXP_EEPROM], out) + eepromSize, err = computeSize(properties.Get(constants.RECIPE_SIZE_REGEXP_EEPROM), out) if err != nil { resErr = errors.New("Invalid eeprom size regexp: " + err.Error()) return diff --git a/vendor/github.com/arduino/arduino-builder/platform_keys_rewrite_loader.go b/vendor/github.com/arduino/arduino-builder/platform_keys_rewrite_loader.go index 9b0fd67d08c..c4f90a6327e 100644 --- a/vendor/github.com/arduino/arduino-builder/platform_keys_rewrite_loader.go +++ b/vendor/github.com/arduino/arduino-builder/platform_keys_rewrite_loader.go @@ -39,7 +39,7 @@ import ( "github.com/arduino/arduino-builder/constants" "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type PlatformKeysRewriteLoader struct{} @@ -73,8 +73,8 @@ func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error { return i18n.WrapError(err) } rewriteKey := strings.Join(keyParts[2:], ".") - oldValue := txt[key] - newValue := txt[constants.PLATFORM_REWRITE_NEW+"."+strings.Join(keyParts[1:], ".")] + oldValue := txt.Get(key) + newValue := txt.Get(constants.PLATFORM_REWRITE_NEW + "." + strings.Join(keyParts[1:], ".")) platformKeyRewrite := types.PlatforKeyRewrite{Key: rewriteKey, OldValue: oldValue, NewValue: newValue} platformKeysRewrite.Rewrites = growSliceOfRewrites(platformKeysRewrite.Rewrites, index) platformKeysRewrite.Rewrites[index] = platformKeyRewrite diff --git a/vendor/github.com/arduino/arduino-builder/preprocess_sketch.go b/vendor/github.com/arduino/arduino-builder/preprocess_sketch.go index c0b2be7b11d..c509b8d1c46 100644 --- a/vendor/github.com/arduino/arduino-builder/preprocess_sketch.go +++ b/vendor/github.com/arduino/arduino-builder/preprocess_sketch.go @@ -41,18 +41,18 @@ import ( "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" - properties "github.com/arduino/go-properties-map" + properties "github.com/arduino/go-properties-orderedmap" ) // ArduinoPreprocessorProperties are the platform properties needed to run arduino-preprocessor -var ArduinoPreprocessorProperties = properties.Map{ +var ArduinoPreprocessorProperties = properties.NewFromHashmap(map[string]string{ // Ctags "tools.arduino-preprocessor.path": "{runtime.tools.arduino-preprocessor.path}", "tools.arduino-preprocessor.cmd.path": "{path}/arduino-preprocessor", "tools.arduino-preprocessor.pattern": `"{cmd.path}" "{source_file}" "{codecomplete}" -- -std=gnu++11`, "preproc.macros.flags": "-w -x c++ -E -CC", -} +}) type PreprocessSketchArduino struct{} @@ -107,12 +107,12 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error { ctx.CodeCompleteAt = strings.Join(splt[1:], ":") } } - properties["codecomplete"] = "-output-code-completions=" + ctx.CodeCompleteAt + properties.Set("codecomplete", "-output-code-completions="+ctx.CodeCompleteAt) } else { - properties["codecomplete"] = "" + properties.Set("codecomplete", "") } - pattern := properties[constants.BUILD_PROPERTIES_PATTERN] + pattern := properties.Get(constants.BUILD_PROPERTIES_PATTERN) if pattern == constants.EMPTY_STRING { return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, "arduino-preprocessor") } diff --git a/vendor/github.com/arduino/arduino-builder/recipe_runner.go b/vendor/github.com/arduino/arduino-builder/recipe_runner.go index bb1bb962d44..0fd9e6d44d9 100644 --- a/vendor/github.com/arduino/arduino-builder/recipe_runner.go +++ b/vendor/github.com/arduino/arduino-builder/recipe_runner.go @@ -39,6 +39,7 @@ import ( "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" + properties "github.com/arduino/go-properties-orderedmap" ) type RecipeByPrefixSuffixRunner struct { @@ -70,10 +71,10 @@ func (s *RecipeByPrefixSuffixRunner) Run(ctx *types.Context) error { } -func findRecipes(buildProperties map[string]string, patternPrefix string, patternSuffix string) []string { +func findRecipes(buildProperties *properties.Map, patternPrefix string, patternSuffix string) []string { var recipes []string - for key, _ := range buildProperties { - if strings.HasPrefix(key, patternPrefix) && strings.HasSuffix(key, patternSuffix) && buildProperties[key] != constants.EMPTY_STRING { + for _, key := range buildProperties.Keys() { + if strings.HasPrefix(key, patternPrefix) && strings.HasSuffix(key, patternSuffix) && buildProperties.Get(key) != "" { recipes = append(recipes, key) } } diff --git a/vendor/github.com/arduino/arduino-builder/rewrite_hardware_keys.go b/vendor/github.com/arduino/arduino-builder/rewrite_hardware_keys.go index d4a02d184b4..56cf17e5632 100644 --- a/vendor/github.com/arduino/arduino-builder/rewrite_hardware_keys.go +++ b/vendor/github.com/arduino/arduino-builder/rewrite_hardware_keys.go @@ -49,10 +49,10 @@ func (s *RewriteHardwareKeys) Run(ctx *types.Context) error { for _, aPackage := range packages.Packages { for _, platform := range aPackage.Platforms { for _, platformRelease := range platform.Releases { - if platformRelease.Properties[constants.REWRITING] != constants.REWRITING_DISABLED { + if platformRelease.Properties.Get(constants.REWRITING) != constants.REWRITING_DISABLED { for _, rewrite := range platformKeysRewrite.Rewrites { - if platformRelease.Properties[rewrite.Key] != "" && platformRelease.Properties[rewrite.Key] == rewrite.OldValue { - platformRelease.Properties[rewrite.Key] = rewrite.NewValue + if platformRelease.Properties.Get(rewrite.Key) == rewrite.OldValue { + platformRelease.Properties.Set(rewrite.Key, rewrite.NewValue) appliedRewrites := rewritesAppliedToPlatform(platformRelease, hardwareRewriteResults) appliedRewrites = append(appliedRewrites, rewrite) hardwareRewriteResults[platformRelease] = appliedRewrites diff --git a/vendor/github.com/arduino/arduino-builder/set_custom_build_properties.go b/vendor/github.com/arduino/arduino-builder/set_custom_build_properties.go index 12b3467a8f0..689dddc6605 100644 --- a/vendor/github.com/arduino/arduino-builder/set_custom_build_properties.go +++ b/vendor/github.com/arduino/arduino-builder/set_custom_build_properties.go @@ -32,7 +32,7 @@ package builder import ( "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type SetCustomBuildProperties struct{} @@ -44,9 +44,7 @@ func (s *SetCustomBuildProperties) Run(ctx *types.Context) error { return i18n.WrapError(err) } - for key, value := range customBuildProperties { - buildProperties[key] = value - } + buildProperties.Merge(customBuildProperties) return nil } diff --git a/vendor/github.com/arduino/arduino-builder/setup_build_properties.go b/vendor/github.com/arduino/arduino-builder/setup_build_properties.go index 4b977e27c5b..1be22b56ad5 100644 --- a/vendor/github.com/arduino/arduino-builder/setup_build_properties.go +++ b/vendor/github.com/arduino/arduino-builder/setup_build_properties.go @@ -39,7 +39,7 @@ import ( "github.com/arduino/arduino-builder/types" "github.com/arduino/arduino-builder/utils" "github.com/arduino/arduino-cli/arduino/cores" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" "github.com/arduino/go-timeutils" ) @@ -52,7 +52,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { actualPlatform := ctx.ActualPlatform targetBoard := ctx.TargetBoard - buildProperties := make(properties.Map) + buildProperties := properties.NewMap() buildProperties.Merge(actualPlatform.Properties) buildProperties.Merge(targetPlatform.Properties) buildProperties.Merge(targetBoard.Properties) @@ -61,9 +61,9 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.SetPath("build.path", ctx.BuildPath) } if ctx.Sketch != nil { - buildProperties["build.project_name"] = ctx.Sketch.MainFile.Name.Base() + buildProperties.Set("build.project_name", ctx.Sketch.MainFile.Name.Base()) } - buildProperties["build.arch"] = strings.ToUpper(targetPlatform.Platform.Architecture) + buildProperties.Set("build.arch", strings.ToUpper(targetPlatform.Platform.Architecture)) // get base folder and use it to populate BUILD_PROPERTIES_RUNTIME_IDE_PATH (arduino and arduino-builder live in the same dir) ex, err := os.Executable() @@ -72,20 +72,20 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { exPath = filepath.Dir(ex) } - buildProperties["build.core"] = ctx.BuildCore - buildProperties["build.core.path"] = actualPlatform.InstallDir.Join("cores", buildProperties["build.core"]).String() - buildProperties["build.system.path"] = actualPlatform.InstallDir.Join("system").String() - buildProperties["runtime.platform.path"] = targetPlatform.InstallDir.String() - buildProperties["runtime.hardware.path"] = targetPlatform.InstallDir.Join("..").String() - buildProperties["runtime.ide.version"] = ctx.ArduinoAPIVersion - buildProperties["runtime.ide.path"] = exPath - buildProperties["build.fqbn"] = ctx.FQBN.String() - buildProperties["ide_version"] = ctx.ArduinoAPIVersion - buildProperties["runtime.os"] = utils.PrettyOSName() - - variant := buildProperties["build.variant"] + buildProperties.Set("build.core", ctx.BuildCore) + buildProperties.SetPath("build.core.path", actualPlatform.InstallDir.Join("cores", buildProperties.Get("build.core"))) + buildProperties.Set("build.system.path", actualPlatform.InstallDir.Join("system").String()) + buildProperties.Set("runtime.platform.path", targetPlatform.InstallDir.String()) + buildProperties.Set("runtime.hardware.path", targetPlatform.InstallDir.Join("..").String()) + buildProperties.Set("runtime.ide.version", ctx.ArduinoAPIVersion) + buildProperties.Set("runtime.ide.path", exPath) + buildProperties.Set("build.fqbn", ctx.FQBN.String()) + buildProperties.Set("ide_version", ctx.ArduinoAPIVersion) + buildProperties.Set("runtime.os", utils.PrettyOSName()) + + variant := buildProperties.Get("build.variant") if variant == "" { - buildProperties["build.variant.path"] = "" + buildProperties.Set("build.variant.path", "") } else { var variantPlatformRelease *cores.PlatformRelease variantParts := strings.Split(variant, ":") @@ -96,20 +96,20 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { } else { variantPlatformRelease = targetPlatform } - buildProperties["build.variant.path"] = variantPlatformRelease.InstallDir.Join("variants", variant).String() + buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant)) } for _, tool := range ctx.AllTools { - buildProperties["runtime.tools."+tool.Tool.Name+".path"] = tool.InstallDir.String() - buildProperties["runtime.tools."+tool.Tool.Name+"-"+tool.Version.String()+".path"] = tool.InstallDir.String() + buildProperties.SetPath("runtime.tools."+tool.Tool.Name+".path", tool.InstallDir) + buildProperties.SetPath("runtime.tools."+tool.Tool.Name+"-"+tool.Version.String()+".path", tool.InstallDir) } for _, tool := range ctx.RequiredTools { - buildProperties["runtime.tools."+tool.Tool.Name+".path"] = tool.InstallDir.String() - buildProperties["runtime.tools."+tool.Tool.Name+"-"+tool.Version.String()+".path"] = tool.InstallDir.String() + buildProperties.SetPath("runtime.tools."+tool.Tool.Name+".path", tool.InstallDir) + buildProperties.SetPath("runtime.tools."+tool.Tool.Name+"-"+tool.Version.String()+".path", tool.InstallDir) } - if !utils.MapStringStringHas(buildProperties, "software") { - buildProperties["software"] = DEFAULT_SOFTWARE + if !buildProperties.ContainsKey("software") { + buildProperties.Set("software", DEFAULT_SOFTWARE) } if ctx.SketchLocation != nil { @@ -122,10 +122,10 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { } now := time.Now() - buildProperties["extra.time.utc"] = strconv.FormatInt(now.Unix(), 10) - buildProperties["extra.time.local"] = strconv.FormatInt(timeutils.LocalUnix(now), 10) - buildProperties["extra.time.zone"] = strconv.Itoa(timeutils.TimezoneOffsetNoDST(now)) - buildProperties["extra.time.dst"] = strconv.Itoa(timeutils.DaylightSavingsOffset(now)) + buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10)) + buildProperties.Set("extra.time.local", strconv.FormatInt(timeutils.LocalUnix(now), 10)) + buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now))) + buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now))) ctx.BuildProperties = buildProperties diff --git a/vendor/github.com/arduino/arduino-builder/target_board_resolver.go b/vendor/github.com/arduino/arduino-builder/target_board_resolver.go index 4463ea9b4e6..4b36140363e 100644 --- a/vendor/github.com/arduino/arduino-builder/target_board_resolver.go +++ b/vendor/github.com/arduino/arduino-builder/target_board_resolver.go @@ -49,7 +49,7 @@ func (s *TargetBoardResolver) Run(ctx *types.Context) error { targetBoard.Properties = buildProperties // FIXME.... - core := targetBoard.Properties["build.core"] + core := targetBoard.Properties.Get("build.core") if core == "" { core = "arduino" } diff --git a/vendor/github.com/arduino/arduino-builder/types/context.go b/vendor/github.com/arduino/arduino-builder/types/context.go index b84b9cf17a8..2dfeabab956 100644 --- a/vendor/github.com/arduino/arduino-builder/types/context.go +++ b/vendor/github.com/arduino/arduino-builder/types/context.go @@ -10,7 +10,7 @@ import ( "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" "github.com/arduino/arduino-cli/arduino/libraries/librariesresolver" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type ProgressStruct struct { @@ -50,7 +50,7 @@ type Context struct { PlatformKeyRewrites PlatforKeysRewrite HardwareRewriteResults map[*cores.PlatformRelease][]PlatforKeyRewrite - BuildProperties properties.Map + BuildProperties *properties.Map BuildCore string BuildPath *paths.Path BuildCachePath *paths.Path @@ -112,13 +112,13 @@ type Context struct { UseArduinoPreprocessor bool } -func (ctx *Context) ExtractBuildOptions() properties.Map { - opts := make(properties.Map) - opts["hardwareFolders"] = strings.Join(ctx.HardwareDirs.AsStrings(), ",") - opts["toolsFolders"] = strings.Join(ctx.ToolsDirs.AsStrings(), ",") - opts["builtInLibrariesFolders"] = strings.Join(ctx.BuiltInLibrariesDirs.AsStrings(), ",") - opts["otherLibrariesFolders"] = strings.Join(ctx.OtherLibrariesDirs.AsStrings(), ",") - opts["sketchLocation"] = ctx.SketchLocation.String() +func (ctx *Context) ExtractBuildOptions() *properties.Map { + opts := properties.NewMap() + opts.Set("hardwareFolders", strings.Join(ctx.HardwareDirs.AsStrings(), ",")) + opts.Set("toolsFolders", strings.Join(ctx.ToolsDirs.AsStrings(), ",")) + opts.Set("builtInLibrariesFolders", strings.Join(ctx.BuiltInLibrariesDirs.AsStrings(), ",")) + opts.Set("otherLibrariesFolders", strings.Join(ctx.OtherLibrariesDirs.AsStrings(), ",")) + opts.SetPath("sketchLocation", ctx.SketchLocation) var additionalFilesRelative []string if ctx.Sketch != nil { for _, sketch := range ctx.Sketch.AdditionalFiles { @@ -130,26 +130,26 @@ func (ctx *Context) ExtractBuildOptions() properties.Map { additionalFilesRelative = append(additionalFilesRelative, relPath.String()) } } - opts["fqbn"] = ctx.FQBN.String() - opts["runtime.ide.version"] = ctx.ArduinoAPIVersion - opts["customBuildProperties"] = strings.Join(ctx.CustomBuildProperties, ",") - opts["additionalFiles"] = strings.Join(additionalFilesRelative, ",") + opts.Set("fqbn", ctx.FQBN.String()) + opts.Set("runtime.ide.version", ctx.ArduinoAPIVersion) + opts.Set("customBuildProperties", strings.Join(ctx.CustomBuildProperties, ",")) + opts.Set("additionalFiles", strings.Join(additionalFilesRelative, ",")) return opts } -func (ctx *Context) InjectBuildOptions(opts properties.Map) { - ctx.HardwareDirs = paths.NewPathList(strings.Split(opts["hardwareFolders"], ",")...) - ctx.ToolsDirs = paths.NewPathList(strings.Split(opts["toolsFolders"], ",")...) - ctx.BuiltInLibrariesDirs = paths.NewPathList(strings.Split(opts["builtInLibrariesFolders"], ",")...) - ctx.OtherLibrariesDirs = paths.NewPathList(strings.Split(opts["otherLibrariesFolders"], ",")...) - ctx.SketchLocation = paths.New(opts["sketchLocation"]) - fqbn, err := cores.ParseFQBN(opts["fqbn"]) +func (ctx *Context) InjectBuildOptions(opts *properties.Map) { + ctx.HardwareDirs = paths.NewPathList(strings.Split(opts.Get("hardwareFolders"), ",")...) + ctx.ToolsDirs = paths.NewPathList(strings.Split(opts.Get("toolsFolders"), ",")...) + ctx.BuiltInLibrariesDirs = paths.NewPathList(strings.Split(opts.Get("builtInLibrariesFolders"), ",")...) + ctx.OtherLibrariesDirs = paths.NewPathList(strings.Split(opts.Get("otherLibrariesFolders"), ",")...) + ctx.SketchLocation = opts.GetPath("sketchLocation") + fqbn, err := cores.ParseFQBN(opts.Get("fqbn")) if err != nil { i18n.ErrorfWithLogger(ctx.GetLogger(), "Error in FQBN: %s", err) } ctx.FQBN = fqbn - ctx.ArduinoAPIVersion = opts["runtime.ide.version"] - ctx.CustomBuildProperties = strings.Split(opts["customBuildProperties"], ",") + ctx.ArduinoAPIVersion = opts.Get("runtime.ide.version") + ctx.CustomBuildProperties = strings.Split(opts.Get("customBuildProperties"), ",") } func (ctx *Context) GetLogger() i18n.Logger { diff --git a/vendor/github.com/arduino/arduino-builder/utils/utils.go b/vendor/github.com/arduino/arduino-builder/utils/utils.go index 25cac5196c7..649807bb1c2 100644 --- a/vendor/github.com/arduino/arduino-builder/utils/utils.go +++ b/vendor/github.com/arduino/arduino-builder/utils/utils.go @@ -324,11 +324,6 @@ func ExecCommand(ctx *types.Context, command *exec.Cmd, stdout int, stderr int) return outbytes, errbytes, i18n.WrapError(err) } -func MapStringStringHas(aMap map[string]string, key string) bool { - _, ok := aMap[key] - return ok -} - func AbsolutizePaths(files []string) ([]string, error) { for idx, file := range files { if file == "" { diff --git a/vendor/github.com/arduino/arduino-builder/warn_about_arch_incompatible_libraries.go b/vendor/github.com/arduino/arduino-builder/warn_about_arch_incompatible_libraries.go index c72e46f7459..32b80fd1f83 100644 --- a/vendor/github.com/arduino/arduino-builder/warn_about_arch_incompatible_libraries.go +++ b/vendor/github.com/arduino/arduino-builder/warn_about_arch_incompatible_libraries.go @@ -49,7 +49,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error { logger := ctx.GetLogger() archs := []string{targetPlatform.Platform.Architecture} - if overrides, ok := buildProperties[constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK]; ok { + if overrides, ok := buildProperties.GetOk(constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK); ok { archs = append(archs, strings.Split(overrides, ",")...) } diff --git a/vendor/github.com/arduino/arduino-builder/warn_about_platform_rewrites.go b/vendor/github.com/arduino/arduino-builder/warn_about_platform_rewrites.go index bdc930dccda..f6e39810eb8 100644 --- a/vendor/github.com/arduino/arduino-builder/warn_about_platform_rewrites.go +++ b/vendor/github.com/arduino/arduino-builder/warn_about_platform_rewrites.go @@ -57,7 +57,11 @@ func (s *WarnAboutPlatformRewrites) Run(ctx *types.Context) error { for _, platform := range platforms { if hardwareRewriteResults[platform] != nil { for _, rewrite := range hardwareRewriteResults[platform] { - logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue) + logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, + constants.MSG_WARNING_PLATFORM_OLD_VALUES, + platform.Properties.Get(constants.PLATFORM_NAME), + rewrite.Key+"="+rewrite.OldValue, + rewrite.Key+"="+rewrite.NewValue) } } } diff --git a/vendor/github.com/arduino/arduino-builder/wipeout_build_path_if_build_options_changed.go b/vendor/github.com/arduino/arduino-builder/wipeout_build_path_if_build_options_changed.go index b7bc09468a0..4816d7972f9 100644 --- a/vendor/github.com/arduino/arduino-builder/wipeout_build_path_if_build_options_changed.go +++ b/vendor/github.com/arduino/arduino-builder/wipeout_build_path_if_build_options_changed.go @@ -38,7 +38,7 @@ import ( "github.com/arduino/arduino-builder/gohasissues" "github.com/arduino/arduino-builder/i18n" "github.com/arduino/arduino-builder/types" - "github.com/arduino/go-properties-map" + "github.com/arduino/go-properties-orderedmap" ) type WipeoutBuildPathIfBuildOptionsChanged struct{} @@ -51,15 +51,15 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious logger := ctx.GetLogger() - var opts properties.Map - var prevOpts properties.Map + var opts *properties.Map + var prevOpts *properties.Map json.Unmarshal([]byte(buildOptionsJson), &opts) json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts) // If SketchLocation path is different but filename is the same, consider it equal - if filepath.Base(opts["sketchLocation"]) == filepath.Base(prevOpts["sketchLocation"]) { - delete(opts, "sketchLocation") - delete(prevOpts, "sketchLocation") + if filepath.Base(opts.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) { + opts.Remove("sketchLocation") + prevOpts.Remove("sketchLocation") } // If options are not changed check if core has diff --git a/vendor/github.com/arduino/go-properties-map/LICENSE b/vendor/github.com/arduino/go-properties-orderedmap/LICENSE similarity index 100% rename from vendor/github.com/arduino/go-properties-map/LICENSE rename to vendor/github.com/arduino/go-properties-orderedmap/LICENSE diff --git a/vendor/github.com/arduino/go-properties-map/README.md b/vendor/github.com/arduino/go-properties-orderedmap/README.md similarity index 59% rename from vendor/github.com/arduino/go-properties-map/README.md rename to vendor/github.com/arduino/go-properties-orderedmap/README.md index 8bbc49a22e3..ac1e783fbbf 100644 --- a/vendor/github.com/arduino/go-properties-map/README.md +++ b/vendor/github.com/arduino/go-properties-orderedmap/README.md @@ -1,5 +1,5 @@ -[![GoDoc](https://godoc.org/github.com/arduino/go-properties-map?status.svg)](https://godoc.org/github.com/arduino/go-properties-map) +[![GoDoc](https://godoc.org/github.com/arduino/go-properties-orderedmap?status.svg)](https://godoc.org/github.com/arduino/go-properties-orderedmap) Package `properties` is a library for handling maps of hierarchical properties. @@ -7,5 +7,7 @@ This library is mainly used in the Arduino platform software to handle configurations made of key/value pairs stored in files with an INI like syntax. +This map also keeps the insertion order when ranging through the `Keys()` method. + For more information read the docs [here](https://godoc.org/github.com/arduino/go-properties-map). diff --git a/vendor/github.com/arduino/go-properties-orderedmap/json.go b/vendor/github.com/arduino/go-properties-orderedmap/json.go new file mode 100644 index 00000000000..4163edfd1f6 --- /dev/null +++ b/vendor/github.com/arduino/go-properties-orderedmap/json.go @@ -0,0 +1,56 @@ +/* + * This file is part of PropertiesOrderedMap library. + * + * Copyright 2018 Arduino AG (http://www.arduino.cc/) + * + * PropertiesOrderedMap library is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + */ + +package properties + +import ( + "encoding/json" +) + +// XXX: no simple way to preserve ordering in JSON. + +// MarshalJSON implements json.Marshaler interface +func (m *Map) MarshalJSON() ([]byte, error) { + return json.Marshal(m.kv) +} + +// UnmarshalJSON implements json.Unmarshaler interface +func (m *Map) UnmarshalJSON(d []byte) error { + var obj map[string]string + if err := json.Unmarshal(d, &obj); err != nil { + return err + } + + m.kv = map[string]string{} + m.o = []string{} + for k, v := range obj { + m.Set(k, v) + } + return nil +} diff --git a/vendor/github.com/arduino/go-properties-map/objects.go b/vendor/github.com/arduino/go-properties-orderedmap/objects.go similarity index 77% rename from vendor/github.com/arduino/go-properties-map/objects.go rename to vendor/github.com/arduino/go-properties-orderedmap/objects.go index b9edc2e6e7f..9807e68cc06 100644 --- a/vendor/github.com/arduino/go-properties-map/objects.go +++ b/vendor/github.com/arduino/go-properties-orderedmap/objects.go @@ -1,9 +1,9 @@ /* - * This file is part of PropertiesMap library. + * This file is part of PropertiesOrderedMap library. * * Copyright 2018 Arduino AG (http://www.arduino.cc/) * - * PropertiesMap library is free software; you can redistribute it and/or modify + * PropertiesOrderedMap library is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. @@ -30,30 +30,32 @@ package properties import ( + "strings" + "github.com/arduino/go-paths-helper" ) // GetBoolean returns true if the map contains the specified key and the value // equals to the string "true", in any other case returns false. -func (m Map) GetBoolean(key string) bool { - value, ok := m[key] - return ok && value == "true" +func (m *Map) GetBoolean(key string) bool { + value, ok := m.GetOk(key) + return ok && strings.TrimSpace(value) == "true" } // SetBoolean sets the specified key to the string "true" or "false" if the value // is respectively true or false. -func (m Map) SetBoolean(key string, value bool) { +func (m *Map) SetBoolean(key string, value bool) { if value { - m[key] = "true" + m.Set(key, "true") } else { - m[key] = "false" + m.Set(key, "false") } } // GetPath returns a paths.Path object using the map value as path. The function // returns nil if the key is not present. -func (m Map) GetPath(key string) *paths.Path { - value, ok := m[key] +func (m *Map) GetPath(key string) *paths.Path { + value, ok := m.GetOk(key) if !ok { return nil } @@ -61,10 +63,10 @@ func (m Map) GetPath(key string) *paths.Path { } // SetPath saves the paths.Path object in the map using the path as value of the map -func (m Map) SetPath(key string, value *paths.Path) { +func (m *Map) SetPath(key string, value *paths.Path) { if value == nil { - m[key] = "" + m.Set(key, "") } else { - m[key] = value.String() + m.Set(key, value.String()) } } diff --git a/vendor/github.com/arduino/go-properties-map/properties.go b/vendor/github.com/arduino/go-properties-orderedmap/properties.go similarity index 66% rename from vendor/github.com/arduino/go-properties-map/properties.go rename to vendor/github.com/arduino/go-properties-orderedmap/properties.go index 9ef9c1979d8..8b7031ff4b5 100644 --- a/vendor/github.com/arduino/go-properties-map/properties.go +++ b/vendor/github.com/arduino/go-properties-orderedmap/properties.go @@ -1,7 +1,7 @@ /* - * This file is part of PropertiesMap library. + * This file is part of PropertiesOrderedMap library. * - * Copyright 2017 Arduino AG (http://www.arduino.cc/) + * Copyright 2017-2018 Arduino AG (http://www.arduino.cc/) * * PropertiesMap library is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,6 +56,9 @@ syntax, for example: This library has methods to parse this kind of files into a Map object. +The Map internally keeps the insertion order so it can be retrieved later when +cycling through the key sets. + The Map object has many helper methods to accomplish some common operation on this kind of data like cloning, merging, comparing and also extracting a submap or generating a map-of-submaps from the first "level" of the hierarchy. @@ -72,14 +75,16 @@ import ( "reflect" "regexp" "runtime" - "sort" "strings" "github.com/arduino/go-paths-helper" ) // Map is a container of properties -type Map map[string]string +type Map struct { + kv map[string]string + o []string +} var osSuffix string @@ -94,8 +99,26 @@ func init() { } } +// NewMap returns a new Map +func NewMap() *Map { + return &Map{ + kv: map[string]string{}, + o: []string{}, + } +} + +// NewFromHashmap creates a new Map from the given map[string]string. +// Insertion order is not preserved. +func NewFromHashmap(orig map[string]string) *Map { + res := NewMap() + for k, v := range orig { + res.Set(k, v) + } + return res +} + // Load reads a properties file and makes a Map out of it. -func Load(filepath string) (Map, error) { +func Load(filepath string) (*Map, error) { bytes, err := ioutil.ReadFile(filepath) if err != nil { return nil, fmt.Errorf("Error reading file: %s", err) @@ -105,7 +128,7 @@ func Load(filepath string) (Map, error) { text = strings.Replace(text, "\r\n", "\n", -1) text = strings.Replace(text, "\r", "\n", -1) - properties := make(Map) + properties := NewMap() for lineNum, line := range strings.Split(text, "\n") { if err := properties.parseLine(line); err != nil { @@ -117,14 +140,14 @@ func Load(filepath string) (Map, error) { } // LoadFromPath reads a properties file and makes a Map out of it. -func LoadFromPath(path *paths.Path) (Map, error) { +func LoadFromPath(path *paths.Path) (*Map, error) { return Load(path.String()) } // LoadFromSlice reads a properties file from an array of string // and makes a Map out of it -func LoadFromSlice(lines []string) (Map, error) { - properties := make(Map) +func LoadFromSlice(lines []string) (*Map, error) { + properties := NewMap() for lineNum, line := range lines { if err := properties.parseLine(line); err != nil { @@ -135,7 +158,7 @@ func LoadFromSlice(lines []string) (Map, error) { return properties, nil } -func (m Map) parseLine(line string) error { +func (m *Map) parseLine(line string) error { line = strings.TrimSpace(line) // Skip empty lines or comments @@ -151,23 +174,23 @@ func (m Map) parseLine(line string) error { value := strings.TrimSpace(lineParts[1]) key = strings.Replace(key, "."+osSuffix, "", 1) - m[key] = value + m.Set(key, value) return nil } // SafeLoadFromPath is like LoadFromPath, except that it returns an empty Map if // the specified file doesn't exists -func SafeLoadFromPath(path *paths.Path) (Map, error) { +func SafeLoadFromPath(path *paths.Path) (*Map, error) { return SafeLoad(path.String()) } // SafeLoad is like Load, except that it returns an empty Map if the specified // file doesn't exists -func SafeLoad(filepath string) (Map, error) { +func SafeLoad(filepath string) (*Map, error) { _, err := os.Stat(filepath) if os.IsNotExist(err) { - return make(Map), nil + return NewMap(), nil } properties, err := Load(filepath) @@ -177,6 +200,49 @@ func SafeLoad(filepath string) (Map, error) { return properties, nil } +// Get retrieve the value corresponding to key +func (m *Map) Get(key string) string { + return m.kv[key] +} + +// GetOk retrieve the value corresponding to key and return a true/false indicator +// to check if the key is present in the map (true if the key is present) +func (m *Map) GetOk(key string) (string, bool) { + v, ok := m.kv[key] + return v, ok +} + +// ContainsKey returns true +func (m *Map) ContainsKey(key string) bool { + _, has := m.kv[key] + return has +} + +// Set inserts or replaces an existing key-value pair in the map +func (m *Map) Set(key, value string) { + if _, has := m.kv[key]; has { + m.Remove(key) + } + m.kv[key] = value + m.o = append(m.o, key) +} + +// Size return the number of elements in the map +func (m *Map) Size() int { + return len(m.kv) +} + +// Remove removes the key from the map +func (m *Map) Remove(key string) { + delete(m.kv, key) + for i, k := range m.o { + if k == key { + m.o = append(m.o[:i], m.o[i+1:]...) + return + } + } +} + // FirstLevelOf generates a map-of-Maps using the first level of the hierarchy // of the current Map. For example the following Map: // @@ -209,21 +275,59 @@ func SafeLoad(filepath string) (Map, error) { // "bootloader.low_fuses": "0xFF", // } // } -func (m Map) FirstLevelOf() map[string]Map { - newMap := make(map[string]Map) - for key, value := range m { +func (m *Map) FirstLevelOf() map[string]*Map { + newMap := make(map[string]*Map) + for _, key := range m.o { if strings.Index(key, ".") == -1 { continue } keyParts := strings.SplitN(key, ".", 2) if newMap[keyParts[0]] == nil { - newMap[keyParts[0]] = make(Map) + newMap[keyParts[0]] = NewMap() } - newMap[keyParts[0]][keyParts[1]] = value + value := m.kv[key] + newMap[keyParts[0]].Set(keyParts[1], value) } return newMap } +// FirstLevelKeys returns the keys in the first level of the hierarchy +// of the current Map. For example the following Map: +// +// properties.Map{ +// "uno.name": "Arduino/Genuino Uno", +// "uno.upload.tool": "avrdude", +// "uno.upload.protocol": "arduino", +// "uno.upload.maximum_size": "32256", +// "diecimila.name": "Arduino Duemilanove or Diecimila", +// "diecimila.upload.tool": "avrdude", +// "diecimila.upload.protocol": "arduino", +// "diecimila.bootloader.tool": "avrdude", +// "diecimila.bootloader.low_fuses": "0xFF", +// } +// +// will produce the following result: +// +// []string{ +// "uno", +// "diecimila", +// } +// +// the order of the original map is preserved +func (m *Map) FirstLevelKeys() []string { + res := []string{} + taken := map[string]bool{} + for _, k := range m.o { + first := strings.SplitN(k, ".", 2)[0] + if taken[first] { + continue + } + taken[first] = true + res = append(res, first) + } + return res +} + // SubTree extracts a sub Map from an existing map using the first level // of the keys hierarchy as selector. // For example the following Map: @@ -248,14 +352,15 @@ func (m Map) FirstLevelOf() map[string]Map { // "upload.protocol": "arduino", // "upload.maximum_size": "32256", // }, -func (m Map) SubTree(rootKey string) Map { +func (m *Map) SubTree(rootKey string) *Map { rootKey += "." - newMap := Map{} - for key, value := range m { + newMap := NewMap() + for _, key := range m.o { if !strings.HasPrefix(key, rootKey) { continue } - newMap[key[len(rootKey):]] = value + value := m.kv[key] + newMap.Set(key[len(rootKey):], value) } return newMap } @@ -268,10 +373,10 @@ func (m Map) SubTree(rootKey string) Map { // Each marker is replaced by the corresponding value of the Map. // The values in the Map may contains other markers, they are evaluated // recursively up to 10 times. -func (m Map) ExpandPropsInString(str string) string { +func (m *Map) ExpandPropsInString(str string) string { for i := 0; i < 10; i++ { newStr := str - for key, value := range m { + for key, value := range m.kv { newStr = strings.Replace(newStr, "{"+key+"}", value, -1) } if str == newStr { @@ -282,56 +387,57 @@ func (m Map) ExpandPropsInString(str string) string { return str } -// Merge merges a Map into this one. Each key/value of the merged Maps replaces +// Merge merges other Maps into this one. Each key/value of the merged Maps replaces // the key/value present in the original Map. -func (m Map) Merge(sources ...Map) Map { +func (m *Map) Merge(sources ...*Map) *Map { for _, source := range sources { - for key, value := range source { - m[key] = value + for _, key := range source.o { + value := source.kv[key] + m.Set(key, value) } } return m } // Keys returns an array of the keys contained in the Map -func (m Map) Keys() []string { - keys := make([]string, len(m)) - i := 0 - for key := range m { - keys[i] = key - i++ - } +func (m *Map) Keys() []string { + keys := make([]string, len(m.o)) + copy(keys, m.o) return keys } // Values returns an array of the values contained in the Map. Duplicated // values are repeated in the list accordingly. -func (m Map) Values() []string { - values := make([]string, len(m)) - i := 0 - for _, value := range m { - values[i] = value - i++ +func (m *Map) Values() []string { + values := make([]string, len(m.o)) + for i, key := range m.o { + values[i] = m.kv[key] } return values } +// AsMap return the underlying map[string]string. This is useful if you need to +// for ... range but without the requirement of the ordered elements. +func (m *Map) AsMap() map[string]string { + return m.kv +} + // Clone makes a copy of the Map -func (m Map) Clone() Map { - clone := make(Map) +func (m *Map) Clone() *Map { + clone := NewMap() clone.Merge(m) return clone } // Equals returns true if the current Map contains the same key/value pairs of -// the Map passed as argument. -func (m Map) Equals(other Map) bool { +// the Map passed as argument with the same order of insertion. +func (m *Map) Equals(other *Map) bool { return reflect.DeepEqual(m, other) } // MergeMapsOfProperties merge the map-of-Maps (obtained from the method FirstLevelOf()) into the // target map-of-Maps. -func MergeMapsOfProperties(target map[string]Map, sources ...map[string]Map) map[string]Map { +func MergeMapsOfProperties(target map[string]*Map, sources ...map[string]*Map) map[string]*Map { for _, source := range sources { for key, value := range source { target[key] = value @@ -348,15 +454,10 @@ func DeleteUnexpandedPropsFromString(str string) string { } // Dump returns a representation of the map in golang source format -func (m Map) Dump() string { +func (m *Map) Dump() string { res := "properties.Map{\n" - keys := []string{} - for k := range m { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - res += fmt.Sprintf(" \"%s\": \"%s\",\n", strings.Replace(k, `"`, `\"`, -1), strings.Replace(m[k], `"`, `\"`, -1)) + for _, k := range m.o { + res += fmt.Sprintf(" \"%s\": \"%s\",\n", strings.Replace(k, `"`, `\"`, -1), strings.Replace(m.Get(k), `"`, `\"`, -1)) } res += "}" return res diff --git a/vendor/github.com/arduino/go-properties-map/strings.go b/vendor/github.com/arduino/go-properties-orderedmap/strings.go similarity index 95% rename from vendor/github.com/arduino/go-properties-map/strings.go rename to vendor/github.com/arduino/go-properties-orderedmap/strings.go index 68910b878b3..f64b15eabe4 100644 --- a/vendor/github.com/arduino/go-properties-map/strings.go +++ b/vendor/github.com/arduino/go-properties-orderedmap/strings.go @@ -1,9 +1,9 @@ /* - * This file is part of PropertiesMap library. + * This file is part of PropertiesOrderedMap library. * * Copyright 2017-2018 Arduino AG (http://www.arduino.cc/) * - * PropertiesMap library is free software; you can redistribute it and/or modify + * PropertiesOrderedMap library is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version.