8000 [skip-changelog] legacy: some simple refactorings by cmaglie · Pull Request #2206 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

[skip-changelog] legacy: some simple refactorings #2206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved ResolveLibrary function in the correct source file
  • Loading branch information
cmaglie committed Jun 7, 2023
commit 49405ac296b26435cefc6c2a08cbd4b2ce0a0a4b
45 changes: 45 additions & 0 deletions legacy/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,48 @@ func queueSourceFilesFromFolder(ctx *types.Context, sourceFileQueue *types.Uniqu

return nil
}

func ResolveLibrary(ctx *types.Context, header string) *libraries.Library {
resolver := ctx.LibrariesResolver
importedLibraries := ctx.ImportedLibraries

candidates := resolver.AlternativesFor(header)

if ctx.Verbose {
ctx.Info(tr("Alternatives for %[1]s: %[2]s", header, candidates))
ctx.Info(fmt.Sprintf("ResolveLibrary(%s)", header))
ctx.Info(fmt.Sprintf(" -> %s: %s", tr("candidates"), candidates))
}

if len(candidates) == 0 {
return nil
}

for _, candidate := range candidates {
if importedLibraries.Contains(candidate) {
return nil
}
}

selected := resolver.ResolveFor(header, ctx.TargetPlatform.Platform.Architecture)
if alreadyImported := importedLibraries.FindByName(selected.Name); alreadyImported != nil {
// Certain libraries might have the same name but be different.
// This usually happens when the user includes two or more custom libraries that have
// different header name but are stored in a parent folder with identical name, like
// ./libraries1/Lib/lib1.h and ./libraries2/Lib/lib2.h
// Without this check the library resolution would be stuck in a loop.
// This behaviour has been reported in this issue:
// https://github.com/arduino/arduino-cli/issues/973
if selected == alreadyImported {
selected = alreadyImported
}
}

candidates.Remove(selected)
ctx.LibrariesResolutionResults[header] = types.LibraryResolutionResult{
Library: selected,
NotUsedLibraries: candidates,
}

return selected
}
68 changes: 0 additions & 68 deletions legacy/builder/resolve_library.go

This file was deleted.

0