Skip to content

Commit 7b79ec8

Browse files
committed
Compiler now read progress through GRPC
1 parent b8e8e78 commit 7b79ec8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

arduino-core/src/cc/arduino/Compiler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ public String build(List<CompilerProgressListener> progListeners, boolean export
207207

208208
CompileResult result;
209209
try {
210-
MessageConsumerOutputStream out = new MessageConsumerOutputStream(new ProgressAwareMessageConsumer(new I18NAwareMessageConsumer(System.out, System.err), progListeners), "\n");
210+
MessageConsumerOutputStream out = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.out, System.err), "\n");
211211
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.err, this), "\n");
212212

213-
result = core.compile(req.build(), out, err);
213+
result = core.compile(req.build(), out, err, progListeners);
214214

215215
out.flush();
216216
err.flush();
@@ -221,7 +221,7 @@ public String build(List<CompilerProgressListener> progListeners, boolean export
221221
if (exception != null)
222222
throw exception;
223223

224-
if (result == CompileResult.error) {
224+
if (result == CompileResult.compile_error) {
225225
RunnerException re = new RunnerException(I18n.format(tr("Error compiling for board {0}."), board.getName()));
226226
re.hideStackTrace();
227227
throw re;

arduino-core/src/cc/arduino/cli/ArduinoCoreInstance.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import com.google.protobuf.ByteString;
4141

42+
import cc.arduino.CompilerProgressListener;
4243
import cc.arduino.cli.commands.ArduinoCoreGrpc.ArduinoCoreBlockingStub;
4344
import cc.arduino.cli.commands.Board.BoardDetailsReq;
4445
import cc.arduino.cli.commands.Board.BoardDetailsResp;
@@ -91,14 +92,14 @@ public void boardDetails(String fqbn) throws StatusException {
9192
}
9293
}
9394

94-
public CompileResult compile(CompileReq req, OutputStream out,
95-
OutputStream err) throws StatusException {
95+
public CompileResult compile(CompileReq req, OutputStream out, OutputStream err,
96+
List<CompilerProgressListener> progressListeners) throws StatusException {
9697
req = CompileReq.newBuilder(req) //
9798
.setInstance(instance) //
9899
.build();
99100
try {
100101
Iterator<CompileResp> stream = stub.compile(req);
101-
CompileResult result = CompileResult.error;
102+
CompileResult result = CompileResult.compile_error;
102103
while (stream.hasNext()) {
103104
CompileResp resp = stream.next();
104105
try {
@@ -108,6 +109,13 @@ public CompileResult compile(CompileReq req, OutputStream out,
108109
ByteString errdata = resp.getErrStream();
109110
if (errdata != null)
110111
err.write(errdata.toByteArray());
112+
TaskProgress taskProgress = resp.getTaskProgress();
113+
if (taskProgress != null) {
114+
float progress = taskProgress.getPercentCompleted();
115+
if (progress > 0) {
116+
progressListeners.forEach(l -> l.progress((int) progress));
117+
}
118+
}
111119
} catch (IOException e) {
112120
e.printStackTrace();
113121
}

0 commit comments

Comments
 (0)