8000 Add `--library` flag to `compile` command by silvanocerza · Pull Request #1258 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Add --library flag to compile command #1258

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 5 commits into from
Apr 13, 2021
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
Fix libraries not being recompiled when path to source file changes
  • Loading branch information
silvanocerza committed Apr 9, 2021
commit 3d1de92a480d2a225d26ba2335ef489d3abac78d
10 changes: 10 additions & 0 deletions legacy/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
return false, nil
}

// The first line of the depfile contains the path to the object file to generate.
// The second line of the depfile contains the path to the source file.
// All subsequent lines contain the header files necessary to compile the object file.

// If we don't do this check it might happen that trying to compile a source file
// that has the same name but a different path wouldn't recreate the object file.
if sourceFile.String() != strings.Trim(rows[1], " ") {
return false, nil
}

rows = rows[1:]
for _, row := range rows {
depStat, err := os.Stat(row)
Expand Down
43 changes: 43 additions & 0 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,3 +953,46 @@ def test_compile_with_library_priority(run_command, data_dir):
f" Not used: {cli_installed_lib_path}",
]
assert "\n".join(expected_output) in res.stdout


def test_recompile_with_different_library(run_command, data_dir):
assert run_command("update")

assert run_command("core install arduino:avr@1.8.3")

sketch_name = "RecompileCompileSketchWithDifferentLibrary"
sketch_path = Path(data_dir, sketch_name)
fqbn = "arduino:avr:uno"

# Install library
assert run_command("lib install WiFi101")

# Manually installs the same library already installed
git_url = "https://github.com/arduino-libraries/WiFi101.git"
manually_install_lib_path = Path(data_dir, "my-libraries", "WiFi101")
assert Repo.clone_from(git_url, manually_install_lib_path, multi_options=["-b 0.16.1"])

# Create new sketch and add library include
assert run_command(f"sketch new {sketch_path}")
sketch_file = sketch_path / f"{sketch_name}.ino"
lines = []
with open(sketch_file, "r") as f:
lines = f.readlines()
lines = ["#include <WiFi101.h>"] + lines
with open(sketch_file, "w") as f:
f.writelines(lines)

sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")

# Compile sketch using library not managed by CLI
res = run_command(f"compile -b {fqbn} --library {manually_install_lib_path} {sketch_path} -v")
assert res.ok
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
assert f"Using previously compiled file: {obj_path}" not in res.stdout

# Compile again using library installed from CLI
res = run_command(f"compile -b {fqbn} {sketch_path} -v")
assert res.ok
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
assert f"Using previously compiled file: {obj_path}" not in res.stdout
0