18
18
package core
19
19
20
20
import (
21
- "os "
21
+ "context "
22
22
23
- "github.com/arduino/arduino-cli/arduino/cores"
24
- "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
25
23
"github.com/arduino/arduino-cli/cli"
26
- "github.com/arduino/arduino-cli/common/formatter"
24
+ "github.com/arduino/arduino-cli/commands/core"
25
+ "github.com/arduino/arduino-cli/rpc"
27
26
"github.com/sirupsen/logrus"
28
27
"github.com/spf13/cobra"
29
28
)
@@ -44,117 +43,24 @@ func initInstallCommand() *cobra.Command {
44
43
}
45
44
46
45
func runInstallCommand (cmd * cobra.Command , args []string ) {
46
+ instance := cli .CreateInstance ()
47
47
logrus .Info ("Executing `arduino core download`" )
48
48
49
49
platformsRefs := parsePlatformReferenceArgs (args )
50
- pm , _ := cli .InitPackageAndLibraryManagerWithoutBundles ()
51
50
52
51
for _ , platformRef := range platformsRefs {
53
- installPlatformByRef (pm , platformRef )
52
+ core .PlatformInstall (context .Background (), & rpc.PlatformInstallReq {
53
+ Instance : instance ,
54
+ PlatformPackage : platformRef .Package ,
55
+ Architecture : platformRef .PlatformArchitecture ,
56
+ Version : platformRef .PlatformVersion .String (),
57
+ })
58
+ // if err != nil {
59
+ // formatter.PrintError(err, "Error during build")
60
+ // os.Exit(cli.ErrGeneric)
61
+ // }
62
+ // }
54
63
}
55
64
56
65
// TODO: Cleanup unused tools
57
66
}
58
-
59
- func installPlatformByRef (pm * packagemanager.PackageManager , platformRef * packagemanager.PlatformReference ) {
60
- platform , tools , err := pm .FindPlatformReleaseDependencies (platformRef )
61
- if err != nil {
62
- formatter .PrintError (err , "Could not determine platform dependencies" )
63
- os .Exit (cli .ErrBadCall )
64
- }
65
-
66
- installPlatform (pm , platform , tools )
67
- }
68
-
69
- func installPlatform (pm * packagemanager.PackageManager , platformRelease * cores.PlatformRelease , requiredTools []* cores.ToolRelease ) {
70
- log := pm .Log .WithField ("platform" , platformRelease )
71
-
72
- // Prerequisite checks before install
73
- if platformRelease .IsInstalled () {
74
- log .Warn ("Platform already installed" )
75
- formatter .Print ("Platform " + platformRelease .String () + " already installed" )
76
- return
77
- }
78
- toolsToInstall := []* cores.ToolRelease {}
79
- for _ , tool := range requiredTools {
80
- if tool .IsInstalled () {
81
- log .WithField ("tool" , tool ).Warn ("Tool already installed" )
82
- formatter .Print ("Tool " + tool .String () + " already installed" )
83
- } else {
84
- toolsToInstall = append (toolsToInstall , tool )
85
- }
86
- }
87
-
88
- // Package download
89
- for _ , tool := range toolsToInstall {
90
- downloadTool (pm , tool )
91
- }
92
- downloadPlatform (pm , platformRelease )
93
-
94
- for _ , tool := range toolsToInstall {
95
- InstallToolRelease (pm , tool )
96
- }
97
-
98
- // Are we installing or upgrading?
99
- platform := platformRelease .Platform
100
- installed := pm .GetInstalledPlatformRelease (platform )
101
- if installed == nil {
102
- log .Info ("Installing platform" )
103
- formatter .Print ("Installing " + platformRelease .String () + "..." )
104
- } else {
105
- log .Info ("Updating platform " + installed .String ())
106
- formatter .Print ("Updating " + installed .String () + " with " + platformRelease .String () + "..." )
107
- }
108
-
109
- // Install
110
- err := pm .InstallPlatform (platformRelease )
111
- if err != nil {
112
- log .WithError (err ).Error ("Cannot install platform" )
113
- formatter .PrintError (err , "Cannot install platform" )
114
- os .Exit (cli .ErrGeneric )
115
- }
116
-
117
- // If upgrading remove previous release
118
- if installed != nil {
119
- err := pm .UninstallPlatform (installed )
120
-
121
- // In case of error try to rollback
122
- if err != nil {
123
- log .WithError (err ).Error ("Error updating platform." )
124
- formatter .PrintError (err , "Error updating platform" )
125
-
126
- // Rollback
127
- if err := pm .UninstallPlatform (platformRelease ); err != nil {
128
- log .WithError (err ).Error ("Error rolling-back changes." )
129
- formatter .PrintError (err , "Error rolling-back changes." )
130
- }
131
- os .Exit (cli .ErrGeneric )
132
- }
133
- }
134
-
135
- log .Info ("Platform installed" )
136
- formatter .Print (platformRelease .String () + " installed" )
137
- }
138
-
139
- // InstallToolRelease installs a ToolRelease
140
- func InstallToolRelease (pm * packagemanager.PackageManager , toolRelease * cores.ToolRelease ) {
141
- log := pm .Log .WithField ("Tool" , toolRelease )
142
-
143
- if toolRelease .IsInstalled () {
144
- log .Warn ("Tool already installed" )
145
- formatter .Print ("Tool " + toolRelease .String () + " already installed" )
146
- return
147
- }
148
-
149
- log .Info ("Installing tool" )
150
- formatter .Print ("Installing " + toolRelease .String () + "..." )
151
- err := pm .InstallTool (toolRelease )
152
- if err != nil {
153
- log .WithError (err ).Warn ("Cannot install tool" )
154
- formatter .PrintError (err , "Cannot install tool: " + toolRelease .String ())
155
- os .Exit (cli .ErrGeneric )
156
- }
157
-
158
- log .Info ("Tool installed" )
159
- formatter .Print (toolRelease .String () + " installed" )
160
- }
0 commit comments