Skip to content

Commit 794c664

Browse files
committed
Fix compile command stuck in a loop when including multiple custom libraries
1 parent df9f204 commit 794c664

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

legacy/builder/resolve_library.go

Lines changed: 10 additions & 1 deletion
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+
// ./Lib1/src/lib1.h and ./Lib2/src/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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,24 @@ def test_compile_with_export_binaries_config(run_command, data_dir, downloads_di
538538
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.hex").exists()
539539
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.bin").exists()
540540
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.hex").exists()
541+
542+
543+
def test_compile_with_custom_libraries(run_command, copy_sketch):
544+
# Init the environment explicitly
545+
assert run_command("update")
546+
547+
# Creates config with additional URL to install necessary core
548+
url = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
549+
assert run_command(f"config init --additional-urls {url}")
550+
551+
# Install core to compile
552+
assert run_command("core install esp8266:esp8266")
553+
554+
sketch_path = copy_sketch("sketch_with_multiple_custom_libraries")
555+
fqbn = "esp8266:esp8266:nodemcu:xtal=80,vt=heap,eesz=4M1M,wipe=none,baud=115200"
556+
557+
first_lib = Path(sketch_path, "libraries", "Lib1")
558+
second_lib = Path(sketch_path, "libraries", "Lib2")
559+
# This compile command has been taken from this issue:
560+
# https://github.com/arduino/arduino-cli/issues/973
561+
assert run_command(f"compile --libraries {first_lib},{second_lib} -b {fqbn} {sketch_path}")

test/testdata/sketch_with_multiple_custom_libraries/libraries/Lib1/src/lib1.h

Whitespace-only changes.

test/testdata/sketch_with_multiple_custom_libraries/libraries/Lib2/src/lib2.h

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "lib1.h"
2+
#include "lib2.h"
3+
4+
void setup() {
5+
}
6+
7+
void loop() {
8+
}

0 commit comments

Comments
 (0)