Skip to content

Commit 5bc5bbb

Browse files
committed
Added tool selection from referenced platform
1 parent 4e2c2ab commit 5bc5bbb

File tree

10 files changed

+133
-21
lines changed

10 files changed

+133
-21
lines changed

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

+15-12
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,9 @@ func (pme *Explorer) GetTool(toolID string) *cores.Tool {
614614
}
615615
}
616616

617-
// FindToolsRequiredForBoard FIXMEDOC
618-
func (pme *Explorer) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.ToolRelease, error) {
619-
pme.log.Infof("Searching tools required for board %s", board)
620-
621-
platform := board.PlatformRelease
617+
// FindToolsRequiredForBuild returns the list of ToolReleases needed to build for the specified
618+
// plaftorm. The buildPlatform may be different depending on the selected board.
619+
func (pme *Explorer) FindToolsRequiredForBuild(platform, buildPlatform *cores.PlatformRelease) ([]*cores.ToolRelease, error) {
622620

623621
// maps tool name => all available ToolRelease
624622
allToolsAlternatives := map[string][]*cores.ToolRelease{}
@@ -631,14 +629,19 @@ func (pme *Explorer) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.Too
631629
// selectBest select the tool with best matching, applying the following rules
632630
// in order of priority:
633631
// - the tool comes from the requested packager
632+
// - the tool comes from the build platform packager
634633
// - the tool has the greatest version
635634
// - the tool packager comes first in alphabetic order
636-
selectBest := func(tools []*cores.ToolRelease, packager string) *cores.ToolRelease {
635+
packagerPriority := map[string]int{}
636+
packagerPriority[platform.Platform.Package.Name] = 2
637+
if buildPlatform != nil {
638+
packagerPriority[buildPlatform.Platform.Package.Name] = 1
639+
}
640+
selectBest := func(tools []*cores.ToolRelease) *cores.ToolRelease {
637641
selected := tools[0]
638-
namePriority := map[string]int{packager: 1}
639642
for _, tool := range tools[1:] {
640-
if namePriority[tool.Tool.Package.Name] != namePriority[selected.Tool.Package.Name] {
641-
if namePriority[tool.Tool.Package.Name] > namePriority[selected.Tool.Package.Name] {
643+
if packagerPriority[tool.Tool.Package.Name] != packagerPriority[selected.Tool.Package.Name] {
644+
if packagerPriority[tool.Tool.Package.Name] > packagerPriority[selected.Tool.Package.Name] {
642645
selected = tool
643646
}
644647
continue
@@ -662,7 +665,7 @@ func (pme *Explorer) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.Too
662665
// on more than one version of the same tool. For example adafruit:samd has both
663666
// [email protected] and [email protected]. To allow the runtime property
664667
// {runtime.tools.bossac.path} to be correctly set to the 1.8.0 version we must ensure
665-
// taht the returned array is sorted by version.
668+
// that the returned array is sorted by version.
666669
platform.ToolDependencies.Sort()
667670
for _, toolDep := range platform.ToolDependencies {
668671
pme.log.WithField("tool", toolDep).Infof("Required tool")
@@ -676,9 +679,9 @@ func (pme *Explorer) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.Too
676679

677680
// Since a Platform may not specify the required tools (because it's a platform that comes
678681
// from a user/hardware dir without a package_index.json) then add all available tools giving
679-
// priority to tools coming from the same packager
682+
// priority to tools coming from the same packager or referenced packager
680683
for _, tools := range allToolsAlternatives {
681-
tool := selectBest(tools, platform.Platform.Package.Name)
684+
tool := selectBest(tools)
682685
requiredTools = append(requiredTools, tool)
683686
}
684687
return requiredTools, nil

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

+43-2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
287287
loadIndex("https://dl.espressif.com/dl/package_esp32_index.json")
288288
loadIndex("http://arduino.esp8266.com/stable/package_esp8266com_index.json")
289289
loadIndex("https://adafruit.github.io/arduino-board-index/package_adafruit_index.json")
290+
loadIndex("https://test.com/package_test_index.json")
291+
290292
// We ignore the errors returned since they might not be necessarily blocking
291293
// but just warnings for the user, like in the case a board is not loaded
292294
// because of malformed menus
@@ -310,8 +312,13 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
310312
})
311313
require.NotNil(t, esptool0413)
312314

315+
testPlatform := pme.FindPlatformRelease(&packagemanager.PlatformReference{
316+
Package: "test",
317+
PlatformArchitecture: "avr",
318+
PlatformVersion: semver.MustParse("1.1.0")})
319+
313320
testConflictingToolsInDifferentPackages := func() {
314-
tools, err := pme.FindToolsRequiredForBoard(esp32)
321+
tools, err := pme.FindToolsRequiredForBuild(esp32.PlatformRelease, nil)
315322
require.NoError(t, err)
316323
require.Contains(t, tools, esptool231)
317324
require.NotContains(t, tools, esptool0413)
@@ -331,10 +338,44 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
331338
testConflictingToolsInDifferentPackages()
332339
testConflictingToolsInDifferentPackages()
333340

341+
{
342+
// Test buildPlatform dependencies
343+
arduinoBossac180 := pme.FindToolDependency(&cores.ToolDependency{
344+
ToolPackager: "arduino",
345+
ToolName: "bossac",
346+
ToolVersion: semver.ParseRelaxed("1.8.0-48-gb176eee"),
347+
})
348+
require.NotNil(t, arduinoBossac180)
349+
testBossac175 := pme.FindToolDependency(&cores.ToolDependency{
350+
ToolPackager: "test",
351+
ToolName: "bossac",
352+
ToolVersion: semver.ParseRelaxed("1.7.5"),
353+
})
354+
require.NotNil(t, testBossac175)
355+
356+
tools, err := pme.FindToolsRequiredForBuild(esp32.PlatformRelease, nil)
357+
require.NoError(t, err)
358+
require.Contains(t, tools, esptool231)
359+
require.NotContains(t, tools, esptool0413)
360+
// When building without testPlatform dependency, arduino:bossac should be selected
361+
// since it has the higher version
362+
require.NotContains(t, tools, testBossac175)
363+
require.Contains(t, tools, arduinoBossac180)
364+
365+
tools, err = pme.FindToolsRequiredForBuild(esp32.PlatformRelease, testPlatform)
366+
require.NoError(t, err)
367+
require.Contains(t, tools, esptool231)
368+
require.NotContains(t, tools, esptool0413)
369+
// When building with testPlatform dependency, test:bossac should be selected
370+
// because it has dependency priority
371+
require.Contains(t, tools, testBossac175)
372+
require.NotContains(t, tools, arduinoBossac180)
373+
}
374+
334375
feather, err := pme.FindBoardWithFQBN("adafruit:samd:adafruit_feather_m0_express")
335376
require.NoError(t, err)
336377
require.NotNil(t, feather)
337-
featherTools, err := pme.FindToolsRequiredForBoard(feather)
378+
featherTools, err := pme.FindToolsRequiredForBuild(feather.PlatformRelease, nil)
338379
require.NoError(t, err)
339380
require.NotNil(t, featherTools)
340381

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "test",
5+
"websiteURL": "https://test.com",
6+
"email": "[email protected]",
7+
"help": {
8+
"online": "https://test.com"
9+
},
10+
"maintainer": "Test",
11+
"platforms": [
12+
{
13+
"architecture": "avr",
14+
"boards": [],
15+
"name": "Test AVR Boards",
16+
"category": "Test",
17+
"version": "1.1.0",
18+
"archiveFileName": "test-1.1.0.tar.bz2",
19+
"checksum": "SHA-256:4e72d4267d9a8d86874edcd021dc661854a5136c0eed947a6fe10366bc51e373",
20+
"help": {
21+
"online": "https://test.com"
22+
},
23+
"url": "https://test.com/test-1.1.0.tar.bz2",
24+
"toolsDependencies": [],
25+
"size": "12345"
26+
}
27+
],
28+
"tools": [
29+
{
30+
"name": "bossac",
31+
"version": "1.7.5",
32+
"systems": [
33+
{
34+
"host": "i386-apple-darwin11",
35+
"checksum": "MD5:603bcce8e59683ac27054b3197a53254",
36+
"size": "96372129",
37+
"archiveFileName": "bossac.tar.bz2",
38+
"url": "https://test.com/bossac.tar.bz2"
39+
}
40+
]
41+
}
42+
]
43+
}
44+
]
45+
}

Diff for: arduino/cores/packagemanager/testdata/data_dir_1/packages/test/hardware/avr/1.1.0/boards.txt

Whitespace-only changes.

Diff for: arduino/cores/packagemanager/testdata/data_dir_1/packages/test/tools/bossac/1.7.5/.keep

Whitespace-only changes.

Diff for: commands/debug/debug_info.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func getDebugProperties(req *debug.DebugConfigRequest, pme *packagemanager.Explo
6666
}
6767

6868
// Find target board and board properties
69-
_, platformRelease, board, boardProperties, referencedPlatformRelease, err := pme.ResolveFQBN(fqbn)
69+
_, platformRelease, _, boardProperties, referencedPlatformRelease, err := pme.ResolveFQBN(fqbn)
7070
if err != nil {
7171
return nil, &arduino.UnknownFQBNError{Cause: err}
7272
}
@@ -98,7 +98,7 @@ func getDebugProperties(req *debug.DebugConfigRequest, pme *packagemanager.Explo
9898
for _, tool := range pme.GetAllInstalledToolsReleases() {
9999
toolProperties.Merge(tool.RuntimeProperties())
100100
}
101-
if requiredTools, err := pme.FindToolsRequiredForBoard(board); err == nil {
101+
if requiredTools, err := pme.FindToolsRequiredForBuild(platformRelease, referencedPlatformRelease); err == nil {
102102
for _, requiredTool := range requiredTools {
103103
logrus.WithField("tool", requiredTool).Info("Tool required for debug")
104104
toolProperties.Merge(requiredTool.RuntimeProperties())

Diff for: commands/upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func runProgramAction(pme *packagemanager.Explorer,
295295
for _, tool := range pme.GetAllInstalledToolsReleases() {
296296
uploadProperties.Merge(tool.RuntimeProperties())
297297
}
298-
if requiredTools, err := pme.FindToolsRequiredForBoard(board); err == nil {
298+
if requiredTools, err := pme.FindToolsRequiredForBuild(boardPlatform, buildPlatform); err == nil {
299299
for _, requiredTool := range requiredTools {
300300
logrus.WithField("tool", requiredTool).Info("Tool required for upload")
301301
if requiredTool.IsInstalled() {

Diff for: docs/UPGRADING.md

+17
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ plus `Name`, `Version`, and an `UpToDate` boolean flag.
7474

7575
`InstallZipLib` method `archivePath` is now a `paths.Path` instead of a `string`.
7676

77+
### golang API change in `github.com/arduino/arduino-cli/rduino/cores/packagemanager.Explorer`
78+
79+
The `packagemanager.Explorer` method `FindToolsRequiredForBoard`:
80+
81+
```go
82+
func (pme *Explorer) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.ToolRelease, error) { ... }
83+
```
84+
85+
has been renamed to `FindToolsRequiredForBuild:
86+
87+
```go
88+
func (pme *Explorer) FindToolsRequiredForBuild(platform, buildPlatform *cores.PlatformRelease) ([]*cores.ToolRelease, error) { ... }
89+
```
90+
91+
moreover it now requires the `platform` and the `buildPlatform` (a.k.a. the referenced platform core used for the
92+
compile) instead of the `board`. Usually these two value are obtained from the `Explorer.ResolveFQBN(...)` method.
93+
7794
## 0.29.0
7895

7996
### Removed gRPC API: `cc.arduino.cli.commands.v1.UpdateCoreLibrariesIndex`, `Outdated`, and `Upgrade`

Diff for: docs/package_index_json-specification.md

+6
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,17 @@ are as follows:
278278

279279
1. the tool, version and packager specified via `toolsDependencies` in the `package_index.json`
280280
1. the highest version of the tool provided by the packager of the current platform
281+
1. the highest version of the tool provided by the packager of the referenced platform used for compile (see
282+
["Referencing another core, variant or tool"](platform-specification.md#referencing-another-core-variant-or-tool)
283+
for more info)
281284
1. the highest version of the tool provided by any other packager (in case of tie, the first packager in alphabetical
282285
order wins)
283286

284287
- The property `{runtime.tools.TOOLNAME-VERSION.path}` points, in order of priority, to:
285288
1. the tool and version provided by the packager of the current platform
289+
1. the tool and version provided by the packager of the referenced platform used for compile (see
290+
["Referencing another core, variant or tool"](platform-specification.md#referencing-another-core-variant-or-tool)
291+
for more info)
286292
1. the tool and version provided by any other packager (in case of tie, the first packager in alphabetical order wins)
287293

288294
### Example JSON index file

Diff for: legacy/builder/target_board_resolver.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
type TargetBoardResolver struct{}
2626

2727
func (s *TargetBoardResolver) Run(ctx *types.Context) error {
28-
targetPackage, targetPlatform, targetBoard, buildProperties, actualPlatform, err := ctx.PackageManager.ResolveFQBN(ctx.FQBN)
28+
targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := ctx.PackageManager.ResolveFQBN(ctx.FQBN)
2929
if err != nil {
3030
return fmt.Errorf("%s: %w", tr("Error resolving FQBN"), err)
3131
}
@@ -39,7 +39,7 @@ func (s *TargetBoardResolver) Run(ctx *types.Context) error {
3939

4040
if ctx.Verbose {
4141
ctx.Info(tr("Using board '%[1]s' from platform in folder: %[2]s", targetBoard.BoardID, targetPlatform.InstallDir))
42-
ctx.Info(tr("Using core '%[1]s' from platform in folder: %[2]s", core, actualPlatform.InstallDir))
42+
ctx.Info(tr("Using core '%[1]s' from platform in folder: %[2]s", core, buildPlatform.InstallDir))
4343
}
4444

4545
if buildProperties.Get("build.board") == "" {
@@ -50,7 +50,7 @@ func (s *TargetBoardResolver) Run(ctx *types.Context) error {
5050
targetBoard.String(), "'build.board'", defaultBuildBoard))
5151
}
5252

53-
requiredTools, err := ctx.PackageManager.FindToolsRequiredForBoard(targetBoard)
53+
requiredTools, err := ctx.PackageManager.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
5454
if err != nil {
5555
return err
5656
}
@@ -60,7 +60,7 @@ func (s *TargetBoardResolver) Run(ctx *types.Context) error {
6060
ctx.TargetBoardBuildProperties = buildProperties
6161
ctx.TargetPlatform = targetPlatform
6262
ctx.TargetPackage = targetPackage
63-
ctx.ActualPlatform = actualPlatform
63+
ctx.ActualPlatform = buildPlatform
6464
ctx.RequiredTools = requiredTools
6565
return nil
6666
}

0 commit comments

Comments
 (0)