Skip to content

Commit 145478d

Browse files
committed
Allow multiple instances of the same 'required_tool' in cores
Fix #166
1 parent dba2d34 commit 145478d

File tree

14 files changed

+5667
-4
lines changed

14 files changed

+5667
-4
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,17 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core
403403
}
404404

405405
// replace the default tools above with the specific required by the current platform
406+
requiredTools := []*cores.ToolRelease{}
406407
for _, toolDep := range platform.Dependencies {
407408
pm.Log.WithField("tool", toolDep).Infof("Required tool")
408409
tool := pm.FindToolDependency(toolDep)
409410
if tool == nil {
410411
return nil, fmt.Errorf("tool release not found: %s", toolDep)
411412
}
412-
foundTools[tool.Tool.Name] = tool
413+
requiredTools = append(requiredTools, tool)
414+
delete(foundTools, tool.Tool.Name)
413415
}
414416

415-
requiredTools := []*cores.ToolRelease{}
416417
for _, toolRel := range foundTools {
417418
requiredTools = append(requiredTools, toolRel)
418419
}

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ import (
2121
"net/url"
2222
"testing"
2323

24-
"go.bug.st/relaxed-semver"
25-
2624
"github.com/arduino/arduino-cli/arduino/cores"
2725
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2826
"github.com/arduino/arduino-cli/configs"
2927
"github.com/arduino/go-paths-helper"
3028
"github.com/arduino/go-properties-orderedmap"
3129
"github.com/stretchr/testify/require"
30+
semver "go.bug.st/relaxed-semver"
3231
)
3332

3433
var customHardware = paths.New("testdata", "custom_hardware")
@@ -102,6 +101,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
102101
}
103102
loadIndex("https://dl.espressif.com/dl/package_esp32_index.json")
104103
loadIndex("http://arduino.esp8266.com/stable/package_esp8266com_index.json")
104+
loadIndex("https://adafruit.github.io/arduino-board-index/package_adafruit_index.json")
105105
require.NoError(t, pm.LoadHardware(conf))
106106
esp32, err := pm.FindBoardWithFQBN("esp32:esp32:esp32")
107107
require.NoError(t, err)
@@ -138,4 +138,28 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
138138
testConflictingToolsInDifferentPackages()
139139
testConflictingToolsInDifferentPackages()
140140
testConflictingToolsInDifferentPackages()
141+
142+
feather, err := pm.FindBoardWithFQBN("adafruit:samd:adafruit_feather_m0_express")
143+
require.NoError(t, err)
144+
require.NotNil(t, feather)
145+
featherTools, err := pm.FindToolsRequiredForBoard(feather)
146+
require.NoError(t, err)
147+
require.NotNil(t, featherTools)
148+
149+
// Test when a package index requires two different version of the same tool
150+
// See: https://github.com/arduino/arduino-cli/issues/166#issuecomment-528295989
151+
bossac17 := pm.FindToolDependency(&cores.ToolDependency{
152+
ToolPackager: "arduino",
153+
ToolName: "bossac",
154+
ToolVersion: semver.ParseRelaxed("1.7.0"),
155+
})
156+
require.NotNil(t, bossac17)
157+
bossac18 := pm.FindToolDependency(&cores.ToolDependency{
158+
ToolPackager: "arduino",
159+
ToolName: "bossac",
160+
ToolVersion: semver.ParseRelaxed("1.8.0-48-gb176eee"),
161+
})
162+
require.NotNil(t, bossac18)
163+
require.Contains(t, featherTools, bossac17)
164+
require.Contains(t, featherTools, bossac18)
141165
}

0 commit comments

Comments
 (0)