From 8ebbaf2890a089d843a4180b6f247614db6e92a2 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Fri, 22 Dec 2023 10:18:31 +0100 Subject: [PATCH] in case 2 unmangaed platform are found, pick the newest one --- .../cores/packagemanager/package_manager.go | 6 ++ internal/integrationtest/core/core_test.go | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/internal/arduino/cores/packagemanager/package_manager.go b/internal/arduino/cores/packagemanager/package_manager.go index 77e10a3a057..d40fa6312f3 100644 --- a/internal/arduino/cores/packagemanager/package_manager.go +++ b/internal/arduino/cores/packagemanager/package_manager.go @@ -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 } diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index e8b7c4ad3be..da740e54bea 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -20,6 +20,7 @@ import ( "encoding/hex" "fmt" "os" + "path/filepath" "runtime" "sort" "strconv" @@ -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()