Skip to content

Commit

Permalink
Handle priority inversion for promoted bundled libraries
Browse files Browse the repository at this point in the history
Fixes arduino/Arduino#4064

Signed-off-by: Martino Facchin <m.facchin@arduino.cc>
  • Loading branch information
facchinm committed Mar 4, 2016
1 parent 34d5b8d commit 4debb62
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/arduino.cc/builder/includes_to_include_folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
var library *types.Library

for _, platform := range platforms {
if platform != nil && library == nil {
if platform != nil {
library = findBestLibraryWithHeader(header, librariesCompatibleWithPlatform(libraries, platform))
}
}
Expand Down Expand Up @@ -218,21 +218,34 @@ func findLibraryIn(libraries []*types.Library, library *types.Library) *types.Li
return nil
}

func libraryCompatibleWithPlatform(library *types.Library, platform *types.Platform) bool {
func libraryCompatibleWithPlatform(library *types.Library, platform *types.Platform) (bool, bool) {
if len(library.Archs) == 0 {
return true
return true, true
}
if utils.SliceContains(library.Archs, constants.LIBRARY_ALL_ARCHS) {
return true, true
}
return utils.SliceContains(library.Archs, platform.PlatformId), false
}

func libraryCompatibleWithAllPlatforms(library *types.Library) bool {
if utils.SliceContains(library.Archs, constants.LIBRARY_ALL_ARCHS) {
return true
}
return utils.SliceContains(library.Archs, platform.PlatformId)
return false
}

func librariesCompatibleWithPlatform(libraries []*types.Library, platform *types.Platform) []*types.Library {
var compatibleLibraries []*types.Library
for _, library := range libraries {
if libraryCompatibleWithPlatform(library, platform) {
compatibleLibraries = append(compatibleLibraries, library)
compatible, generic := libraryCompatibleWithPlatform(library, platform)
if compatible {
if !generic && len(compatibleLibraries) != 0 && libraryCompatibleWithAllPlatforms(compatibleLibraries[0]) {
//priority inversion
compatibleLibraries = append([]*types.Library{library}, compatibleLibraries...)
} else {
compatibleLibraries = append(compatibleLibraries, library)
}
}
}

Expand Down

0 comments on commit 4debb62

Please sign in to comment.