Skip to content

Commit e8889eb

Browse files
authored
Fix compile command stuck in a loop when including multiple custom libraries (#1066)
1 parent dcab980 commit e8889eb

File tree

6 files changed

+627
-1
lines changed

6 files changed

+627
-1
lines changed

legacy/builder/resolve_library.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ func ResolveLibrary(ctx *types.Context, header string) *libraries.Library {
4848

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

5463
ctx.LibrariesResolutionResults[header] = types.LibraryResolutionResult{

test/test_compile.py

+21
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,24 @@ def test_compile_with_invalid_url(run_command, data_dir):
564564
assert "Error creating instance: error loading platform index:" in lines
565565
expected_index_file = Path(data_dir, "package_example_index.json")
566566
assert f"loading json index file {expected_index_file}: " + f"open {expected_index_file}:" in lines[-1]
567+
568+
569+
def test_compile_with_custom_libraries(run_command, copy_sketch):
570+
# Creates config with additional URL to install necessary core
571+
url = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
572+
assert run_command(f"config init --dest-dir . --additional-urls {url}")
573+
574+
# Init the environment explicitly
575+
assert run_command("update")
576+
577+
# Install core to compile
578+
assert run_command("core install esp8266:esp8266")
579+
580+
sketch_path = copy_sketch("sketch_with_multiple_custom_libraries")
581+
fqbn = "esp8266:esp8266:nodemcu:xtal=80,vt=heap,eesz=4M1M,wipe=none,baud=115200"
582+
583+
first_lib = Path(sketch_path, "libraries1")
584+
second_lib = Path(sketch_path, "libraries2")
585+
# This compile command has been taken from this issue:
586+
# https://github.com/arduino/arduino-cli/issues/973
587+
assert run_command(f"compile --libraries {first_lib},{second_lib} -b {fqbn} {sketch_path}")

0 commit comments

Comments
 (0)