Skip to content

Commit b3db7a6

Browse files
committed
Reorder toolDependencies to properly generate runtime properties
1 parent 33d0483 commit b3db7a6

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

Diff for: arduino/cores/cores.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ package cores
1919

2020
import (
2121
"encoding/json"
22+
"sort"
2223
"strings"
2324

24-
paths "github.com/arduino/go-paths-helper"
25-
2625
"github.com/arduino/arduino-cli/arduino/resources"
26+
paths "github.com/arduino/go-paths-helper"
2727
properties "github.com/arduino/go-properties-orderedmap"
2828
semver "go.bug.st/relaxed-semver"
2929
)
@@ -79,6 +79,20 @@ func (bm *BoardManifest) HasUsbID(vid, pid string) bool {
7979
// ToolDependencies is a set of tool dependency
8080
type ToolDependencies []*ToolDependency
8181

82+
// Sort sorts the ToolDependencies by name and (if multiple instance of the same
83+
// tool is required) by version.
84+
func (deps ToolDependencies) Sort() {
85+
sort.Slice(deps, func(i, j int) bool {
86+
if deps[i].ToolPackager != deps[j].ToolPackager {
87+
return deps[i].ToolPackager < deps[j].ToolPackager
88+
}
89+
if deps[i].ToolName != deps[j].ToolName {
90+
return deps[i].ToolName < deps[j].ToolName
91+
}
92+
return deps[i].ToolVersion.LessThan(deps[j].ToolVersion)
93+
})
94+
}
95+
8296
// ToolDependency is a tuple that uniquely identifies a specific version of a Tool
8397
type ToolDependency struct {
8498
ToolName string

Diff for: arduino/cores/packagemanager/package_manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core
404404

405405
// replace the default tools above with the specific required by the current platform
406406
requiredTools := []*cores.ToolRelease{}
407+
platform.Dependencies.Sort()
407408
for _, toolDep := range platform.Dependencies {
408409
pm.Log.WithField("tool", toolDep).Infof("Required tool")
409410
tool := pm.FindToolDependency(toolDep)

Diff for: arduino/cores/packagemanager/package_manager_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,11 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
162162
require.NotNil(t, bossac18)
163163
require.Contains(t, featherTools, bossac17)
164164
require.Contains(t, featherTools, bossac18)
165+
166+
// Check if the runtime variable is set correctly to the latest version
167+
uploadProperties := properties.NewMap()
168+
for _, requiredTool := range featherTools {
169+
uploadProperties.Merge(requiredTool.RuntimeProperties())
170+
}
171+
require.Equal(t, bossac18.InstallDir.String(), uploadProperties.Get("runtime.tools.bossac.path"))
165172
}

Diff for: arduino/cores/packagemanager/testdata/data_dir_1/package_adafruit_index.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -3935,12 +3935,16 @@
39353935
{
39363936
"packager": "arduino",
39373937
"name": "bossac",
3938-
"version": "1.7.0"
3938+
"version": "1.8.0-48-gb176eee"
39393939
},
39403940
{
3941+
"_warning":
3942+
3943+
"*** [email protected] is listed after [email protected] to test if the runtime propoerty `runtime.tools.bossac.path` is correctly set to the path of [email protected] ***",
3944+
39413945
"packager": "arduino",
39423946
"name": "bossac",
3943-
"version": "1.8.0-48-gb176eee"
3947+
"version": "1.7.0"
39443948
},
39453949
{
39463950
"packager": "arduino",

0 commit comments

Comments
 (0)