Skip to content

Commit 11326b5

Browse files
Replace direct access to the package manager with a call to PlatformSearch function
1 parent f99145e commit 11326b5

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

Diff for: arduino/cores/packagemanager/download.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func (platform *PlatformReference) String() string {
4343

4444
// FindPlatform returns the Platform matching the PlatformReference or nil if not found.
4545
// The PlatformVersion field of the reference is ignored.
46-
func (pme *Explorer) FindPlatform(platformPackage, platformArchitecture string) *cores.Platform {
47-
targetPackage, ok := pme.packages[platformPackage]
46+
func (pme *Explorer) FindPlatform(ref *PlatformReference) *cores.Platform {
47+
targetPackage, ok := pme.packages[ref.Package]
4848
if !ok {
4949
return nil
5050
}
51-
platform, ok := targetPackage.Platforms[platformArchitecture]
51+
platform, ok := targetPackage.Platforms[ref.PlatformArchitecture]
5252
if !ok {
5353
return nil
5454
}
@@ -57,7 +57,7 @@ func (pme *Explorer) FindPlatform(platformPackage, platformArchitecture string)
5757

5858
// FindPlatformRelease returns the PlatformRelease matching the PlatformReference or nil if not found
5959
func (pme *Explorer) FindPlatformRelease(ref *PlatformReference) *cores.PlatformRelease {
60-
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
60+
platform := pme.FindPlatform(ref)
6161
if platform == nil {
6262
return nil
6363
}

Diff for: arduino/cores/packagemanager/install_uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (pme *Explorer) DownloadAndInstallPlatformUpgrades(
4545
}
4646

4747
// Search the latest version for all specified platforms
48-
platform := pme.FindPlatform(platformRef.Package, platformRef.PlatformArchitecture)
48+
platform := pme.FindPlatform(platformRef)
4949
if platform == nil {
5050
return nil, &arduino.PlatformNotFoundError{Platform: platformRef.String()}
5151
}

Diff for: arduino/cores/packagemanager/package_manager_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ func TestBoardOrdering(t *testing.T) {
387387
pme, release := pm.NewExplorer()
388388
defer release()
389389

390-
pl := pme.FindPlatform("arduino", "avr")
390+
pl := pme.FindPlatform(&PlatformReference{
391+
Package: "arduino",
392+
PlatformArchitecture: "avr",
393+
})
391394
require.NotNil(t, pl)
392395
plReleases := pl.GetAllInstalled()
393396
require.NotEmpty(t, plReleases)

Diff for: commands/core/uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
4848
PlatformArchitecture: req.Architecture,
4949
}
5050
if ref.PlatformVersion == nil {
51-
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
51+
platform := pme.FindPlatform(ref)
5252
if platform == nil {
5353
return &arduino.PlatformNotFoundError{Platform: ref.String()}
5454
}

Diff for: commands/upload/upload.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ func runProgramAction(pme *packagemanager.Explorer,
285285
Property: fmt.Sprintf("%s.tool.%s", action, port.Protocol), // TODO: Can be done better, maybe inline getToolID(...)
286286
Value: uploadToolID}
287287
} else if len(split) == 2 {
288-
p := pme.FindPlatform(split[0], boardPlatform.Platform.Architecture)
288+
p := pme.FindPlatform(&packagemanager.PlatformReference{
289+
Package: split[0],
290+
PlatformArchitecture: boardPlatform.Platform.Architecture,
291+
})
289292
if p == nil {
290293
return nil, &arduino.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture}
291294
}

Diff for: internal/cli/compile/compile.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
"strings"
2626

2727
"github.com/arduino/arduino-cli/arduino"
28-
"github.com/arduino/arduino-cli/commands"
2928
"github.com/arduino/arduino-cli/commands/compile"
29+
"github.com/arduino/arduino-cli/commands/core"
3030
"github.com/arduino/arduino-cli/commands/sketch"
3131
"github.com/arduino/arduino-cli/commands/upload"
3232
"github.com/arduino/arduino-cli/configuration"
@@ -362,13 +362,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
362362
panic(tr("Platform ID is not correct"))
363363
}
364364

365-
pme, release := commands.GetPackageManagerExplorer(compileRequest)
366-
platform := pme.FindPlatform(split[0], split[1])
367-
release()
368-
369365
if profileArg.String() == "" {
370366
res.Error += fmt.Sprintln()
371-
if platform != nil {
367+
368+
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
369+
Instance: inst,
370+
SearchArgs: platformErr.Platform,
371+
AllVersions: false,
372+
}); err != nil {
373+
res.Error += err.Error()
374+
} else if len(platform.GetSearchOutput()) > 0 {
372375
suggestion := fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform)
373376
res.Error += tr("Try running %s", suggestion)
374377
} else {

Diff for: internal/cli/upload/upload.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/arduino/arduino-cli/arduino"
26-
"github.com/arduino/arduino-cli/commands"
26+
"github.com/arduino/arduino-cli/commands/core"
2727
sk "github.com/arduino/arduino-cli/commands/sketch"
2828
"github.com/arduino/arduino-cli/commands/upload"
2929
"github.com/arduino/arduino-cli/i18n"
@@ -129,12 +129,14 @@ func runUploadCommand(command *cobra.Command, args []string) {
129129
panic(tr("Platform ID is not correct"))
130130
}
131131

132-
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
133-
platform := pme.FindPlatform(split[0], split[1])
134-
release()
135-
136132
msg += "\n"
137-
if platform != nil {
133+
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
134+
Instance: inst,
135+
SearchArgs: platformErr.Platform,
136+
AllVersions: false,
137+
}); err != nil {
138+
msg += err.Error()
139+
} else if len(platform.GetSearchOutput()) > 0 {
138140
msg += tr("Try running %s", fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform))
139141
} else {
140142
msg += tr("Platform %s is not found in any known index\nMaybe you need to add a 3rd party URL?", platformErr.Platform)

0 commit comments

Comments
 (0)