Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 00194d2

Browse files
committedJun 6, 2023
Moved ResolveLibrary function in the correct source file
1 parent d6c25ae commit 00194d2

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
@@ -455,3 +455,48 @@ func queueSourceFilesFromFolder(ctx *types.Context, sourceFileQueue *types.Uniqu
455455

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

‎legacy/builder/resolve_library.go

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

0 commit comments

Comments
 (0)
Please sign in to comment.