Skip to content
2 changes: 1 addition & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
// Load libraries
for _, pack := range pme.GetPackages() {
for _, platform := range pack.Platforms {
if platformRelease := pme.GetInstalledPlatformRelease(platform); platformRelease != nil {
if platformRelease := pme.GetBestInstalledPlatformRelease(platform); platformRelease != nil {
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
PlatformRelease: platformRelease,
Path: platformRelease.GetLibrariesDir(),
Expand Down
2 changes: 1 addition & 1 deletion commands/service_board_listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *arduinoCoreServerImpl) BoardListAll(ctx context.Context, req *rpc.Board
list := &rpc.BoardListAllResponse{Boards: []*rpc.BoardListItem{}}
for _, targetPackage := range toSortedPackageArray(pme.GetPackages()) {
for _, platform := range toSortedPlatformArray(targetPackage.Platforms) {
installedPlatformRelease := pme.GetInstalledPlatformRelease(platform)
installedPlatformRelease := pme.GetBestInstalledPlatformRelease(platform)
// We only want to list boards for installed platforms
if installedPlatformRelease == nil {
continue
Expand Down
2 changes: 1 addition & 1 deletion commands/service_board_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS
for _, targetPackage := range pme.GetPackages() {
for _, platform := range targetPackage.Platforms {
latestPlatformRelease := platform.GetLatestCompatibleRelease()
installedPlatformRelease := pme.GetInstalledPlatformRelease(platform)
installedPlatformRelease := pme.GetBestInstalledPlatformRelease(platform)

if latestPlatformRelease == nil && installedPlatformRelease == nil {
continue
Expand Down
2 changes: 1 addition & 1 deletion commands/service_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetCommandLine(t *testing.T) {
sketchPath := paths.New("testdata", "debug", sketch)
require.NoError(t, sketchPath.ToAbs())

pmb := packagemanager.NewBuilder(nil, nil, nil, nil, nil, "test", downloader.GetDefaultConfig())
pmb := packagemanager.NewBuilder(nil, nil, customHardware, nil, nil, "test", downloader.GetDefaultConfig())
pmb.LoadHardwareFromDirectory(customHardware)
pmb.LoadHardwareFromDirectory(dataDir)

Expand Down
1 change: 1 addition & 0 deletions commands/service_platform_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest,
PlatformArchitecture: req.GetArchitecture(),
PlatformVersion: version,
}
fmt.Println(ref)
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref)
if err != nil {
return &cmderrors.PlatformNotFoundError{Platform: ref.String(), Cause: err}
Expand Down
5 changes: 4 additions & 1 deletion commands/service_platform_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
} else {
searchArgs := utils.SearchTermsFromQueryString(req.GetSearchArgs())
for _, targetPackage := range pme.GetPackages() {
for _, targetPackage := range pme.AllPackages() {
for _, platform := range targetPackage.Platforms {
if platform == nil {
continue
Expand Down Expand Up @@ -91,6 +91,9 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
rpcPlatformSummary.LatestVersion = latestCompatible.Version.String()
}
if _, has := platform.GetManuallyInstalledRelease(); has {
rpcPlatformSummary.HasManuallyInstalledRelease = true
}
for _, platformRelease := range platform.GetAllReleases() {
rpcPlatformRelease := platformReleaseToRPC(platformRelease)
rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease
Expand Down
2 changes: 1 addition & 1 deletion commands/service_platform_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func platformUninstall(_ context.Context, req *rpc.PlatformUninstallRequest, tas
if platform == nil {
return &cmderrors.PlatformNotFoundError{Platform: ref.String()}
}
platformRelease := pme.GetInstalledPlatformRelease(platform)
platformRelease := pme.GetBestInstalledPlatformRelease(platform)
if platformRelease == nil {
return &cmderrors.PlatformNotFoundError{Platform: ref.String()}
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (s *arduinoCoreServerImpl) runProgramAction(ctx context.Context, pme *packa
return nil, &cmderrors.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture}
}
uploadToolID = split[1]
uploadToolPlatform = pme.GetInstalledPlatformRelease(p)
uploadToolPlatform = pme.GetBestInstalledPlatformRelease(p)
if uploadToolPlatform == nil {
return nil, &cmderrors.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture}
}
Expand Down
8 changes: 5 additions & 3 deletions commands/service_upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
}

func TestUploadPropertiesComposition(t *testing.T) {
pmb := packagemanager.NewBuilder(nil, nil, nil, nil, nil, "test", downloader.GetDefaultConfig())
errs := pmb.LoadHardwareFromDirectory(paths.New("testdata", "upload", "hardware"))
userdir := paths.New("testdata", "upload")
hwdir := userdir.Join("hardware")
pmb := packagemanager.NewBuilder(nil, nil, hwdir, nil, nil, "test", downloader.GetDefaultConfig())
errs := pmb.LoadHardwareFromDirectory(hwdir)
require.Len(t, errs, 0)
buildPath1 := paths.New("testdata", "upload", "build_path_1")
buildPath1 := userdir.Join("build_path_1")
logrus.SetLevel(logrus.TraceLevel)
type test struct {
importDir *paths.Path
Expand Down
20 changes: 16 additions & 4 deletions internal/arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Platform struct {
Architecture string // The name of the architecture of this package.
Releases map[semver.NormalizedString]*PlatformRelease // The Releases of this platform, labeled by version.
Package *Package `json:"-"`
ManuallyInstalled bool // true if the Platform has been installed without the CLI
ManuallyInstalled bool // true if the Platform exists due to a manually installed release
Deprecated bool // true if the latest PlatformRelease of this Platform has been deprecated
Indexed bool // true if the Platform has been indexed from additional-urls
Latest *semver.Version `json:"-"`
Expand Down Expand Up @@ -117,6 +117,11 @@ func (t *TimestampsStore) Dirty() bool {
return false
}

// IsManaged returns true if the platform release is managed by the package manager.
func (release *PlatformRelease) IsManaged() bool {
return release.Version.String() != ""
}

// Dirty returns true if one of the files of this PlatformRelease has been changed
// (it means that the PlatformRelease should be rebuilt to be used correctly).
func (release *PlatformRelease) Dirty() bool {
Expand Down Expand Up @@ -238,10 +243,10 @@ func (d *MonitorDependency) String() string {
// GetOrCreateRelease returns the specified release corresponding the provided version,
// or creates a new one if not found.
func (platform *Platform) GetOrCreateRelease(version *semver.Version) *PlatformRelease {
var tag semver.NormalizedString
if version != nil {
tag = version.NormalizedString()
if version == nil {
version = semver.MustParse("")
}
tag := version.NormalizedString()
if release, ok := platform.Releases[tag]; ok {
return release
}
Expand All @@ -257,6 +262,13 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) *PlatformR
return release
}

// GetManuallyInstalledRelease returns (*PlatformRelease, true) if the Platform has
// a manually installed release or (nil, false) otherwise.
func (platform *Platform) GetManuallyInstalledRelease() (*PlatformRelease, bool) {
res, ok := platform.Releases[semver.MustParse("").NormalizedString()]
return res, ok
}

// FindReleaseWithVersion returns the specified release corresponding the provided version,
// or nil if not found.
func (platform *Platform) FindReleaseWithVersion(version *semver.Version) *PlatformRelease {
Expand Down
5 changes: 4 additions & 1 deletion internal/arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
outPlatform := outPackage.GetOrCreatePlatform(inPlatformRelease.Architecture)
// If the variable `isInstallJSON` is false it means that the index we're reading is coming from the additional-urls.
// Therefore, the `outPlatform.Indexed` will be set at `true`.
outPlatform.Indexed = outPlatform.Indexed || !isInstallJSON
if !isInstallJSON {
outPlatform.Indexed = true
outPlatform.ManuallyInstalled = false
}

// If the latest platform release is deprecated, then deprecate the whole platform.
if outPlatform.Latest == nil || outPlatform.Latest.LessThan(inPlatformRelease.Version) {
Expand Down
21 changes: 2 additions & 19 deletions internal/arduino/cores/packagemanager/install_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,6 @@ func (pme *Explorer) RunPreOrPostScript(installDir *paths.Path, prefix string) (
return []byte{}, []byte{}, nil
}

// IsManagedPlatformRelease returns true if the PlatforRelease is managed by the PackageManager
func (pme *Explorer) IsManagedPlatformRelease(platformRelease *cores.PlatformRelease) bool {
if pme.PackagesDir == nil {
return false
}
installDir := platformRelease.InstallDir.Clone()
if installDir.FollowSymLink() != nil {
return false
}
packagesDir := pme.PackagesDir.Clone()
if packagesDir.FollowSymLink() != nil {
return false
}
managed, _ := installDir.IsInsideDir(packagesDir)
return managed
}

// UninstallPlatform remove a PlatformRelease.
func (pme *Explorer) UninstallPlatform(platformRelease *cores.PlatformRelease, taskCB rpc.TaskProgressCB, skipPreUninstall bool) error {
log := pme.log.WithField("platform", platformRelease)
Expand All @@ -288,7 +271,7 @@ func (pme *Explorer) UninstallPlatform(platformRelease *cores.PlatformRelease, t
}

// Safety measure
if !pme.IsManagedPlatformRelease(platformRelease) {
if !platformRelease.IsManaged() {
err := errors.New(i18n.Tr("%s is not managed by package manager", platformRelease))
log.WithError(err).Error("Error uninstalling")
return &cmderrors.FailedUninstallError{Message: err.Error()}
Expand Down Expand Up @@ -441,7 +424,7 @@ func (pme *Explorer) IsToolRequired(toolRelease *cores.ToolRelease) bool {
// Search in all installed platforms
for _, targetPackage := range pme.packages {
for _, platform := range targetPackage.Platforms {
if platformRelease := pme.GetInstalledPlatformRelease(platform); platformRelease != nil {
if platformRelease := pme.GetBestInstalledPlatformRelease(platform); platformRelease != nil {
if platformRelease.RequiresToolRelease(toolRelease) {
return true
}
Expand Down
Loading