Skip to content

Commit f2bd18a

Browse files
committed
Fix issue with board listall
1 parent 68d37eb commit f2bd18a

File tree

4 files changed

+2733
-16
lines changed

4 files changed

+2733
-16
lines changed

arduino/cores/packageindex/index.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/arduino/arduino-cli/arduino/resources"
2424
"github.com/arduino/arduino-cli/arduino/security"
2525
"github.com/arduino/go-paths-helper"
26-
"github.com/arduino/go-properties-orderedmap"
2726
"github.com/sirupsen/logrus"
2827
semver "go.bug.st/relaxed-semver"
2928
)
@@ -87,10 +86,11 @@ type IndexToolReleaseFlavour struct {
8786
// IndexBoard represents a single Board as written in package_index.json file.
8887
type IndexBoard struct {
8988
Name string `json:"name"`
90-
ID []indexBoardID `json:"id,omitempty"`
89+
ID []IndexBoardID `json:"id,omitempty"`
9190
}
9291

93-
type indexBoardID struct {
92+
// IndexBoardID represents the ID of a single board. i.e. uno, yun, diecimila, micro and the likes
93+
type IndexBoardID struct {
9494
USB string `json:"usb"`
9595
}
9696

@@ -147,15 +147,6 @@ func (inPlatformRelease IndexPlatformRelease) extractPlatformIn(outPackage *core
147147
CachePath: "packages",
148148
}
149149
outPlatformRelease.Help = cores.PlatformReleaseHelp{Online: inPlatformRelease.Help.Online}
150-
outPlatformRelease.Boards = map[string]*cores.Board{}
151-
for _, board := range inPlatformRelease.Boards {
152-
outPlatformRelease.Boards[board.Name] = &cores.Board{
153-
Properties: properties.NewFromHashmap(map[string]string{
154-
"name": board.Name,
155-
}),
156-
PlatformRelease: outPlatformRelease,
157-
}
158-
}
159150
outPlatformRelease.BoardsManifest = inPlatformRelease.extractBoardsManifest()
160151
if deps, err := inPlatformRelease.extractDeps(); err == nil {
161152
outPlatformRelease.Dependencies = deps

arduino/cores/packagemanager/install_uninstall.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ func (pm *PackageManager) InstallPlatform(platformRelease *cores.PlatformRelease
5050

5151
func platformReleaseToIndex(pr *cores.PlatformRelease) packageindex.IndexPlatformRelease {
5252
boards := []packageindex.IndexBoard{}
53-
for name := range pr.Boards {
54-
boards = append(boards, packageindex.IndexBoard{
55-
Name: name,
56-
})
53+
for _, manifest := range pr.BoardsManifest {
54+
board := packageindex.IndexBoard{
55+
Name: manifest.Name,
56+
}
57+
for _, id := range manifest.ID {
58+
if id.USB != "" {
59+
board.ID = []packageindex.IndexBoardID{{USB: id.USB}}
60+
}
61+
}
62+
boards = append(boards, board)
5763
}
5864

5965
tools := []packageindex.IndexToolDependency{}

commands/board/listall_test.go

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package board
17+
18+
import (
19+
"context"
20+
"os"
21+
"testing"
22+
23+
"github.com/arduino/arduino-cli/cli/instance"
24+
"github.com/arduino/arduino-cli/cli/output"
25+
"github.com/arduino/arduino-cli/commands/core"
26+
"github.com/arduino/arduino-cli/configuration"
27+
rpc "github.com/arduino/arduino-cli/rpc/commands"
28+
"github.com/arduino/go-paths-helper"
29+
"github.com/stretchr/testify/require"
30+
)
31+
32+
func TestListAll(t *testing.T) {
33+
dataDir := paths.TempDir().Join("test", "data_dir")
34+
downloadDir := paths.TempDir().Join("test", "staging")
35+
os.Setenv("ARDUINO_DATA_DIR", dataDir.String())
36+
os.Setenv("ARDUINO_DOWNLOADS_DIR", downloadDir.String())
37+
dataDir.MkdirAll()
38+
downloadDir.MkdirAll()
39+
defer paths.TempDir().Join("test").RemoveAll()
40+
err := paths.New("testdata").Join("package_index.json").CopyTo(dataDir.Join("package_index.json"))
41+
require.Nil(t, err)
42+
43+
configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String())
44+
45+
inst, err := instance.CreateInstance()
46+
require.Nil(t, err)
47+
48+
_, err = core.PlatformInstall(context.Background(),
49+
&rpc.PlatformInstallReq{
50+
Instance: inst,
51+
PlatformPackage: "arduino",
52+
Architecture: "avr",
53+
Version: "1.8.3",
54+
SkipPostInstall: true,
55+
}, output.NewDownloadProgressBarCB(), output.NewTaskProgressCB())
56+
require.Nil(t, err)
57+
58+
res, err := ListAll(context.Background(), &rpc.BoardListAllReq{
59+
Instance: inst,
60+
SearchArgs: []string{},
61+
IncludeHiddenBoards: true,
62+
})
63+
require.Nil(t, err)
64+
require.NotNil(t, res)
65+
require.Equal(t, 26, len(res.Boards))
66+
require.Contains(t, res.Boards, &rpc.BoardListItem{
67+
Name: "Arduino Yún",
68+
FQBN: "arduino:avr:yun",
69+
IsHidden: false,
70+
})
71+
require.Contains(t, res.Boards, &rpc.BoardListItem{
72+
Name: "Arduino Uno",
73+
FQBN: "arduino:avr:uno",
74+
IsHidden: false,
75+
})
76+
require.Contains(t, res.Boards, &rpc.BoardListItem{
77+
Name: "Arduino Duemilanove or Diecimila",
78+
FQBN: "arduino:avr:diecimila",
79+
IsHidden: false,
80+
})
81+
require.Contains(t, res.Boards, &rpc.BoardListItem{
82+
Name: "Arduino Nano",
83+
FQBN: "arduino:avr:nano",
84+
IsHidden: false,
85+
})
86+
require.Contains(t, res.Boards, &rpc.BoardListItem{
87+
Name: "Arduino Mega or Mega 2560",
88+
FQBN: "arduino:avr:mega",
89+
IsHidden: false,
90+
})
91+
require.Contains(t, res.Boards, &rpc.BoardListItem{
92+
Name: "Arduino Mega ADK",
93+
FQBN: "arduino:avr:megaADK",
94+
IsHidden: false,
95+
})
96+
require.Contains(t, res.Boards, &rpc.BoardListItem{
97+
Name: "Arduino Leonardo",
98+
FQBN: "arduino:avr:leonardo",
99+
IsHidden: false,
100+
})
101+
require.Contains(t, res.Boards, &rpc.BoardListItem{
102+
Name: "Arduino Leonardo ETH",
103+
FQBN: "arduino:avr:leonardoeth",
104+
IsHidden: false,
105+
})
106+
require.Contains(t, res.Boards, &rpc.BoardListItem{
107+
Name: "Arduino Micro",
108+
FQBN: "arduino:avr:micro",
109+
IsHidden: false,
110+
})
111+
require.Contains(t, res.Boards, &rpc.BoardListItem{
112+
Name: "Arduino Esplora",
113+
FQBN: "arduino:avr:esplora",
114+
IsHidden: false,
115+
})
116+
require.Contains(t, res.Boards, &rpc.BoardListItem{
117+
Name: "Arduino Mini",
118+
FQBN: "arduino:avr:mini",
119+
IsHidden: false,
120+
})
121+
require.Contains(t, res.Boards, &rpc.BoardListItem{
122+
Name: "Arduino Ethernet",
123+
FQBN: "arduino:avr:ethernet",
124+
IsHidden: false,
125+
})
126+
require.Contains(t, res.Boards, &rpc.BoardListItem{
127+
Name: "Arduino Fio",
128+
FQBN: "arduino:avr:fio",
129+
IsHidden: false,
130+
})
131+
require.Contains(t, res.Boards, &rpc.BoardListItem{
132+
Name: "Arduino BT",
133+
FQBN: "arduino:avr:bt",
134+
IsHidden: false,
135+
})
136+
require.Contains(t, res.Boards, &rpc.BoardListItem{
137+
Name: "LilyPad Arduino USB",
138+
FQBN: "arduino:avr:LilyPadUSB",
139+
IsHidden: false,
140+
})
141+
require.Contains(t, res.Boards, &rpc.BoardListItem{
142+
Name: "LilyPad Arduino",
143+
FQBN: "arduino:avr:lilypad",
144+
IsHidden: false,
145+
})
146+
require.Contains(t, res.Boards, &rpc.BoardListItem{
147+
Name: "Arduino Pro or Pro Mini",
148+
FQBN: "arduino:avr:pro",
149+
IsHidden: false,
150+
})
151+
require.Contains(t, res.Boards, &rpc.BoardListItem{
152+
Name: "Arduino NG or older",
153+
FQBN: "arduino:avr:atmegang",
154+
IsHidden: false,
155+
})
156+
require.Contains(t, res.Boards, &rpc.BoardListItem{
157+
Name: "Arduino Robot Control",
158+
FQBN: "arduino:avr:robotControl",
159+
IsHidden: false,
160+
})
161+
require.Contains(t, res.Boards, &rpc.BoardListItem{
162+
Name: "Arduino Robot Motor",
163+
FQBN: "arduino:avr:robotMotor",
164+
IsHidden: false,
165+
})
166+
require.Contains(t, res.Boards, &rpc.BoardListItem{
167+
Name: "Arduino Gemma",
168+
FQBN: "arduino:avr:gemma",
169+
IsHidden: false,
170+
})
171+
require.Contains(t, res.Boards, &rpc.BoardListItem{
172+
Name: "Adafruit Circuit Playground",
173+
FQBN: "arduino:avr:circuitplay32u4cat",
174+
IsHidden: false,
175+
})
176+
require.Contains(t, res.Boards, &rpc.BoardListItem{
177+
Name: "Arduino Yún Mini",
178+
FQBN: "arduino:avr:yunmini",
179+
IsHidden: false,
180+
})
181+
require.Contains(t, res.Boards, &rpc.BoardListItem{
182+
Name: "Arduino Industrial 101",
183+
FQBN: "arduino:avr:chiwawa",
184+
IsHidden: false,
185+
})
186+
require.Contains(t, res.Boards, &rpc.BoardListItem{
187+
Name: "Linino One",
188+
FQBN: "arduino:avr:one",
189+
IsHidden: false,
190+
})
191+
require.Contains(t, res.Boards, &rpc.BoardListItem{
192+
Name: "Arduino Uno WiFi",
193+
FQBN: "arduino:avr:unowifi",
194+
IsHidden: false,
195+
})
196+
197+
}

0 commit comments

Comments
 (0)