@@ -17,7 +17,6 @@ package commands
1717
1818import (
1919 "context"
20- "errors"
2120 "fmt"
2221 "net/url"
2322 "os"
@@ -28,7 +27,6 @@ import (
2827 "github.com/arduino/arduino-cli/arduino/cores/packageindex"
2928 "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
3029 "github.com/arduino/arduino-cli/arduino/globals"
31- "github.com/arduino/arduino-cli/arduino/httpclient"
3230 "github.com/arduino/arduino-cli/arduino/libraries"
3331 "github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
3432 "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
@@ -641,188 +639,6 @@ func getOutputRelease(lib *librariesindex.Release) *rpc.LibraryRelease {
641639 return & rpc.LibraryRelease {}
642640}
643641
644- // Upgrade downloads and installs outdated Cores and Libraries
645- func Upgrade (ctx context.Context , req * rpc.UpgradeRequest , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) error {
646- downloaderConfig , err := httpclient .GetDownloaderConfig ()
647- if err != nil {
648- return err
649- }
650-
651- lm := GetLibraryManager (req .Instance .Id )
652- if lm == nil {
653- return & arduino.InvalidInstanceError {}
654- }
655-
656- for _ , libAlternatives := range lm .Libraries {
657- for _ , library := range libAlternatives .Alternatives {
658- if library .Location != libraries .User {
659- continue
660- }
661- available := lm .Index .FindLibraryUpdate (library )
662- if available == nil {
663- continue
664- }
665-
666- // Downloads latest library release
667- taskCB (& rpc.TaskProgress {Name : tr ("Downloading %s" , available )})
668- if err := available .Resource .Download (lm .DownloadsDir , downloaderConfig , available .String (), downloadCB ); err != nil {
669- return & arduino.FailedDownloadError {Message : tr ("Error downloading library" ), Cause : err }
670- }
671-
672- // Installs downloaded library
673- taskCB (& rpc.TaskProgress {Name : tr ("Installing %s" , available )})
674- libPath , libReplaced , err := lm .InstallPrerequisiteCheck (available )
675- if errors .Is (err , librariesmanager .ErrAlreadyInstalled ) {
676- taskCB (& rpc.TaskProgress {Message : tr ("Already installed %s" , available ), Completed : true })
677- continue
678- } else if err != nil {
679- return & arduino.FailedLibraryInstallError {Cause : err }
680- }
681-
682- if libReplaced != nil {
683- taskCB (& rpc.TaskProgress {Message : tr ("Replacing %[1]s with %[2]s" , libReplaced , available )})
684- }
685-
686- if err := lm .Install (available , libPath ); err != nil {
687- return & arduino.FailedLibraryInstallError {Cause : err }
688- }
689-
690- taskCB (& rpc.TaskProgress {Message : tr ("Installed %s" , available ), Completed : true })
691- }
692- }
693-
694- pm := GetPackageManager (req .Instance .Id )
695- if pm == nil {
696- return & arduino.InvalidInstanceError {}
697- }
698-
699- for _ , targetPackage := range pm .Packages {
700- for _ , installed := range targetPackage .Platforms {
701- if installedRelease := pm .GetInstalledPlatformRelease (installed ); installedRelease != nil {
702- latest := installed .GetLatestRelease ()
703- if latest == nil || latest == installedRelease {
704- continue
705- }
706-
707- ref := & packagemanager.PlatformReference {
708- Package : installedRelease .Platform .Package .Name ,
709- PlatformArchitecture : installedRelease .Platform .Architecture ,
710- PlatformVersion : installedRelease .Version ,
711- }
712- // Get list of installed tools needed by the currently installed version
713- _ , installedTools , err := pm .FindPlatformReleaseDependencies (ref )
714- if err != nil {
715- return & arduino.NotFoundError {Message : tr ("Can't find dependencies for platform %s" , ref ), Cause : err }
716- }
717-
718- ref = & packagemanager.PlatformReference {
719- Package : latest .Platform .Package .Name ,
720- PlatformArchitecture : latest .Platform .Architecture ,
721- PlatformVersion : latest .Version ,
722- }
723-
724- taskCB (& rpc.TaskProgress {Name : tr ("Downloading %s" , latest )})
725- _ , tools , err := pm .FindPlatformReleaseDependencies (ref )
726- if err != nil {
727- return & arduino.NotFoundError {Message : tr ("Can't find dependencies for platform %s" , ref ), Cause : err }
728- }
729-
730- toolsToInstall := []* cores.ToolRelease {}
731- for _ , tool := range tools {
732- if tool .IsInstalled () {
733- logrus .WithField ("tool" , tool ).Warn ("Tool already installed" )
734- taskCB (& rpc.TaskProgress {Name : tr ("Tool %s already installed" , tool ), Completed : true })
735- } else {
736- toolsToInstall = append (toolsToInstall , tool )
737- }
738- }
739-
740- // Downloads platform tools
741- for _ , tool := range toolsToInstall {
742- if err := pm .DownloadToolRelease (tool , nil , downloadCB ); err != nil {
743- taskCB (& rpc.TaskProgress {Message : tr ("Error downloading tool %s" , tool )})
744- return & arduino.FailedDownloadError {Message : tr ("Error downloading tool %s" , tool ), Cause : err }
745- }
746- }
747-
748- // Downloads platform
749- if err := pm .DownloadPlatformRelease (latest , downloaderConfig , downloadCB ); err != nil {
750- return & arduino.FailedDownloadError {Message : tr ("Error downloading platform %s" , latest ), Cause : err }
751- }
752-
753- logrus .Info ("Updating platform " + installed .String ())
754- taskCB (& rpc.TaskProgress {Name : tr ("Updating platform %s" , latest )})
755-
756- // Installs tools
757- for _ , tool := range toolsToInstall {
758- if err := pm .InstallTool (tool , taskCB ); err != nil {
759- msg := tr ("Error installing tool %s" , tool )
760- taskCB (& rpc.TaskProgress {Message : msg })
761- return & arduino.FailedInstallError {Message : msg , Cause : err }
762- }
763- }
764-
765- // Installs platform
766- err = pm .InstallPlatform (latest )
767- if err != nil {
768- logrus .WithError (err ).Error ("Cannot install platform" )
769- msg := tr ("Error installing platform %s" , latest )
770- taskCB (& rpc.TaskProgress {Message : msg })
771- return & arduino.FailedInstallError {Message : msg , Cause : err }
772- }
773-
774- // Uninstall previously installed release
775- err = pm .UninstallPlatform (installedRelease , taskCB )
776-
777- // In case uninstall fails tries to rollback
778- if err != nil {
779- logrus .WithError (err ).Error ("Error updating platform." )
780- taskCB (& rpc.TaskProgress {Message : tr ("Error upgrading platform: %s" , err )})
781-
782- // Rollback
783- if err := pm .UninstallPlatform (latest , taskCB ); err != nil {
784- logrus .WithError (err ).Error ("Error rolling-back changes." )
785- msg := tr ("Error rolling-back changes" )
786- taskCB (& rpc.TaskProgress {Message : fmt .Sprintf ("%s: %s" , msg , err )})
787- return & arduino.FailedInstallError {Message : msg , Cause : err }
788- }
789- }
790-
791- // Uninstall unused tools
792- for _ , toolRelease := range installedTools {
793- if ! pm .IsToolRequired (toolRelease ) {
794- log := pm .Log .WithField ("Tool" , toolRelease )
795-
796- log .Info ("Uninstalling tool" )
797- taskCB (& rpc.TaskProgress {Name : tr ("Uninstalling %s: tool is no more required" , toolRelease )})
798- if err := pm .UninstallTool (toolRelease , taskCB ); err != nil {
799- log .WithError (err ).Error ("Error uninstalling" )
800- return & arduino.FailedInstallError {Message : tr ("Error uninstalling tool %s" , toolRelease ), Cause : err }
801- }
802-
803- log .Info ("Tool uninstalled" )
804- taskCB (& rpc.TaskProgress {Message : tr ("%s uninstalled" , toolRelease ), Completed : true })
805- }
806- }
807-
808- // Perform post install
809- if ! req .SkipPostInstall {
810- logrus .Info ("Running post_install script" )
811- taskCB (& rpc.TaskProgress {Message : tr ("Configuring platform" )})
812- if err := pm .RunPostInstallScript (latest ); err != nil {
813- taskCB (& rpc.TaskProgress {Message : tr ("WARNING: cannot run post install: %s" , err )})
814- }
815- } else {
816- logrus .Info ("Skipping platform configuration (post_install run)." )
817- taskCB (& rpc.TaskProgress {Message : tr ("Skipping platform configuration" )})
818- }
819- }
820- }
821- }
822-
823- return nil
824- }
825-
826642// LoadSketch collects and returns all files composing a sketch
827643func LoadSketch (ctx context.Context , req * rpc.LoadSketchRequest ) (* rpc.LoadSketchResponse , error ) {
828644 // TODO: This should be a ToRpc function for the Sketch struct
0 commit comments