|
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 |
| - |
18 | 1 | package core
|
19 | 2 |
|
20 | 3 | import (
|
21 |
| - "os" |
| 4 | + "context" |
22 | 5 |
|
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" |
29 | 7 | )
|
30 | 8 |
|
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 |
160 | 11 | }
|
0 commit comments