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