From e335dff80d86b3856b4133fb4941d4d45ea9e84e Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 8 Oct 2020 15:16:51 -0700 Subject: [PATCH 1/2] Fix platform tool dependency determination The platform tool dependency check was giving false negatives due to comparing pointers instead of version values. This caused tools to be removed during platform uninstallation even when another installed platform had a dependency on that tool. --- arduino/cores/cores.go | 2 +- arduino/cores/cores_test.go | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 arduino/cores/cores_test.go diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index 9b90bc84744..b5ce672c7b1 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -218,7 +218,7 @@ func (release *PlatformRelease) RequiresToolRelease(toolRelease *ToolRelease) bo for _, toolDep := range release.Dependencies { if toolDep.ToolName == toolRelease.Tool.Name && toolDep.ToolPackager == toolRelease.Tool.Package.Name && - toolDep.ToolVersion == toolRelease.Version { + toolDep.ToolVersion.Equal(toolRelease.Version) { return true } } diff --git a/arduino/cores/cores_test.go b/arduino/cores/cores_test.go new file mode 100644 index 00000000000..6df901ae230 --- /dev/null +++ b/arduino/cores/cores_test.go @@ -0,0 +1,57 @@ +// This file is part of arduino-cli. +// +// Copyright 2020 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 cores + +import ( + "testing" + + "github.com/stretchr/testify/require" + semver "go.bug.st/relaxed-semver" +) + +func TestRequiresToolRelease(t *testing.T) { + toolDependencyName := "avr-gcc" + toolDependencyVersion := "7.3.0-atmel3.6.1-arduino7" + toolDependencyPackager := "arduino" + + release := PlatformRelease{ + Dependencies: ToolDependencies{ + { + ToolName: toolDependencyName, + ToolVersion: semver.ParseRelaxed(toolDependencyVersion), + ToolPackager: toolDependencyPackager, + }, + }, + } + + toolRelease := &ToolRelease{ + Version: semver.ParseRelaxed(toolDependencyVersion + "not"), + Tool: &Tool{ + Name: toolDependencyName + "not", + Package: &Package{ + Name: toolDependencyPackager + "not", + }, + }, + } + + require.False(t, release.RequiresToolRelease(toolRelease)) + toolRelease.Tool.Name = toolDependencyName + require.False(t, release.RequiresToolRelease(toolRelease)) + toolRelease.Tool.Package.Name = toolDependencyPackager + require.False(t, release.RequiresToolRelease(toolRelease)) + toolRelease.Version = semver.ParseRelaxed(toolDependencyVersion) + require.True(t, release.RequiresToolRelease(toolRelease)) +} From 715c18328f63d86cf9f07e3500db469891f4391c Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 10 Oct 2020 15:05:03 -0700 Subject: [PATCH 2/2] Add integration test for tool removal during platform uninstall Tool dependency by `arduino-cli core uninstall` is somewhat complex because it must only uninstall the tools that no other platforms have a dependency on. If it doesn't, it breaks the other platform and the cause of this breakage would likely not be obvious to the user. So it's important to test to ensure this functionality continues to work correctly. --- test/test_core.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_core.py b/test/test_core.py index 950f73265f2..6e3c28a163b 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -205,6 +205,27 @@ def test_core_uninstall(run_command): assert not _in(result.stdout, "arduino:avr") +def test_core_uninstall_tool_dependency_removal(run_command, data_dir): + # These platforms both have a dependency on the arduino:avr-gcc@7.3.0-atmel3.6.1-arduino5 tool + # arduino:avr@1.8.2 has a dependency on arduino:avrdude@6.3.0-arduino17 + assert run_command("core install arduino:avr@1.8.2") + # arduino:megaavr@1.8.4 has a dependency on arduino:avrdude@6.3.0-arduino16 + assert run_command("core install arduino:megaavr@1.8.4") + assert run_command("core uninstall arduino:avr") + + arduino_tools_path = Path(data_dir, "packages", "arduino", "tools") + + avr_gcc_binaries_path = arduino_tools_path.joinpath("avr-gcc", "7.3.0-atmel3.6.1-arduino5", "bin") + # The tool arduino:avr-gcc@7.3.0-atmel3.6.1-arduino5 that is a dep of another installed platform should remain + assert avr_gcc_binaries_path.joinpath("avr-gcc").exists() or avr_gcc_binaries_path.joinpath("avr-gcc.exe").exists() + + avrdude_binaries_path = arduino_tools_path.joinpath("avrdude", "6.3.0-arduino17", "bin") + # The tool arduino:avrdude@6.3.0-arduino17 that is only a dep of arduino:avr should have been removed + assert ( + avrdude_binaries_path.joinpath("avrdude").exists() or avrdude_binaries_path.joinpath("avrdude.exe").exists() + ) is False + + def test_core_zipslip(run_command): url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json" assert run_command("core update-index --additional-urls={}".format(url))