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
Next Next commit
Change FindPlatform's signature to avoid references to the Package Ma…
…nager
  • Loading branch information
MatteoPologruto committed Sep 20, 2023
commit f99145e752f1b7f9dae9d43476c19ddbcff0a1a6
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(ref *PlatformReference) *cores.Platform {
targetPackage, ok := pme.packages[ref.Package]
func (pme *Explorer) FindPlatform(platformPackage, platformArchitecture string) *cores.Platform {
targetPackage, ok := pme.packages[platformPackage]
if !ok {
return nil
}
platform, ok := targetPackage.Platforms[ref.PlatformArchitecture]
platform, ok := targetPackage.Platforms[platformArchitecture]
if !ok {
return nil
}
Expand All @@ -57,7 +57,7 @@ func (pme *Explorer) FindPlatform(ref *PlatformReference) *cores.Platform {

// FindPlatformRelease returns the PlatformRelease matching the PlatformReference or nil if not found
func (pme *Explorer) FindPlatformRelease(ref *PlatformReference) *cores.PlatformRelease {
platform := pme.FindPlatform(ref)
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
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)
platform := pme.FindPlatform(platformRef.Package, platformRef.PlatformArchitecture)
if platform == nil {
return nil, &arduino.PlatformNotFoundError{Platform: platformRef.String()}
}
Expand Down
5 changes: 1 addition & 4 deletions arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ func TestBoardOrdering(t *testing.T) {
pme, release := pm.NewExplorer()
defer release()

pl := pme.FindPlatform(&PlatformReference{
Package: "arduino",
PlatformArchitecture: "avr",
})
pl := pme.FindPlatform("arduino", "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)
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
if platform == nil {
return &arduino.PlatformNotFoundError{Platform: ref.String()}
}
Expand Down
5 changes: 1 addition & 4 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ 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(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: boardPlatform.Platform.Architecture,
})
p := pme.FindPlatform(split[0], boardPlatform.Platform.Architecture)
if p == nil {
return nil, &arduino.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture}
}
Expand Down
7 changes: 1 addition & 6 deletions internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"strings"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/commands/sketch"
Expand Down Expand Up @@ -363,12 +362,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
panic(tr("Platform ID is not correct"))
}

// FIXME: Here we should not access PackageManager...
pme, release := commands.GetPackageManagerExplorer(compileRequest)
platform := pme.FindPlatform(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: split[1],
})
platform := pme.FindPlatform(split[0], split[1])
release()

if profileArg.String() == "" {
Expand Down
7 changes: 1 addition & 6 deletions internal/cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"

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

// FIXME: Here we must not access package manager...
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
platform := pme.FindPlatform(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: split[1],
})
platform := pme.FindPlatform(split[0], split[1])
release()

msg += "\n"
Expand Down