Skip to content

Commit 3d1de92

Browse files
committed
Fix libraries not being recompiled when path to source file changes
1 parent a5b8f16 commit 3d1de92

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

legacy/builder/builder_utils/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,16 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
357357
return false, nil
358358
}
359359

360+
// The first line of the depfile contains the path to the object file to generate.
361+
// The second line of the depfile contains the path to the source file.
362+
// All subsequent lines contain the header files necessary to compile the object file.
363+
364+
// If we don't do this check it might happen that trying to compile a source file
365+
// that has the same name but a different path wouldn't recreate the object file.
366+
if sourceFile.String() != strings.Trim(rows[1], " ") {
367+
return false, nil
368+
}
369+
360370
rows = rows[1:]
361371
for _, row := range rows {
362372
depStat, err := os.Stat(row)

test/test_compile.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,3 +953,46 @@ def test_compile_with_library_priority(run_command, data_dir):
953953
f" Not used: {cli_installed_lib_path}",
954954
]
955955
assert "\n".join(expected_output) in res.stdout
956+
957+
958+
def test_recompile_with_different_library(run_command, data_dir):
959+
assert run_command("update")
960+
961+
assert run_command("core install arduino:[email protected]")
962+
963+
sketch_name = "RecompileCompileSketchWithDifferentLibrary"
964+
sketch_path = Path(data_dir, sketch_name)
965+
fqbn = "arduino:avr:uno"
966+
967+
# Install library
968+
assert run_command("lib install WiFi101")
969+
970+
# Manually installs the same library already installed
971+
git_url = "https://github.com/arduino-libraries/WiFi101.git"
972+
manually_install_lib_path = Path(data_dir, "my-libraries", "WiFi101")
973+
assert Repo.clone_from(git_url, manually_install_lib_path, multi_options=["-b 0.16.1"])
974+
975+
# Create new sketch and add library include
976+
assert run_command(f"sketch new {sketch_path}")
977+
sketch_file = sketch_path / f"{sketch_name}.ino"
978+
lines = []
979+
with open(sketch_file, "r") as f:
980+
lines = f.readlines()
981+
lines = ["#include <WiFi101.h>"] + lines
982+
with open(sketch_file, "w") as f:
983+
f.writelines(lines)
984+
985+
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
986+
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
987+
988+
# Compile sketch using library not managed by CLI
989+
res = run_command(f"compile -b {fqbn} --library {manually_install_lib_path} {sketch_path} -v")
990+
assert res.ok
991+
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
992+
assert f"Using previously compiled file: {obj_path}" not in res.stdout
993+
994+
# Compile again using library installed from CLI
995+
res = run_command(f"compile -b {fqbn} {sketch_path} -v")
996+
assert res.ok
997+
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
998+
assert f"Using previously compiled file: {obj_path}" not in res.stdout

0 commit comments

Comments
 (0)