Skip to content

Commit d810785

Browse files
committed
fix: use the libraries resolution algorithm to determine library priority
1 parent 12bc114 commit d810785

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

Diff for: arduino/libraries/libraries.go

-15
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,6 @@ func (library *Library) SourceDirs() []SourceDir {
212212
return dirs
213213
}
214214

215-
// LocationPriorityFor returns a number representing the location priority for the given library
216-
// using the given platform and referenced-platform. Higher value means higher priority.
217-
func (library *Library) LocationPriorityFor(platformRelease, refPlatformRelease *cores.PlatformRelease) int {
218-
if library.Location == IDEBuiltIn {
219-
return 1
220-
} else if library.ContainerPlatform == refPlatformRelease {
221-
return 2
222-
} else if library.ContainerPlatform == platformRelease {
223-
return 3
224-
} else if library.Location == User {
225-
return 4
226-
}
227-
return 0
228-
}
229-
230215
// DeclaredHeaders returns the C++ headers that the library declares in library.properties
231216
func (library *Library) DeclaredHeaders() []string {
232217
if library.declaredHeaders == nil {

Diff for: commands/lib/list.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/arduino/arduino-cli/arduino/libraries"
2525
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
2626
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
27+
"github.com/arduino/arduino-cli/arduino/libraries/librariesresolver"
2728
"github.com/arduino/arduino-cli/commands"
2829
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2930
)
@@ -69,7 +70,9 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
6970
}
7071
}
7172
if latest, has := filteredRes[lib.Library.Name]; has {
72-
if latest.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) >= lib.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) {
73+
latestPriority := librariesresolver.ComputePriority(latest.Library, "", fqbn.PlatformArch)
74+
libPriority := librariesresolver.ComputePriority(lib.Library, "", fqbn.PlatformArch)
75+
if latestPriority >= libPriority {
7376
// Pick library with the best priority
7477
continue
7578
}

0 commit comments

Comments
 (0)