Skip to content

Commit 74998fe

Browse files
committed
Added daemon callback for Install rpc call
1 parent 1801430 commit 74998fe

File tree

2 files changed

+9
-153
lines changed

2 files changed

+9
-153
lines changed

commands/core/install.go

+4-153
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,11 @@
1-
/*
2-
* This file is part of arduino-cli.
3-
*
4-
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
5-
*
6-
* This software is released under the GNU General Public License version 3,
7-
* which covers the main part of arduino-cli.
8-
* The terms of this license can be found at:
9-
* https://www.gnu.org/licenses/gpl-3.0.en.html
10-
*
11-
* You can be released from the requirements of the above licenses by purchasing
12-
* a commercial license. Buying such a license is mandatory if you want to modify or
13-
* otherwise use the software for commercial activities involving the Arduino
14-
* software without disclosing the source code of your own applications. To purchase
15-
* a commercial license, send an email to license@arduino.cc.
16-
*/
17-
181
package core
192

203
import (
21-
"os"
4+
"context"
225

23-
"github.com/arduino/arduino-cli/arduino/cores"
24-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
25-
"github.com/arduino/arduino-cli/cli"
26-
"github.com/arduino/arduino-cli/common/formatter"
27-
"github.com/sirupsen/logrus"
28-
"github.com/spf13/cobra"
6+
"github.com/arduino/arduino-cli/rpc"
297
)
308

31-
func initInstallCommand() *cobra.Command {
32-
installCommand := &cobra.Command{
33-
Use: "install PACKAGER:ARCH[@VERSION] ...",
34-
Short: "Installs one or more cores and corresponding tool dependencies.",
35-
Long: "Installs one or more cores and corresponding tool dependencies.",
36-
Example: " # download the latest version of arduino SAMD core.\n" +
37-
" " + cli.AppName + " core install arduino:samd\n\n" +
38-
" # download a specific version (in this case 1.6.9).\n" +
39-
" " + cli.AppName + " core install arduino:samd=1.6.9",
40-
Args: cobra.MinimumNArgs(1),
41-
Run: runInstallCommand,
42-
}
43-
return installCommand
44-
}
45-
46-
func runInstallCommand(cmd *cobra.Command, args []string) {
47-
logrus.Info("Executing `arduino core download`")
48-
49-
platformsRefs := parsePlatformReferenceArgs(args)
50-
pm, _ := cli.InitPackageAndLibraryManagerWithoutBundles()
51-
52-
for _, platformRef := range platformsRefs {
53-
installPlatformByRef(pm, platformRef)
54-
}
55-
56-
// TODO: Cleanup unused tools
57-
}
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")
9+
func Install(ctx context.Context, req *rpc.InstallReq) (*rpc.InstallResp, error) {
10+
return nil, nil
16011
}

daemon/daemon.go

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/arduino/arduino-cli/commands"
1515
"github.com/arduino/arduino-cli/commands/board"
1616
"github.com/arduino/arduino-cli/commands/compile"
17+
"github.com/arduino/arduino-cli/commands/core"
1718
"github.com/arduino/arduino-cli/rpc"
1819
"github.com/spf13/cobra"
1920
"google.golang.org/grpc"
@@ -66,3 +67,7 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoC
6667
stream.Send(resp)
6768
return err
6869
}
70+
71+
func (s *ArduinoCoreServerImpl) Install(ctx context.Context, req *rpc.InstallReq) (*rpc.InstallResp, error) {
72+
return core.Install(ctx, req)
73+
}

0 commit comments

Comments
 (0)