Skip to content

Commit f7b3c30

Browse files
Change FindPlatform's signature to avoid references to the Package Manager
1 parent 8e048b0 commit f7b3c30

File tree

7 files changed

+10
-26
lines changed

7 files changed

+10
-26
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(ref *PlatformReference) *cores.Platform {
47-
targetPackage, ok := pme.packages[ref.Package]
46+
func (pme *Explorer) FindPlatform(platformPackage, platformArchitecture string) *cores.Platform {
47+
targetPackage, ok := pme.packages[platformPackage]
4848
if !ok {
4949
return nil
5050
}
51-
platform, ok := targetPackage.Platforms[ref.PlatformArchitecture]
51+
platform, ok := targetPackage.Platforms[platformArchitecture]
5252
if !ok {
5353
return nil
5454
}
@@ -57,7 +57,7 @@ func (pme *Explorer) FindPlatform(ref *PlatformReference) *cores.Platform {
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)
60+
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
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
@@ -44,7 +44,7 @@ func (pme *Explorer) DownloadAndInstallPlatformUpgrades(
4444
}
4545

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

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

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

390-
pl := pme.FindPlatform(&PlatformReference{
391-
Package: "arduino",
392-
PlatformArchitecture: "avr",
393-
})
390+
pl := pme.FindPlatform("arduino", "avr")
394391
require.NotNil(t, pl)
395392
plReleases := pl.GetAllInstalled()
396393
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)
51+
platform := pme.FindPlatform(ref.Package, ref.PlatformArchitecture)
5252
if platform == nil {
5353
return &arduino.PlatformNotFoundError{Platform: ref.String()}
5454
}

Diff for: commands/upload/upload.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ 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(&packagemanager.PlatformReference{
289-
Package: split[0],
290-
PlatformArchitecture: boardPlatform.Platform.Architecture,
291-
})
288+
p := pme.FindPlatform(split[0], boardPlatform.Platform.Architecture)
292289
if p == nil {
293290
return nil, &arduino.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture}
294291
}

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

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

2727
"github.com/arduino/arduino-cli/arduino"
28-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2928
"github.com/arduino/arduino-cli/commands"
3029
"github.com/arduino/arduino-cli/commands/compile"
3130
"github.com/arduino/arduino-cli/commands/sketch"
@@ -363,12 +362,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
363362
panic(tr("Platform ID is not correct"))
364363
}
365364

366-
// FIXME: Here we should not access PackageManager...
367365
pme, release := commands.GetPackageManagerExplorer(compileRequest)
368-
platform := pme.FindPlatform(&packagemanager.PlatformReference{
369-
Package: split[0],
370-
PlatformArchitecture: split[1],
371-
})
366+
platform := pme.FindPlatform(split[0], split[1])
372367
release()
373368

374369
if profileArg.String() == "" {

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

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

2525
"github.com/arduino/arduino-cli/arduino"
26-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2726
"github.com/arduino/arduino-cli/commands"
2827
sk "github.com/arduino/arduino-cli/commands/sketch"
2928
"github.com/arduino/arduino-cli/commands/upload"
@@ -130,12 +129,8 @@ func runUploadCommand(command *cobra.Command, args []string) {
130129
panic(tr("Platform ID is not correct"))
131130
}
132131

133-
// FIXME: Here we must not access package manager...
134132
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
135-
platform := pme.FindPlatform(&packagemanager.PlatformReference{
136-
Package: split[0],
137-
PlatformArchitecture: split[1],
138-
})
133+
platform := pme.FindPlatform(split[0], split[1])
139134
release()
140135

141136
msg += "\n"

0 commit comments

Comments
 (0)