Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
122bca5b
Commit
122bca5b
authored
Aug 13, 2018
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented core uninstall
parent
7e2872d0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
152 additions
and
0 deletions
+152
-0
arduino/cores/packagemanager/install_uninstall.go
arduino/cores/packagemanager/install_uninstall.go
+40
-0
commands/commands_test.go
commands/commands_test.go
+10
-0
commands/core/core.go
commands/core/core.go
+1
-0
commands/core/uninstall.go
commands/core/uninstall.go
+101
-0
No files found.
arduino/cores/packagemanager/install_uninstall.go
View file @
122bca5b
...
...
@@ -33,6 +33,26 @@ func (pm *PackageManager) InstallPlatform(platformRelease *cores.PlatformRelease
return
platformRelease
.
Resource
.
Install
(
pm
.
DownloadDir
,
pm
.
TempDir
,
destDir
)
}
// UninstallPlatform remove a PlatformRelease.
func
(
pm
*
PackageManager
)
UninstallPlatform
(
platformRelease
*
cores
.
PlatformRelease
)
error
{
if
platformRelease
.
InstallDir
==
nil
{
return
fmt
.
Errorf
(
"platform not installed"
)
}
// Safety measure
if
safe
,
err
:=
platformRelease
.
InstallDir
.
IsInsideDir
(
pm
.
PackagesDir
);
err
!=
nil
{
return
fmt
.
Errorf
(
"checking if plaform is installed in data dir: %s"
,
err
)
}
else
if
!
safe
{
return
fmt
.
Errorf
(
"platform is not installed inside data dir"
)
}
if
err
:=
platformRelease
.
InstallDir
.
RemoveAll
();
err
!=
nil
{
return
fmt
.
Errorf
(
"removing platform files: %s"
,
err
)
}
platformRelease
.
InstallDir
=
nil
return
nil
}
// InstallTool installs a specific release of a tool.
func
(
pm
*
PackageManager
)
InstallTool
(
toolRelease
*
cores
.
ToolRelease
)
error
{
toolResource
:=
toolRelease
.
GetCompatibleFlavour
()
...
...
@@ -47,6 +67,26 @@ func (pm *PackageManager) InstallTool(toolRelease *cores.ToolRelease) error {
return
toolResource
.
Install
(
pm
.
DownloadDir
,
pm
.
TempDir
,
destDir
)
}
// UninstallTool remove a ToolRelease.
func
(
pm
*
PackageManager
)
UninstallTool
(
toolRelease
*
cores
.
ToolRelease
)
error
{
if
toolRelease
.
InstallDir
==
nil
{
return
fmt
.
Errorf
(
"tool not installed"
)
}
// Safety measure
if
safe
,
err
:=
toolRelease
.
InstallDir
.
IsInsideDir
(
pm
.
PackagesDir
);
err
!=
nil
{
return
fmt
.
Errorf
(
"checking if tool is installed in data dir: %s"
,
err
)
}
else
if
!
safe
{
return
fmt
.
Errorf
(
"tool is not installed inside data dir"
)
}
if
err
:=
toolRelease
.
InstallDir
.
RemoveAll
();
err
!=
nil
{
return
fmt
.
Errorf
(
"removing tool files: %s"
,
err
)
}
toolRelease
.
InstallDir
=
nil
return
nil
}
// IsToolRequired returns true if any of the installed platforms requires the toolRelease
// passed as parameter
func
(
pm
*
PackageManager
)
IsToolRequired
(
toolRelease
*
cores
.
ToolRelease
)
bool
{
...
...
commands/commands_test.go
View file @
122bca5b
...
...
@@ -372,4 +372,14 @@ func TestCoreCommands(t *testing.T) {
exitCode
,
d
=
executeWithArgs
(
t
,
"compile"
,
"-b"
,
"arduino:avr:uno"
,
currSketchbookDir
.
Join
(
"Test1"
)
.
String
())
require
.
Zero
(
t
,
exitCode
,
"exit code"
)
require
.
Contains
(
t
,
string
(
d
),
"Sketch uses"
)
// Uninstall arduino:avr
exitCode
,
d
=
executeWithArgs
(
t
,
"core"
,
"uninstall"
,
"arduino:avr"
)
require
.
Zero
(
t
,
exitCode
,
"exit code"
)
require
.
Contains
(
t
,
string
(
d
),
AVR
+
" uninstalled"
)
// Empty cores list
exitCode
,
d
=
executeWithArgs
(
t
,
"core"
,
"list"
)
require
.
Zero
(
t
,
exitCode
,
"exit code"
)
require
.
Empty
(
t
,
strings
.
TrimSpace
(
string
(
d
)))
}
commands/core/core.go
View file @
122bca5b
...
...
@@ -34,6 +34,7 @@ func InitCommand() *cobra.Command {
coreCommand
.
AddCommand
(
initInstallCommand
())
coreCommand
.
AddCommand
(
initListCommand
())
coreCommand
.
AddCommand
(
initUpdateIndexCommand
())
coreCommand
.
AddCommand
(
initUninstallCommand
())
coreCommand
.
AddCommand
(
initSearchCommand
())
return
coreCommand
}
commands/core/uninstall.go
0 → 100644
View file @
122bca5b
/*
* This file is part of arduino-cli.
*
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
*
* This software is released under the GNU General Public License version 3,
* which covers the main part of arduino-cli.
* The terms of this license can be found at:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* You can be released from the requirements of the above licenses by purchasing
* a commercial license. Buying such a license is mandatory if you want to modify or
* otherwise use the software for commercial activities involving the Arduino
* software without disclosing the source code of your own applications. To purchase
* a commercial license, send an email to license@arduino.cc.
*/
package
core
import
(
"fmt"
"os"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func
initUninstallCommand
()
*
cobra
.
Command
{
return
&
cobra
.
Command
{
Use
:
"uninstall PACKAGER:ARCH[@VERSION] ..."
,
Short
:
"Uninstalls one or more cores and corresponding tool dependencies if no more used."
,
Long
:
"Uninstalls one or more cores and corresponding tool dependencies if no more used."
,
Example
:
" "
+
commands
.
AppName
+
" core uninstall arduino:samd
\n
"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
runUninstallCommand
,
}
}
func
runUninstallCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino core download`"
)
platformsRefs
:=
parsePlatformReferenceArgs
(
args
)
pm
:=
commands
.
InitPackageManager
()
for
_
,
platformRef
:=
range
platformsRefs
{
uninstallPlatformByRef
(
pm
,
platformRef
)
}
}
func
uninstallPlatformByRef
(
pm
*
packagemanager
.
PackageManager
,
platformRef
*
packagemanager
.
PlatformReference
)
{
platform
,
tools
,
err
:=
pm
.
FindPlatformReleaseDependencies
(
platformRef
)
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Could not determine platform dependencies"
)
os
.
Exit
(
commands
.
ErrBadCall
)
}
uninstallPlatformRelease
(
pm
,
platform
)
for
_
,
tool
:=
range
tools
{
if
!
pm
.
IsToolRequired
(
tool
)
{
fmt
.
Printf
(
"Tool %s is no more required
\n
"
,
tool
)
uninstallToolRelease
(
pm
,
tool
)
}
}
}
func
uninstallPlatformRelease
(
pm
*
packagemanager
.
PackageManager
,
platformRelease
*
cores
.
PlatformRelease
)
{
log
:=
pm
.
Log
.
WithField
(
"platform"
,
platformRelease
)
log
.
Info
(
"Uninstalling platform"
)
formatter
.
Print
(
"Uninstalling "
+
platformRelease
.
String
()
+
"..."
)
if
err
:=
pm
.
UninstallPlatform
(
platformRelease
);
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"Error uninstalling"
)
formatter
.
PrintError
(
err
,
"Error uninstalling "
+
platformRelease
.
String
())
os
.
Exit
(
commands
.
ErrGeneric
)
}
log
.
Info
(
"Platform uninstalled"
)
formatter
.
Print
(
platformRelease
.
String
()
+
" uninstalled"
)
}
func
uninstallToolRelease
(
pm
*
packagemanager
.
PackageManager
,
toolRelease
*
cores
.
ToolRelease
)
{
log
:=
pm
.
Log
.
WithField
(
"Tool"
,
toolRelease
)
log
.
Info
(
"Uninstalling tool"
)
formatter
.
Print
(
"Uninstalling "
+
toolRelease
.
String
())
if
err
:=
pm
.
UninstallTool
(
toolRelease
);
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"Error uninstalling"
)
formatter
.
PrintError
(
err
,
"Error uninstalling "
+
toolRelease
.
String
())
os
.
Exit
(
commands
.
ErrGeneric
)
}
log
.
Info
(
"Tool uninstalled"
)
formatter
.
Print
(
toolRelease
.
String
()
+
" uninstalled"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment