Skip to content

Commit e335dff

Browse files
committed
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.
1 parent 1d1da06 commit e335dff

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

arduino/cores/cores.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (release *PlatformRelease) RequiresToolRelease(toolRelease *ToolRelease) bo
218218
for _, toolDep := range release.Dependencies {
219219
if toolDep.ToolName == toolRelease.Tool.Name &&
220220
toolDep.ToolPackager == toolRelease.Tool.Package.Name &&
221-
toolDep.ToolVersion == toolRelease.Version {
221+
toolDep.ToolVersion.Equal(toolRelease.Version) {
222222
return true
223223
}
224224
}

arduino/cores/cores_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package cores
17+
18+
import (
19+
"testing"
20+
21+
"github.com/stretchr/testify/require"
22+
semver "go.bug.st/relaxed-semver"
23+
)
24+
25+
func TestRequiresToolRelease(t *testing.T) {
26+
toolDependencyName := "avr-gcc"
27+
toolDependencyVersion := "7.3.0-atmel3.6.1-arduino7"
28+
toolDependencyPackager := "arduino"
29+
30+
release := PlatformRelease{
31+
Dependencies: ToolDependencies{
32+
{
33+
ToolName: toolDependencyName,
34+
ToolVersion: semver.ParseRelaxed(toolDependencyVersion),
35+
ToolPackager: toolDependencyPackager,
36+
},
37+
},
38+
}
39+
40+
toolRelease := &ToolRelease{
41+
Version: semver.ParseRelaxed(toolDependencyVersion + "not"),
42+
Tool: &Tool{
43+
Name: toolDependencyName + "not",
44+
Package: &Package{
45+
Name: toolDependencyPackager + "not",
46+
},
47+
},
48+
}
49+
50+
require.False(t, release.RequiresToolRelease(toolRelease))
51+
toolRelease.Tool.Name = toolDependencyName
52+
require.False(t, release.RequiresToolRelease(toolRelease))
53+
toolRelease.Tool.Package.Name = toolDependencyPackager
54+
require.False(t, release.RequiresToolRelease(toolRelease))
55+
toolRelease.Version = semver.ParseRelaxed(toolDependencyVersion)
56+
require.True(t, release.RequiresToolRelease(toolRelease))
57+
}

0 commit comments

Comments
 (0)