Skip to content

Fix platform tool dependency determination #1020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
57 changes: 57 additions & 0 deletions arduino/cores/cores_test.go
Original file line number Diff line number Diff line change
@@ -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 [email protected].

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))
}
21 changes: 21 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected] tool
# arduino:[email protected] has a dependency on arduino:[email protected]
assert run_command("core install arduino:[email protected]")
# arduino:[email protected] has a dependency on arduino:[email protected]
assert run_command("core install arduino:[email protected]")
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:[email protected] 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:[email protected] 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))
Expand Down