Skip to content

Commit db21521

Browse files
committed
turbine support worker mode
1 parent a1cd9bf commit db21521

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ package(
77

88
java_binary(
99
name = "turbine_direct_binary",
10-
main_class = "com.google.turbine.main.Main",
10+
main_class = "com.google.devtools.build.java.turbine.TurbineWorkerWrapper",
11+
srcs = ["TurbineWorkerWrapper.java"],
12+
deps = [
13+
"//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers",
14+
"//third_party:turbine",
15+
],
1116
runtime_deps = [
1217
"//src/main/protobuf:deps_java_proto",
1318
"//third_party:guava",
1419
"//third_party:jsr305",
15-
"//third_party:turbine",
1620
],
1721
)
1822

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.google.devtools.build.java.turbine;
2+
3+
import com.google.turbine.main.Main;
4+
import com.google.devtools.build.lib.worker.ProtoWorkerMessageProcessor;
5+
import com.google.devtools.build.lib.worker.WorkRequestHandler;
6+
7+
import java.io.IOException;
8+
import java.io.PrintWriter;
9+
import java.time.Duration;
10+
import java.util.List;
11+
12+
/**
13+
* A Wrapper for Turbine to support multiplex worker
14+
*/
15+
public class TurbineWorkerWrapper {
16+
17+
public static void main(String[] args) throws IOException {
18+
if (args.length == 1 && args[0].equals("--persistent_worker")) {
19+
WorkRequestHandler workerHandler =
20+
new WorkRequestHandler.WorkRequestHandlerBuilder(
21+
TurbineWorkerWrapper::turbine,
22+
System.err,
23+
new ProtoWorkerMessageProcessor(System.in, System.out))
24+
.setCpuUsageBeforeGc(Duration.ofSeconds(10))
25+
.build();
26+
int exitCode = 1;
27+
try {
28+
workerHandler.processRequests();
29+
exitCode = 0;
30+
} catch (IOException e) {
31+
System.err.println(e.getMessage());
32+
} finally {
33+
// Prevent hanging threads from keeping the worker alive.
34+
System.exit(exitCode);
35+
}
36+
} else {
37+
Main.main(args);
38+
}
39+
}
40+
41+
private static int turbine(List<String> args, PrintWriter pw) {
42+
try {
43+
Main.compile(args.toArray(new String[0]));
44+
} catch (Throwable e) {
45+
System.err.println(e.getMessage());
46+
return 1;
47+
}
48+
return 0;
49+
}
50+
51+
}

src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static Builder newBuilder(RuleContext ruleContext) {
132132
public static final class Builder {
133133

134134
private static final ParamFileInfo PARAM_FILE_INFO =
135-
ParamFileInfo.builder(UNQUOTED).setCharset(ISO_8859_1).build();
135+
ParamFileInfo.builder(UNQUOTED).setCharset(ISO_8859_1).setUseAlways(true).build();
136136

137137
private final RuleContext ruleContext;
138138

@@ -457,6 +457,11 @@ public void build(JavaToolchainProvider javaToolchain) {
457457
ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS,
458458
outputDepsProto.getExecPathString());
459459
}
460+
executionInfo = ImmutableMap.<String, String>builder()
461+
.putAll(executionInfo)
462+
.putAll(ExecutionRequirements.WORKER_MODE_ENABLED)
463+
.putAll(ExecutionRequirements.WORKER_MULTIPLEX_MODE_ENABLED)
464+
.build();
460465
if (useDirectClasspath) {
461466
NestedSet<Artifact> classpath;
462467
if (!directJars.isEmpty() || classpathEntries.isEmpty()) {
@@ -485,7 +490,7 @@ public void build(JavaToolchainProvider javaToolchain) {
485490
ruleContext.registerAction(
486491
new JavaHeaderCompileAction(
487492
/* owner= */ ruleContext.getActionOwner(),
488-
/* tools= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER),
493+
/* tools= */ headerCompiler.tool().getFilesToRun(),
489494
/* inputs= */ allInputs,
490495
/* outputs= */ outputs.build(),
491496
/* resourceSetOrBuilder= */ AbstractAction.DEFAULT_RESOURCE_SET,

0 commit comments

Comments
 (0)