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)) +} 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))