Simplify BazelWorker print handling
*/
package com.google.j2cl.bazel;
-import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
@@ -23,10 +22,8 @@ import com.google.common.io.Files;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse;
import com.google.j2cl.common.Problems;
-import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
@@ -74,20 +71,14 @@ public abstract class BazelWorker {
if (args.length == 1 && args[0].equals("--persistent_worker")) {
runPersistentWorker(workerSupplier);
} else {
- runStandaloneWorker(workerSupplier, args);
+ runStandaloneWorker(workerSupplier, expandFlagFile(args));
}
}
private static void runStandaloneWorker(Supplier<BazelWorker> workerSupplier, String[] args)
throws IOException {
// This is a single invocation of builder that exits after it processed the request.
-
- // DO NOT close the err PrintWriter, since it will close the System.err stream and swallow
- // whatever gets sent to it, e.g. exception stack trace.
- PrintWriter err =
- new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)));
- int exitCode = execute(workerSupplier, expandFlagFile(args), err);
- err.flush();
+ int exitCode = workerSupplier.get().processRequest(args).reportAndGetExitCode(System.err);
System.exit(exitCode);
}
@@ -99,10 +90,10 @@ public abstract class BazelWorker {
break;
}
- try (StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw)) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
String[] args = request.getArgumentsList().toArray(new String[0]);
- int exitCode = execute(workerSupplier, args, pw);
+ int exitCode = workerSupplier.get().processRequest(args).reportAndGetExitCode(pw);
WorkResponse.newBuilder()
.setOutput(sw.toString())
.setExitCode(exitCode)
@@ -116,12 +107,6 @@ public abstract class BazelWorker {
System.gc();
}
}
- }
-
- private static final int execute(
- Supplier<BazelWorker> workerSupplier, String[] args, PrintWriter err) {
- return workerSupplier.get().processRequest(args).reportAndGetExitCode(err);
- }
/**
* Loads a potential flag file and returns the flags. Flag files are only allowed as the last
