mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Compiler now read progress through GRPC
This commit is contained in:
parent
b8e8e7842d
commit
7b79ec848e
@ -207,10 +207,10 @@ public class Compiler implements MessageConsumer {
|
|||||||
|
|
||||||
CompileResult result;
|
CompileResult result;
|
||||||
try {
|
try {
|
||||||
MessageConsumerOutputStream out = new MessageConsumerOutputStream(new ProgressAwareMessageConsumer(new I18NAwareMessageConsumer(System.out, System.err), progListeners), "\n");
|
MessageConsumerOutputStream out = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.out, System.err), "\n");
|
||||||
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.err, this), "\n");
|
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.err, this), "\n");
|
||||||
|
|
||||||
result = core.compile(req.build(), out, err);
|
result = core.compile(req.build(), out, err, progListeners);
|
||||||
|
|
||||||
out.flush();
|
out.flush();
|
||||||
err.flush();
|
err.flush();
|
||||||
@ -221,7 +221,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
if (exception != null)
|
if (exception != null)
|
||||||
throw exception;
|
throw exception;
|
||||||
|
|
||||||
if (result == CompileResult.error) {
|
if (result == CompileResult.compile_error) {
|
||||||
RunnerException re = new RunnerException(I18n.format(tr("Error compiling for board {0}."), board.getName()));
|
RunnerException re = new RunnerException(I18n.format(tr("Error compiling for board {0}."), board.getName()));
|
||||||
re.hideStackTrace();
|
re.hideStackTrace();
|
||||||
throw re;
|
throw re;
|
||||||
|
@ -39,6 +39,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
|
||||||
|
import cc.arduino.CompilerProgressListener;
|
||||||
import cc.arduino.cli.commands.ArduinoCoreGrpc.ArduinoCoreBlockingStub;
|
import cc.arduino.cli.commands.ArduinoCoreGrpc.ArduinoCoreBlockingStub;
|
||||||
import cc.arduino.cli.commands.Board.BoardDetailsReq;
|
import cc.arduino.cli.commands.Board.BoardDetailsReq;
|
||||||
import cc.arduino.cli.commands.Board.BoardDetailsResp;
|
import cc.arduino.cli.commands.Board.BoardDetailsResp;
|
||||||
@ -91,14 +92,14 @@ public class ArduinoCoreInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompileResult compile(CompileReq req, OutputStream out,
|
public CompileResult compile(CompileReq req, OutputStream out, OutputStream err,
|
||||||
OutputStream err) throws StatusException {
|
List<CompilerProgressListener> progressListeners) throws StatusException {
|
||||||
req = CompileReq.newBuilder(req) //
|
req = CompileReq.newBuilder(req) //
|
||||||
.setInstance(instance) //
|
.setInstance(instance) //
|
||||||
.build();
|
.build();
|
||||||
try {
|
try {
|
||||||
Iterator<CompileResp> stream = stub.compile(req);
|
Iterator<CompileResp> stream = stub.compile(req);
|
||||||
CompileResult result = CompileResult.error;
|
CompileResult result = CompileResult.compile_error;
|
||||||
while (stream.hasNext()) {
|
while (stream.hasNext()) {
|
||||||
CompileResp resp = stream.next();
|
CompileResp resp = stream.next();
|
||||||
try {
|
try {
|
||||||
@ -108,6 +109,13 @@ public class ArduinoCoreInstance {
|
|||||||
ByteString errdata = resp.getErrStream();
|
ByteString errdata = resp.getErrStream();
|
||||||
if (errdata != null)
|
if (errdata != null)
|
||||||
err.write(errdata.toByteArray());
|
err.write(errdata.toByteArray());
|
||||||
|
TaskProgress taskProgress = resp.getTaskProgress();
|
||||||
|
if (taskProgress != null) {
|
||||||
|
float progress = taskProgress.getPercentCompleted();
|
||||||
|
if (progress > 0) {
|
||||||
|
progressListeners.forEach(l -> l.progress((int) progress));
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user