Skip to content

Commit d3b4fb1

Browse files
committed
Handle promotion based on architecture for all libraries
solves arduino/ArduinoCore-samd#80, which was caused by USBHost library not having a corresponding .h, thus bypassing the findBestLibraryWithHeader check
1 parent 4debb62 commit d3b4fb1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: src/arduino.cc/builder/includes_to_include_folders.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
141141

142142
for _, platform := range platforms {
143143
if platform != nil {
144-
library = findBestLibraryWithHeader(header, librariesCompatibleWithPlatform(libraries, platform))
144+
library = findBestLibraryWithHeader(header, librariesCompatibleWithPlatform(libraries, platform, true))
145145
}
146146
}
147147

@@ -150,6 +150,12 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
150150
}
151151

152152
if library == nil {
153+
// reorder libraries to promote fully compatible ones
154+
for _, platform := range platforms {
155+
if platform != nil {
156+
libraries = append(librariesCompatibleWithPlatform(libraries, platform, false), libraries...)
157+
}
158+
}
153159
library = libraries[0]
154160
}
155161

@@ -235,12 +241,12 @@ func libraryCompatibleWithAllPlatforms(library *types.Library) bool {
235241
return false
236242
}
237243

238-
func librariesCompatibleWithPlatform(libraries []*types.Library, platform *types.Platform) []*types.Library {
244+
func librariesCompatibleWithPlatform(libraries []*types.Library, platform *types.Platform, reorder bool) []*types.Library {
239245
var compatibleLibraries []*types.Library
240246
for _, library := range libraries {
241247
compatible, generic := libraryCompatibleWithPlatform(library, platform)
242248
if compatible {
243-
if !generic && len(compatibleLibraries) != 0 && libraryCompatibleWithAllPlatforms(compatibleLibraries[0]) {
249+
if !generic && len(compatibleLibraries) != 0 && libraryCompatibleWithAllPlatforms(compatibleLibraries[0]) && reorder == true {
244250
//priority inversion
245251
compatibleLibraries = append([]*types.Library{library}, compatibleLibraries...)
246252
} else {

0 commit comments

Comments
 (0)