Skip to content

Commit f55fe64

Browse files
committed
Moved ResolveLibrary function in the correct source file
1 parent 0b7a8b0 commit f55fe64

File tree

2 files changed

+45
-68
lines changed

2 files changed

+45
-68
lines changed

legacy/builder/container_find_includes.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,48 @@ func queueSourceFilesFromFolder(ctx *types.Context, queue *types.UniqueSourceFil
445445

446446
return nil
447447
}
448+
449+
func ResolveLibrary(ctx *types.Context, header string) *libraries.Library {
450+
resolver := ctx.LibrariesResolver
451+
importedLibraries := ctx.ImportedLibraries
452+
453+
candidates := resolver.AlternativesFor(header)
454+
455+
if ctx.Verbose {
456+
ctx.Info(tr("Alternatives for %[1]s: %[2]s", header, candidates))
457+
ctx.Info(fmt.Sprintf("ResolveLibrary(%s)", header))
458+
ctx.Info(fmt.Sprintf(" -> %s: %s", tr("candidates"), candidates))
459+
}
460+
461+
if len(candidates) == 0 {
462+
return nil
463+
}
464+
465+
for _, candidate := range candidates {
466+
if importedLibraries.Contains(candidate) {
467+
return nil
468+
}
469+
}
470+
471+
selected := resolver.ResolveFor(header, ctx.TargetPlatform.Platform.Architecture)
472+
if alreadyImported := importedLibraries.FindByName(selected.Name); alreadyImported != nil {
473+
// Certain libraries might have the same name but be different.
474+
// This usually happens when the user includes two or more custom libraries that have
475+
// different header name but are stored in a parent folder with identical name, like
476+
// ./libraries1/Lib/lib1.h and ./libraries2/Lib/lib2.h
477+
// Without this check the library resolution would be stuck in a loop.
478+
// This behaviour has been reported in this issue:
479+
// https://github.com/arduino/arduino-cli/issues/973
480+
if selected == alreadyImported {
481+
selected = alreadyImported
482+
}
483+
}
484+
485+
candidates.Remove(selected)
486+
ctx.LibrariesResolutionResults[header] = types.LibraryResolutionResult{
487+
Library: selected,
488+
NotUsedLibraries: candidates,
489+
}
490+
491+
return selected
492+
}

legacy/builder/resolve_library.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)