Skip to content

Commit 1d601c5

Browse files
committed
Fix compile and upload with custom build path
1 parent 39a3025 commit 1d601c5

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

cli/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func run(cmd *cobra.Command, args []string) {
141141
Port: port,
142142
Verbose: verbose,
143143
Verify: verify,
144-
ImportDir: exportDir,
144+
ImportDir: buildPath,
145145
Programmer: programmer,
146146
}, os.Stdout, os.Stderr)
147147

test/test_compile.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,44 @@ def test_compile_with_export_binaries_flag(run_command, data_dir):
299299
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.hex").exists()
300300
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.bin").exists()
301301
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.hex").exists()
302+
303+
304+
def test_compile_with_custom_build_path(run_command, data_dir):
305+
# Init the environment explicitly
306+
run_command("core update-index")
307+
308+
# Download latest AVR
309+
run_command("core install arduino:avr")
310+
311+
sketch_name = "CompileWithBuildPath"
312+
sketch_path = Path(data_dir, sketch_name)
313+
fqbn = "arduino:avr:uno"
314+
315+
# Create a test sketch
316+
result = run_command(f"sketch new {sketch_path}")
317+
assert result.ok
318+
assert f"Sketch created in: {sketch_path}" in result.stdout
319+
320+
# Test the --build-path flag with absolute path
321+
build_path = Path(data_dir, "test_dir", "build_dir")
322+
result = run_command(f"compile -b {fqbn} {sketch_path} --build-path {build_path}")
323+
print(result.stderr)
324+
assert result.ok
325+
326+
# Verifies expected binaries have been built to build_path
327+
assert build_path.exists()
328+
assert build_path.is_dir()
329+
assert (build_path / f"{sketch_name}.ino.eep").exists()
330+
assert (build_path / f"{sketch_name}.ino.elf").exists()
331+
assert (build_path / f"{sketch_name}.ino.hex").exists()
332+
assert (build_path / f"{sketch_name}.ino.with_bootloader.bin").exists()
333+
assert (build_path / f"{sketch_name}.ino.with_bootloader.hex").exists()
334+
335+
# Verifies there are no binaries in temp directory
336+
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
337+
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
338+
assert not (build_dir / f"{sketch_name}.ino.eep").exists()
339+
assert not (build_dir / f"{sketch_name}.ino.elf").exists()
340+
assert not (build_dir / f"{sketch_name}.ino.hex").exists()
341+
assert not (build_dir / f"{sketch_name}.ino.with_bootloader.bin").exists()
342+
assert not (build_dir / f"{sketch_name}.ino.with_bootloader.hex").exists()

test/test_upload.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,42 @@ def run_test(s):
156156

157157
run_test(sketch_path)
158158
run_test(sketch_main_file)
159+
160+
161+
def test_compile_and_upload_combo_with_custom_build_path(run_command, data_dir, detected_boards, wait_for_board):
162+
# Init the environment explicitly
163+
run_command("core update-index")
164+
165+
# Install required core(s)
166+
run_command("core install arduino:avr@1.8.3")
167+
run_command("core install arduino:samd@1.8.6")
168+
169+
sketch_name = "CompileAndUploadCustomBuildPathIntegrationTest"
170+
sketch_path = Path(data_dir, sketch_name)
171+
assert run_command(f"sketch new {sketch_path}")
172+
173+
for board in detected_boards:
174+
fqbn_normalized = board.fqbn.replace(":", "-")
175+
log_file_name = f"{fqbn_normalized}-compile.log"
176+
log_file = Path(data_dir, log_file_name)
177+
command_log_flags = f"--log-format json --log-file {log_file} --log-level trace"
178+
179+
wait_for_board()
180+
181+
build_path = Path(data_dir, "test_dir", fqbn_normalized, "build_dir")
182+
result = run_command(
183+
f"compile -b {board.fqbn} "
184+
+ f"--upload -p {board.address} "
185+
+ f"--build-path {build_path} "
186+
+ f"{sketch_path} {command_log_flags}"
187+
)
188+
print(result.stderr)
189+
assert result.ok
190+
191+
# check from the logs if the bin file were uploaded on the current board
192+
log_json = open(log_file, "r")
193+
traces = parse_json_traces(log_json.readlines())
194+
assert f"Compile {sketch_path} for {board.fqbn} started" in traces
195+
assert f"Compile {sketch_name} for {board.fqbn} successful" in traces
196+
assert f"Upload {sketch_path} on {board.fqbn} started" in traces
197+
assert "Upload successful" in traces

0 commit comments

Comments
 (0)