Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Replace direct access to the package manager with a call to PlatformS…
…earch function
  • Loading branch information
MatteoPologruto committed Sep 20, 2023
commit 11326b5352c759e5b975d3d1fffb397404e01988
8 changes: 4 additions & 4 deletions arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func (platform *PlatformReference) String() string {

// FindPlatform returns the Platform matching the PlatformReference or nil if not found.
// The PlatformVersion field of the reference is ignored.
func (pme *Explorer) FindPlatform(platformPackage, platformArchitecture string) *cores.Platform {
targetPackage, ok := pme.packages[platformPackage]
func (pme *Explorer) FindPlatform(ref *PlatformReference) *cores.Platform {
targetPackage, ok := pme.packages[ref.Package]
if !ok {
return nil
}
platform, ok := targetPackage.Platforms[platformArchitecture]
platform, ok := targetPackage.Platforms[ref.PlatformArchitecture]
if !ok {
return nil
}
Expand All @@ -57,7 +57,7 @@ func (pme *Explorer) FindPlatform(platformPackage, platformArchitecture string)

// FindPlatformRelease returns the PlatformRelease matching the PlatformReference or nil if not found
func (pme *Explorer) FindPlatformRelease(ref *PlatformReference) *cores.PlatformRelease {
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
platform := pme.FindPlatform(ref)
if platform == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/install_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (pme *Explorer) DownloadAndInstallPlatformUpgrades(
}

// Search the latest version for all specified platforms
platform := pme.FindPlatform(platformRef.Package, platformRef.PlatformArchitecture)
platform := pme.FindPlatform(platformRef)
if platform == nil {
return nil, &arduino.PlatformNotFoundError{Platform: platformRef.String()}
}
Expand Down
5 changes: 4 additions & 1 deletion arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ func TestBoardOrdering(t *testing.T) {
pme, release := pm.NewExplorer()
defer release()

pl := pme.FindPlatform("arduino", "avr")
pl := pme.FindPlatform(&PlatformReference{
Package: "arduino",
PlatformArchitecture: "avr",
})
require.NotNil(t, pl)
plReleases := pl.GetAllInstalled()
require.NotEmpty(t, plReleases)
Expand Down
2 changes: 1 addition & 1 deletion commands/core/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
PlatformArchitecture: req.Architecture,
}
if ref.PlatformVersion == nil {
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
platform := pme.FindPlatform(ref)
if platform == nil {
return &arduino.PlatformNotFoundError{Platform: ref.String()}
}
Expand Down
5 changes: 4 additions & 1 deletion commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ func runProgramAction(pme *packagemanager.Explorer,
Property: fmt.Sprintf("%s.tool.%s", action, port.Protocol), // TODO: Can be done better, maybe inline getToolID(...)
Value: uploadToolID}
} else if len(split) == 2 {
p := pme.FindPlatform(split[0], boardPlatform.Platform.Architecture)
p := pme.FindPlatform(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: boardPlatform.Platform.Architecture,
})
if p == nil {
return nil, &arduino.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture}
}
Expand Down
15 changes: 9 additions & 6 deletions internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strings"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/configuration"
Expand Down Expand Up @@ -362,13 +362,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
panic(tr("Platform ID is not correct"))
}

pme, release := commands.GetPackageManagerExplorer(compileRequest)
platform := pme.FindPlatform(split[0], split[1])
release()

if profileArg.String() == "" {
res.Error += fmt.Sprintln()
if platform != nil {

if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
Instance: inst,
SearchArgs: platformErr.Platform,
AllVersions: false,
}); err != nil {
res.Error += err.Error()
} else if len(platform.GetSearchOutput()) > 0 {
suggestion := fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform)
res.Error += tr("Try running %s", suggestion)
} else {
Expand Down
14 changes: 8 additions & 6 deletions internal/cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"strings"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/core"
sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/i18n"
Expand Down Expand Up @@ -129,12 +129,14 @@ func runUploadCommand(command *cobra.Command, args []string) {
panic(tr("Platform ID is not correct"))
}

pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
platform := pme.FindPlatform(split[0], split[1])
release()

msg += "\n"
if platform != nil {
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
Instance: inst,
SearchArgs: platformErr.Platform,
AllVersions: false,
}); err != nil {
msg += err.Error()
} else if len(platform.GetSearchOutput()) > 0 {
msg += tr("Try running %s", fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform))
} else {
msg += tr("Platform %s is not found in any known index\nMaybe you need to add a 3rd party URL?", platformErr.Platform)
Expand Down