Skip to content

Commit 3a5465d

Browse files
committed
Moved ResolveLibrary function in the correct source file
1 parent 75e10de commit 3a5465d

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
@@ -426,3 +426,48 @@ func queueSourceFilesFromFolder(ctx *types.Context, queue *types.UniqueSourceFil
426426

427427
return nil
428428
}
429+
430+
func ResolveLibrary(ctx *types.Context, header string) *libraries.Library {
431+
resolver := ctx.LibrariesResolver
432+
importedLibraries := ctx.ImportedLibraries
433+
434+
candidates := resolver.AlternativesFor(header)
435+
436+
if ctx.Verbose {
437+
ctx.Info(tr("Alternatives for %[1]s: %[2]s", header, candidates))
438+
ctx.Info(fmt.Sprintf("ResolveLibrary(%s)", header))
439+
ctx.Info(fmt.Sprintf(" -> %s: %s", tr("candidates"), candidates))
440+
}
441+
442+
if len(candidates) == 0 {
443+
return nil
444+
}
445+
446+
for _, candidate := range candidates {
447+
if importedLibraries.Contains(candidate) {
448+
return nil
449+
}
450+
}
451+
452+
selected := resolver.ResolveFor(header, ctx.TargetPlatform.Platform.Architecture)
453+
if alreadyImported := importedLibraries.FindByName(selected.Name); alreadyImported != nil {
454+
// Certain libraries might have the same name but be different.
455+
// This usually happens when the user includes two or more custom libraries that have
456+
// different header name but are stored in a parent folder with identical name, like
457+
// ./libraries1/Lib/lib1.h and ./libraries2/Lib/lib2.h
458+
// Without this check the library resolution would be stuck in a loop.
459+
// This behaviour has been reported in this issue:
460+
// https://github.com/arduino/arduino-cli/issues/973
461+
if selected == alreadyImported {
462+
selected = alreadyImported
463+
}
464+
}
465+
466+
candidates.Remove(selected)
467+
ctx.LibrariesResolutionResults[header] = types.LibraryResolutionResult{
468+
Library: selected,
469+
NotUsedLibraries: candidates,
470+
}
471+
472+
return selected
473+
}

legacy/builder/resolve_library.go

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

0 commit comments

Comments
 (0)