Skip to content

Commit c1967a7

Browse files
committed
Board identification function do not require a full Port but just the properties
1 parent 7782c89 commit c1967a7

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

commands/service_board_list.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/arduino/arduino-cli/pkg/fqbn"
3838
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3939
"github.com/arduino/go-properties-orderedmap"
40-
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
4140
"github.com/sirupsen/logrus"
4241
)
4342

@@ -139,20 +138,20 @@ func identifyViaCloudAPI(props *properties.Map, settings *configuration.Settings
139138
}
140139

141140
// identify returns a list of boards checking first the installed platforms or the Cloud API
142-
func identify(pme *packagemanager.Explorer, port *discovery.Port, settings *configuration.Settings, skipCloudAPI bool) ([]*rpc.BoardListItem, error) {
143-
boards := []*rpc.BoardListItem{}
144-
if port.Properties == nil {
145-
return boards, nil
141+
func identify(pme *packagemanager.Explorer, properties *properties.Map, settings *configuration.Settings, skipCloudAPI bool) ([]*rpc.BoardListItem, error) {
142+
if properties == nil {
143+
return nil, nil
146144
}
147145

148146
// first query installed cores through the Package Manager
147+
boards := []*rpc.BoardListItem{}
149148
logrus.Debug("Querying installed cores for board identification...")
150-
for _, board := range pme.IdentifyBoard(port.Properties) {
149+
for _, board := range pme.IdentifyBoard(properties) {
151150
fqbn, err := fqbn.Parse(board.FQBN())
152151
if err != nil {
153152
return nil, &cmderrors.InvalidFQBNError{Cause: err}
154153
}
155-
fqbn.Configs = board.IdentifyBoardConfiguration(port.Properties)
154+
fqbn.Configs = board.IdentifyBoardConfiguration(properties)
156155

157156
// We need the Platform maintaner for sorting so we set it here
158157
platform := &rpc.Platform{
@@ -171,7 +170,7 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port, settings *conf
171170
// if installed cores didn't recognize the board, try querying
172171
// the builder API if the board is a USB device port
173172
if len(boards) == 0 && !skipCloudAPI && !settings.SkipCloudApiForBoardDetection() {
174-
items, err := identifyViaCloudAPI(port.Properties, settings)
173+
items, err := identifyViaCloudAPI(properties, settings)
175174
if err != nil {
176175
// this is bad, but keep going
177176
logrus.WithError(err).Debug("Error querying builder API")
@@ -225,7 +224,7 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
225224

226225
ports := []*rpc.DetectedPort{}
227226
for _, port := range dm.List() {
228-
boards, err := identify(pme, port, s.settings, req.GetSkipCloudApiForBoardDetection())
227+
boards, err := identify(pme, port.Properties, s.settings, req.GetSkipCloudApiForBoardDetection())
229228
if err != nil {
230229
warnings = append(warnings, err.Error())
231230
}
@@ -298,7 +297,7 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
298297

299298
boardsError := ""
300299
if event.Type == "add" {
301-
boards, err := identify(pme, event.Port, s.settings, req.GetSkipCloudApiForBoardDetection())
300+
boards, err := identify(pme, event.Port.Properties, s.settings, req.GetSkipCloudApiForBoardDetection())
302301
if err != nil {
303302
boardsError = err.Error()
304303
}

commands/service_board_list_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/arduino/arduino-cli/internal/cli/configuration"
2626
"github.com/arduino/go-paths-helper"
2727
"github.com/arduino/go-properties-orderedmap"
28-
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
2928
"github.com/stretchr/testify/require"
3029
"go.bug.st/downloader/v2"
3130
semver "go.bug.st/relaxed-semver"
@@ -157,7 +156,7 @@ func TestBoardIdentifySorting(t *testing.T) {
157156
defer release()
158157

159158
settings := configuration.NewSettings()
160-
res, err := identify(pme, &discovery.Port{Properties: idPrefs}, settings, true)
159+
res, err := identify(pme, idPrefs, settings, true)
161160
require.NoError(t, err)
162161
require.NotNil(t, res)
163162
require.Len(t, res, 4)

0 commit comments

Comments
 (0)