Skip to content

Commit 06d97b0

Browse files
committed
Fix compile error message not printed to correct writer on error
1 parent bb5d778 commit 06d97b0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Diff for: legacy/builder/container_find_includes.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ package builder
9595
import (
9696
"encoding/json"
9797
"fmt"
98-
"os"
9998
"os/exec"
10099
"time"
101100

@@ -378,7 +377,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
378377
return errors.New(tr("Internal error in cache"))
379378
}
380379
}
381-
os.Stderr.Write(preproc_stderr)
380+
ctx.ExecStderr.Write(preproc_stderr)
382381
return errors.WithStack(preproc_err)
383382
}
384383

Diff for: test/test_compile.py

+25
Original file line numberDiff line numberDiff line change
@@ -1252,3 +1252,28 @@ def test_compile_with_relative_build_path(run_command, data_dir, copy_sketch):
12521252
assert "libraries" in built_files
12531253
assert "preproc" in built_files
12541254
assert "sketch" in built_files
1255+
1256+
1257+
def test_compile_error_returned_if_library_not_installed(run_command, copy_sketch):
1258+
assert run_command(["update"])
1259+
1260+
run_command(["core", "install", "arduino:avr@1.8.3"])
1261+
1262+
sketch_name = "sketch_with_sd_library"
1263+
sketch_path = copy_sketch(sketch_name)
1264+
fqbn = "arduino:avr:uno"
1265+
1266+
res = run_command(["compile", "-b", fqbn, "--format", "json", sketch_path])
1267+
assert res.ok
1268+
1269+
compile_output = json.loads(res.stdout)
1270+
1271+
sketch_main_file = f"{Path(sketch_path, sketch_name)}.ino"
1272+
expected_error = (
1273+
f"{sketch_main_file}:2:10: fatal error: SD.h: No such file or directory\n #include <SD.h>\n"
1274+
+ " ^~~~~~\ncompilation terminated.\n"
1275+
)
1276+
1277+
assert not compile_output["success"]
1278+
assert compile_output["compiler_out"] == ""
1279+
assert compile_output["compiler_err"] == expected_error

0 commit comments

Comments
 (0)