From 6ce39b4a460e39d22d9e15ffe3a971ec6c2fb92a Mon Sep 17 00:00:00 2001 From: janakr Date: Tue, 24 Nov 2020 15:42:01 -0800 Subject: [PATCH] Only show the progress bar after printing stdout/stderr if the printing cleared the progress bar. I'm not sure how to add a test for this because the fancy terminal overwriting the ui does isn't really compatible with our test infrastructure for assertions on blaze output. Will keep on trying, but wanted to fix the bug first. PiperOrigin-RevId: 344144890 --- .../devtools/build/lib/runtime/UiEventHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/runtime/UiEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/UiEventHandler.java index e7962a16b9047c..215e60f0191e90 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/UiEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/UiEventHandler.java @@ -303,8 +303,9 @@ private void handleLocked(Event event, @Nullable byte[] stdout, @Nullable byte[] stream.write(event.getMessageBytes()); stream.flush(); } else { - writeToStream(stream, event.getKind(), event.getMessageBytes()); - if (showProgress && cursorControl) { + boolean clearedProgress = + writeToStream(stream, event.getKind(), event.getMessageBytes()); + if (clearedProgress && showProgress && cursorControl) { addProgressBar(); } terminal.flush(); @@ -452,14 +453,14 @@ public void handle(Event event) { handleInternal(event); } - private void writeToStream(OutputStream stream, EventKind eventKind, byte[] message) + private boolean writeToStream(OutputStream stream, EventKind eventKind, byte[] message) throws IOException { int eolIndex = Bytes.lastIndexOf(message, (byte) '\n'); ByteArrayOutputStream outLineBuffer = eventKind == EventKind.STDOUT ? stdoutLineBuffer : stderrLineBuffer; if (eolIndex < 0) { outLineBuffer.write(message); - return; + return false; } clearProgressBar(); @@ -473,6 +474,7 @@ private void writeToStream(OutputStream stream, EventKind eventKind, byte[] mess stream.flush(); outLineBuffer.write(message, eolIndex + 1, message.length - eolIndex - 1); + return true; } private void setEventKindColor(EventKind kind) throws IOException {