Skip to content

Commit 61932eb

Browse files
committed
Adopting go-properties-orderedmap
1 parent cba8e64 commit 61932eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+481
-365
lines changed

Gopkg.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
branch = "master"
3636
name = "github.com/arduino/board-discovery"
3737

38-
[[constraint]]
39-
branch = "master"
40-
name = "github.com/arduino/go-properties-map"
41-
4238
[[constraint]]
4339
branch = "master"
4440
name = "github.com/arduino/go-win32-utils"

arduino/cores/board.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ import (
2121
"fmt"
2222
"strings"
2323

24-
"github.com/arduino/go-properties-map"
24+
"github.com/arduino/go-properties-orderedmap"
2525
)
2626

2727
// Board represents a board loaded from an installed platform
2828
type Board struct {
2929
BoardID string
30-
Properties properties.Map `json:"-"`
30+
Properties *properties.Map `json:"-"`
3131
PlatformRelease *PlatformRelease `json:"-"`
3232
}
3333

3434
// HasUsbID returns true if the board match the usb vid and pid parameters
3535
func (b *Board) HasUsbID(reqVid, reqPid string) bool {
3636
vids := b.Properties.SubTree("vid")
3737
pids := b.Properties.SubTree("pid")
38-
for id, vid := range vids {
39-
if pid, ok := pids[id]; ok {
38+
for id, vid := range vids.AsMap() {
39+
if pid, ok := pids.GetOk(id); ok {
4040
if strings.EqualFold(vid, reqVid) && strings.EqualFold(pid, reqPid) {
4141
return true
4242
}
@@ -47,7 +47,7 @@ func (b *Board) HasUsbID(reqVid, reqPid string) bool {
4747

4848
// Name returns the board name as defined in boards.txt properties
4949
func (b *Board) Name() string {
50-
return b.Properties["name"]
50+
return b.Properties.Get("name")
5151
}
5252

5353
// FQBN return the Fully-Qualified-Board-Name for the default configuration of this board
@@ -62,26 +62,27 @@ func (b *Board) String() string {
6262

6363
// GetBuildProperties returns the build properties and the build
6464
// platform for the Board with the configuration passed as parameter.
65-
func (b *Board) GetBuildProperties(configs properties.Map) (properties.Map, error) {
65+
func (b *Board) GetBuildProperties(configs *properties.Map) (*properties.Map, error) {
6666
// Start with board's base properties
6767
buildProperties := b.Properties.Clone()
6868

6969
// Add all sub-configurations one by one
7070
menu := b.Properties.SubTree("menu")
71-
for option, value := range configs {
71+
for _, option := range configs.Keys() {
7272
if option == "" {
7373
return nil, fmt.Errorf("invalid empty option found")
7474
}
7575

7676
optionMenu := menu.SubTree(option)
77-
if len(optionMenu) == 0 {
77+
if optionMenu.Size() == 0 {
7878
return nil, fmt.Errorf("invalid option '%s'", option)
7979
}
80-
if _, ok := optionMenu[value]; !ok {
81-
return nil, fmt.Errorf("invalid value '%s' for option '%s'", value, option)
80+
optionValue := configs.Get(option)
81+
if !optionMenu.ContainsKey(optionValue) {
82+
return nil, fmt.Errorf("invalid value '%s' for option '%s'", optionValue, option)
8283
}
8384

84-
optionsConf := optionMenu.SubTree(value)
85+
optionsConf := optionMenu.SubTree(optionValue)
8586
buildProperties.Merge(optionsConf)
8687
}
8788

@@ -93,7 +94,7 @@ func (b *Board) GetBuildProperties(configs properties.Map) (properties.Map, erro
9394
// the full FQBN is "arduino:avr:mega:cpu=atmega2560" the config part must be
9495
// "cpu=atmega2560".
9596
// FIXME: deprecated, use GetBuildProperties instead
96-
func (b *Board) GeneratePropertiesForConfiguration(config string) (properties.Map, error) {
97+
func (b *Board) GeneratePropertiesForConfiguration(config string) (*properties.Map, error) {
9798
fqbn, err := ParseFQBN(b.String() + ":" + config)
9899
if err != nil {
99100
return nil, fmt.Errorf("parsing fqbn: %s", err)

arduino/cores/board_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ package cores
2020
import (
2121
"testing"
2222

23-
properties "github.com/arduino/go-properties-map"
23+
properties "github.com/arduino/go-properties-orderedmap"
2424
"github.com/stretchr/testify/require"
2525
)
2626

2727
var boardUno = &Board{
2828
BoardID: "uno",
29-
Properties: properties.Map{
29+
Properties: properties.NewFromHashmap(map[string]string{
3030
"name": "Arduino/Genuino Uno",
3131
"vid.0": "0x2341",
3232
"pid.0": "0x0043",
@@ -53,7 +53,7 @@ var boardUno = &Board{
5353
"build.board": "AVR_UNO",
5454
"build.core": "arduino",
5555
"build.variant": "standard",
56-
},
56+
}),
5757
PlatformRelease: &PlatformRelease{
5858
Platform: &Platform{
5959
Architecture: "avr",
@@ -66,7 +66,7 @@ var boardUno = &Board{
6666

6767
var boardMega = &Board{
6868
BoardID: "mega",
69-
Properties: properties.Map{
69+
Properties: properties.NewFromHashmap(map[string]string{
7070
"name": "Arduino/Genuino Mega or Mega 2560",
7171
"vid.0": "0x2341",
7272
"pid.0": "0x0010",
@@ -108,7 +108,7 @@ var boardMega = &Board{
108108
"menu.cpu.atmega1280.bootloader.file": "atmega/ATmegaBOOT_168_atmega1280.hex",
109109
"menu.cpu.atmega1280.build.mcu": "atmega1280",
110110
"menu.cpu.atmega1280.build.board": "AVR_MEGA",
111-
},
111+
}),
112112
PlatformRelease: &PlatformRelease{
113113
Platform: &Platform{
114114
Architecture: "avr",
@@ -121,7 +121,7 @@ var boardMega = &Board{
121121

122122
var boardWatterottTiny841 = &Board{
123123
BoardID: "attiny841",
124-
Properties: properties.Map{
124+
Properties: properties.NewFromHashmap(map[string]string{
125125
"name": "ATtiny841 (8 MHz)",
126126
"menu.core.arduino": "Standard Arduino",
127127
"menu.core.arduino.build.core": "arduino:arduino",
@@ -148,7 +148,7 @@ var boardWatterottTiny841 = &Board{
148148
"build.mcu": "attiny841",
149149
"build.f_cpu": "8000000L",
150150
"build.board": "AVR_ATTINY841",
151-
},
151+
}),
152152
PlatformRelease: &PlatformRelease{
153153
Platform: &Platform{
154154
Architecture: "avr",
@@ -188,7 +188,7 @@ func TestBoard(t *testing.T) {
188188
}
189189

190190
func TestBoardOptions(t *testing.T) {
191-
expConf2560 := properties.Map{
191+
expConf2560 := properties.NewFromHashmap(map[string]string{
192192
"bootloader.extended_fuses": "0xFD",
193193
"bootloader.file": "stk500v2/stk500boot_v2_mega2560.hex",
194194
"bootloader.high_fuses": "0xD8",
@@ -237,13 +237,13 @@ func TestBoardOptions(t *testing.T) {
237237
"vid.3": "0x2A03",
238238
"vid.4": "0x2341",
239239
"vid.5": "0x2341",
240-
}
240+
})
241241

242242
conf2560, err := boardMega.GeneratePropertiesForConfiguration("cpu=atmega2560")
243243
require.NoError(t, err, "generating cpu=atmega2560 configuration")
244-
require.EqualValues(t, expConf2560, conf2560, "configuration for cpu=atmega2560")
244+
require.EqualValues(t, expConf2560.AsMap(), conf2560.AsMap(), "configuration for cpu=atmega2560")
245245

246-
expConf1280 := properties.Map{
246+
expConf1280 := properties.NewFromHashmap(map[string]string{
247247
"bootloader.extended_fuses": "0xF5",
248248
"bootloader.file": "atmega/ATmegaBOOT_168_atmega1280.hex",
249249
"bootloader.high_fuses": "0xDA",
@@ -292,18 +292,18 @@ func TestBoardOptions(t *testing.T) {
292292
"vid.3": "0x2A03",
293293
"vid.4": "0x2341",
294294
"vid.5": "0x2341",
295-
}
295+
})
296296
conf1280, err := boardMega.GeneratePropertiesForConfiguration("cpu=atmega1280")
297297
require.NoError(t, err, "generating cpu=atmega1280 configuration")
298-
require.EqualValues(t, expConf1280, conf1280, "configuration for cpu=atmega1280")
298+
require.EqualValues(t, expConf1280.AsMap(), conf1280.AsMap(), "configuration for cpu=atmega1280")
299299

300300
_, err = boardMega.GeneratePropertiesForConfiguration("cpu=atmegassss")
301301
require.Error(t, err, "generating cpu=atmegassss configuration")
302302

303303
_, err = boardUno.GeneratePropertiesForConfiguration("cpu=atmega1280")
304304
require.Error(t, err, "generating cpu=atmega1280 configuration")
305305

306-
expWatterott := properties.Map{
306+
expWatterott := properties.NewFromHashmap(map[string]string{
307307
"bootloader.extended_fuses": "0xFE",
308308
"bootloader.file": "micronucleus-t841.hex",
309309
"bootloader.high_fuses": "0xDD",
@@ -332,10 +332,10 @@ func TestBoardOptions(t *testing.T) {
332332
"upload.use_1200bps_touch": "false",
333333
"upload.wait_for_upload_port": "false",
334334
"vid.0": "0x16D0",
335-
}
335+
})
336336
confWatterott, err := boardWatterottTiny841.GeneratePropertiesForConfiguration("core=spencekonde,info=info")
337337
require.NoError(t, err, "generating core=spencekonde,info=info configuration")
338-
require.EqualValues(t, expWatterott, confWatterott, "generating core=spencekonde,info=info configuration")
338+
require.EqualValues(t, expWatterott.AsMap(), confWatterott.AsMap(), "generating core=spencekonde,info=info configuration")
339339

340340
// data, err := json.MarshalIndent(prop, "", " ")
341341
// require.NoError(t, err, "marshaling result")

arduino/cores/cores.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/arduino/go-paths-helper"
2424

2525
"github.com/arduino/arduino-cli/arduino/resources"
26-
"github.com/arduino/go-properties-map"
26+
"github.com/arduino/go-properties-orderedmap"
2727
"go.bug.st/relaxed-semver"
2828
)
2929

@@ -44,11 +44,11 @@ type PlatformRelease struct {
4444
Dependencies ToolDependencies // The Dependency entries to load tools.
4545
Platform *Platform `json:"-"`
4646

47-
Properties properties.Map `json:"-"`
48-
Boards map[string]*Board `json:"-"`
49-
Programmers map[string]properties.Map `json:"-"`
50-
Menus map[string]string `json:"-"`
51-
InstallDir *paths.Path `json:"-"`
47+
Properties *properties.Map `json:"-"`
48+
Boards map[string]*Board `json:"-"`
49+
Programmers map[string]*properties.Map `json:"-"`
50+
Menus *properties.Map `json:"-"`
51+
InstallDir *paths.Path `json:"-"`
5252
}
5353

5454
// BoardManifest contains information about a board. These metadata are usually
@@ -103,8 +103,8 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) (*Platform
103103
release := &PlatformRelease{
104104
Version: version,
105105
Boards: map[string]*Board{},
106-
Properties: properties.Map{},
107-
Programmers: map[string]properties.Map{},
106+
Properties: properties.NewMap(),
107+
Programmers: map[string]*properties.Map{},
108108
Platform: platform,
109109
}
110110
platform.Releases[tag] = release
@@ -177,7 +177,7 @@ func (release *PlatformRelease) GetOrCreateBoard(boardID string) *Board {
177177
}
178178
board := &Board{
179179
BoardID: boardID,
180-
Properties: properties.Map{},
180+
Properties: properties.NewMap(),
181181
PlatformRelease: release,
182182
}
183183
release.Boards[boardID] = board
@@ -198,10 +198,10 @@ func (release *PlatformRelease) RequiresToolRelease(toolRelease *ToolRelease) bo
198198
}
199199

200200
// RuntimeProperties returns the runtime properties for this PlatformRelease
201-
func (release *PlatformRelease) RuntimeProperties() properties.Map {
202-
return properties.Map{
203-
"runtime.platform.path": release.InstallDir.String(),
204-
}
201+
func (release *PlatformRelease) RuntimeProperties() *properties.Map {
202+
res := properties.NewMap()
203+
res.Set("runtime.platform.path", release.InstallDir.String())
204+
return res
205205
}
206206

207207
// GetLibrariesDir returns the path to the core libraries or nil if not

arduino/cores/fqbn.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@ package cores
1919

2020
import (
2121
"fmt"
22-
"sort"
2322
"strings"
2423

25-
properties "github.com/arduino/go-properties-map"
24+
properties "github.com/arduino/go-properties-orderedmap"
2625
)
2726

2827
// FQBN represents a Board with a specific configuration
2928
type FQBN struct {
3029
Package string
3130
PlatformArch string
3231
BoardID string
33-
Configs properties.Map
32+
Configs *properties.Map
3433
}
3534

3635
// ParseFQBN extract an FQBN object from the input string
@@ -45,12 +44,12 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
4544
Package: fqbnParts[0],
4645
PlatformArch: fqbnParts[1],
4746
BoardID: fqbnParts[2],
47+
Configs: properties.NewMap(),
4848
}
4949
if fqbn.BoardID == "" {
5050
return nil, fmt.Errorf("invalid fqbn: empty board identifier")
5151
}
5252
if len(fqbnParts) > 3 {
53-
fqbn.Configs = properties.Map{}
5453
for _, pair := range strings.Split(fqbnParts[3], ",") {
5554
parts := strings.SplitN(pair, "=", 2)
5655
if len(parts) != 2 {
@@ -61,20 +60,18 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
6160
if k == "" {
6261
return nil, fmt.Errorf("invalid fqbn config: %s", pair)
6362
}
64-
fqbn.Configs[k] = v
63+
fqbn.Configs.Set(k, v)
6564
}
6665
}
6766
return fqbn, nil
6867
}
6968

7069
func (fqbn *FQBN) String() string {
7170
res := fmt.Sprintf("%s:%s:%s", fqbn.Package, fqbn.PlatformArch, fqbn.BoardID)
72-
if fqbn.Configs != nil {
71+
if fqbn.Configs.Size() > 0 {
7372
sep := ":"
74-
keys := fqbn.Configs.Keys()
75-
sort.Strings(keys)
76-
for _, k := range keys {
77-
res += sep + k + "=" + fqbn.Configs[k]
73+
for _, k := range fqbn.Configs.Keys() {
74+
res += sep + k + "=" + fqbn.Configs.Get(k)
7875
sep = ","
7976
}
8077
}

0 commit comments

Comments
 (0)