Skip to content

Commit

Permalink
in case 2 unmangaed platform are found, pick the newest one
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Jan 2, 2024
1 parent 4c3a69f commit 8ebbaf2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ func (pme *Explorer) GetInstalledPlatformRelease(platform *cores.Platform) *core
for _, candidate := range releases[1:] {
candidateIsManaged := pme.IsManagedPlatformRelease(candidate)
debug("candidate", candidate)
if !candidateIsManaged && !bestIsManaged {
if candidate.Version.GreaterThan(best.Version) {
best = candidate
}
continue
}
if !candidateIsManaged {
continue
}
Expand Down
55 changes: 55 additions & 0 deletions internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/hex"
"fmt"
"os"
"path/filepath"
"runtime"
"sort"
"strconv"
Expand Down Expand Up @@ -518,6 +519,60 @@ func TestCoreListAllManuallyInstalledCore(t *testing.T) {
]}`)
}

func TestCoreListShowsLatestVersionWhenMultipleReleasesOfAManuallyInstalledCoreArePresent(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)

// Verifies only cores in board manager are shown
stdout, _, err := cli.Run("core", "list", "--all", "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, `.platforms | length > 0`, `true`)
length, err := strconv.Atoi(requirejson.Parse(t, stdout).Query(".platforms | length").String())
require.NoError(t, err)

// Manually installs a core in sketchbooks hardware folder
gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
_, err = git.PlainClone(filepath.Join(repoDir.String(), "1.8.3"), false, &git.CloneOptions{
URL: gitUrl,
ReferenceName: plumbing.NewTagReferenceName("1.8.3"),
})
require.NoError(t, err)

tmp := paths.New(t.TempDir(), "1.8.4")
_, err = git.PlainClone(tmp.String(), false, &git.CloneOptions{
URL: gitUrl,
ReferenceName: plumbing.NewTagReferenceName("1.8.4"),
})
require.NoError(t, err)

err = tmp.Rename(repoDir.Join("1.8.4"))
require.NoError(t, err)

// When manually installing 2 releases of the same core, the newest one takes precedence
stdout, _, err = cli.Run("core", "list", "--all", "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, `.platforms | length`, fmt.Sprint(length+1))
requirejson.Contains(t, stdout, `{"platforms":[
{
"id": "arduino-beta-development:avr",
"latest_version": "1.8.4",
"installed_version": "1.8.4",
"releases": {
"1.8.3": {
"name": "Arduino AVR Boards"
},
"1.8.3": {
"name": "Arduino AVR Boards"
}
}
}
]}`)
}

func TestCoreListUpdatableAllFlags(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
Expand Down

0 comments on commit 8ebbaf2

Please sign in to comment.