Skip to content

Fix compile command stuck in a loop when including multiple custom libraries #1066

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 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion legacy/builder/resolve_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ func ResolveLibrary(ctx *types.Context, header string) *libraries.Library {

selected := resolver.ResolveFor(header, ctx.TargetPlatform.Platform.Architecture)
if alreadyImported := importedLibraries.FindByName(selected.Name); alreadyImported != nil {
selected = alreadyImported
// 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
}
}

ctx.LibrariesResolutionResults[header] = types.LibraryResolutionResult{
Expand Down
21 changes: 21 additions & 0 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,24 @@ def test_compile_with_invalid_url(run_command, data_dir):
assert "Error creating instance: error loading platform index:" in lines
expected_index_file = Path(data_dir, "package_example_index.json")
assert f"loading json index file {expected_index_file}: " + f"open {expected_index_file}:" in lines[-1]


def test_compile_with_custom_libraries(run_command, copy_sketch):
# Creates config with additional URL to install necessary core
url = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
assert run_command(f"config init --dest-dir . --additional-urls {url}")

# Init the environment explicitly
assert run_command("update")

# Install core to compile
assert run_command("core install esp8266:esp8266")

sketch_path = copy_sketch("sketch_with_multiple_custom_libraries")
fqbn = "esp8266:esp8266:nodemcu:xtal=80,vt=heap,eesz=4M1M,wipe=none,baud=115200"

first_lib = Path(sketch_path, "libraries1")
second_lib = Path(sketch_path, "libraries2")
# This compile command has been taken from this issue:
# https://github.com/arduino/arduino-cli/issues/973
assert run_command(f"compile --libraries {first_lib},{second_lib} -b {fqbn} {sketch_path}")
Loading