Commit df7a4781 authored by Cristian Maglie's avatar Cristian Maglie

First implementation of 'core upgrade'

parent aead8c8d
......@@ -369,6 +369,32 @@ func TestCoreCommands(t *testing.T) {
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "arduino:avr")
// Upgrade platform
exitCode, d = executeWithArgs(t, "core", "upgrade", "arduino:avr@1.6.17")
require.NotZero(t, exitCode, "exit code")
require.Contains(t, string(d), "Invalid item arduino:avr@1.6.17")
exitCode, d = executeWithArgs(t, "core", "upgrade", "other:avr")
require.NotZero(t, exitCode, "exit code")
require.Contains(t, string(d), "other:avr not found")
exitCode, d = executeWithArgs(t, "core", "upgrade", "arduino:samd")
require.NotZero(t, exitCode, "exit code")
require.Contains(t, string(d), "arduino:samd is not installed")
exitCode, d = executeWithArgs(t, "core", "upgrade", "arduino:avr")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Updating arduino:avr@1.6.16 with "+AVR)
// List updatable cores
exitCode, d = executeWithArgs(t, "core", "list", "--updatable")
require.Zero(t, exitCode, "exit code")
require.NotContains(t, string(d), "arduino:avr")
exitCode, d = executeWithArgs(t, "core", "list")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "arduino:avr")
// Build sketch for arduino:avr:uno
exitCode, d = executeWithArgs(t, "sketch", "new", "Test1")
require.Zero(t, exitCode, "exit code")
......@@ -381,7 +407,7 @@ func TestCoreCommands(t *testing.T) {
// Uninstall arduino:avr
exitCode, d = executeWithArgs(t, "core", "uninstall", "arduino:avr")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "arduino:avr@1.6.16 uninstalled")
require.Contains(t, string(d), AVR+" uninstalled")
// Empty cores list
exitCode, d = executeWithArgs(t, "core", "list")
......
......@@ -52,6 +52,8 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
downloadPlatformByRef(pm, platformRef)
installPlatformByRef(pm, platformRef)
}
// TODO: Cleanup unused tools
}
func installPlatformByRef(pm *packagemanager.PackageManager, platformRef *packagemanager.PlatformReference) {
......@@ -61,6 +63,10 @@ func installPlatformByRef(pm *packagemanager.PackageManager, platformRef *packag
os.Exit(commands.ErrBadCall)
}
// TODO: Check install prerequisites here
// TODO: Download here
for _, tool := range tools {
InstallToolRelease(pm, tool)
}
......@@ -70,8 +76,15 @@ func installPlatformByRef(pm *packagemanager.PackageManager, platformRef *packag
func installPlatformRelease(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease) {
log := pm.Log.WithField("platform", platformRelease)
platform := platformRelease.Platform
installed := platform.GetInstalled()
if installed == nil {
log.Info("Installing platform")
formatter.Print("Installing " + platformRelease.String() + "...")
} else {
log.Info("Updating platform " + installed.String())
formatter.Print("Updating " + installed.String() + " with " + platformRelease.String() + "...")
}
err := pm.InstallPlatform(platformRelease)
if os.IsExist(err) {
......@@ -84,6 +97,24 @@ func installPlatformRelease(pm *packagemanager.PackageManager, platformRelease *
os.Exit(commands.ErrGeneric)
}
// If upgrading remove previous release
if installed != nil {
err := pm.UninstallPlatform(installed)
// In case of error try to rollback
if err != nil {
log.WithError(err).Error("Error updating platform.")
formatter.PrintError(err, "Error updating platform")
// Rollback
if err := pm.UninstallPlatform(platformRelease); err != nil {
log.WithError(err).Error("Error rolling-back changes.")
formatter.PrintError(err, "Error rolling-back changes.")
}
os.Exit(commands.ErrGeneric)
}
}
log.Info("Platform installed")
formatter.Print(platformRelease.String() + " installed")
}
......
......@@ -18,7 +18,6 @@
package core
import (
"fmt"
"os"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
......@@ -112,8 +111,7 @@ func upgrade(pm *packagemanager.PackageManager, platformsRefs []*packagemanager.
}
for _, platformRef := range toInstallRefs {
fmt.Printf("Upgrading %s\n", platformRef)
// downloadPlatformByRef(pm, platformRef)
// installPlatformByRef(pm, platformRef)
downloadPlatformByRef(pm, platformRef)
installPlatformByRef(pm, platformRef)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment