Skip to content

Commit a1b3c1d

Browse files
committed
add flag
1 parent db21521 commit a1b3c1d

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

src/java_tools/buildjar/java/com/google/devtools/build/java/turbine/TurbineWorkerWrapper.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.devtools.build.lib.worker.WorkRequestHandler;
66

77
import java.io.IOException;
8+
import java.io.PrintStream;
89
import java.io.PrintWriter;
910
import java.time.Duration;
1011
import java.util.List;
@@ -16,10 +17,13 @@ public class TurbineWorkerWrapper {
1617

1718
public static void main(String[] args) throws IOException {
1819
if (args.length == 1 && args[0].equals("--persistent_worker")) {
20+
PrintStream realStdErr = System.err;
1921
WorkRequestHandler workerHandler =
2022
new WorkRequestHandler.WorkRequestHandlerBuilder(
21-
TurbineWorkerWrapper::turbine,
22-
System.err,
23+
new WorkRequestHandler.WorkRequestCallback(
24+
(request, pw) ->
25+
turbine(request.getArgumentsList(), pw)),
26+
realStdErr,
2327
new ProtoWorkerMessageProcessor(System.in, System.out))
2428
.setCpuUsageBeforeGc(Duration.ofSeconds(10))
2529
.build();
@@ -28,7 +32,7 @@ public static void main(String[] args) throws IOException {
2832
workerHandler.processRequests();
2933
exitCode = 0;
3034
} catch (IOException e) {
31-
System.err.println(e.getMessage());
35+
realStdErr.println(e.getMessage());
3236
} finally {
3337
// Prevent hanging threads from keeping the worker alive.
3438
System.exit(exitCode);
@@ -42,7 +46,7 @@ private static int turbine(List<String> args, PrintWriter pw) {
4246
try {
4347
Main.compile(args.toArray(new String[0]));
4448
} catch (Throwable e) {
45-
System.err.println(e.getMessage());
49+
pw.println(e.getMessage());
4650
return 1;
4751
}
4852
return 0;

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,21 @@ public void build(JavaToolchainProvider javaToolchain) {
449449
}
450450
}
451451

452-
ImmutableMap<String, String> executionInfo =
453-
TargetUtils.getExecutionInfo(ruleContext.getRule(), ruleContext.isAllowTagsPropagation());
452+
ImmutableMap.Builder<String, String> executionInfoBuilder = ImmutableMap.builder();
453+
executionInfoBuilder.putAll(
454+
TargetUtils.getExecutionInfo(ruleContext.getRule(), ruleContext.isAllowTagsPropagation()));
454455
if (javaConfiguration.inmemoryJdepsFiles()) {
455-
executionInfo =
456-
ImmutableMap.of(
457-
ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS,
458-
outputDepsProto.getExecPathString());
456+
executionInfoBuilder.put(
457+
ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS,
458+
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();
460+
if (javaToolchain.getHeaderCompilerSupportsWorkers()) {
461+
executionInfoBuilder.putAll(ExecutionRequirements.WORKER_MODE_ENABLED);
462+
}
463+
if (javaToolchain.getHeaderCompilerSupportsMultiplexWorkers()) {
464+
executionInfoBuilder.putAll(ExecutionRequirements.WORKER_MULTIPLEX_MODE_ENABLED);
465+
}
466+
ImmutableMap<String, String> executionInfo = executionInfoBuilder.build();
465467
if (useDirectClasspath) {
466468
NestedSet<Artifact> classpath;
467469
if (!directJars.isEmpty() || classpathEntries.isEmpty()) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public ConfiguredTarget create(RuleContext ruleContext)
6868
ruleContext.attributes().get("javac_supports_multiplex_workers", Type.BOOLEAN);
6969
boolean javacSupportsWorkerCancellation =
7070
ruleContext.attributes().get("javac_supports_worker_cancellation", Type.BOOLEAN);
71+
boolean headerCompilerSupportsWorkers =
72+
ruleContext.attributes().get("header_compiler_supports_workers", Type.BOOLEAN);
73+
boolean headerCompilerSupportsMultiplexWorkers =
74+
ruleContext.attributes().get("header_compiler_supports_multiplex_workers", Type.BOOLEAN);
7175
ImmutableSet<String> headerCompilerBuiltinProcessors =
7276
ImmutableSet.copyOf(
7377
ruleContext.attributes().get("header_compiler_builtin_processors", Type.STRING_LIST));
@@ -168,6 +172,8 @@ public ConfiguredTarget create(RuleContext ruleContext)
168172
javacSupportsWorkers,
169173
javacSupportsMultiplexWorkers,
170174
javacSupportsWorkerCancellation,
175+
headerCompilerSupportsWorkers,
176+
headerCompilerSupportsMultiplexWorkers,
171177
bootclasspath,
172178
tools,
173179
javabuilder,

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public static JavaToolchainProvider create(
9797
boolean javacSupportsWorkers,
9898
boolean javacSupportsMultiplexWorkers,
9999
boolean javacSupportsWorkerCancellation,
100+
boolean headerCompilerSupportsWorkers,
101+
boolean headerCompilerSupportsMultiplexWorkers,
100102
BootClassPathInfo bootclasspath,
101103
NestedSet<Artifact> tools,
102104
JavaToolchainTool javaBuilder,
@@ -149,6 +151,8 @@ public static JavaToolchainProvider create(
149151
javacSupportsWorkers,
150152
javacSupportsMultiplexWorkers,
151153
javacSupportsWorkerCancellation,
154+
headerCompilerSupportsWorkers,
155+
headerCompilerSupportsMultiplexWorkers,
152156
packageConfiguration,
153157
jacocoRunner,
154158
proguardAllowlister,
@@ -182,6 +186,8 @@ public static JavaToolchainProvider create(
182186
private final boolean javacSupportsWorkers;
183187
private final boolean javacSupportsMultiplexWorkers;
184188
private final boolean javacSupportsWorkerCancellation;
189+
private final boolean headerCompilerSupportsWorkers;
190+
private final boolean headerCompilerSupportsMultiplexWorkers;
185191
private final ImmutableList<JavaPackageConfigurationProvider> packageConfiguration;
186192
private final FilesToRunProvider jacocoRunner;
187193
private final FilesToRunProvider proguardAllowlister;
@@ -215,6 +221,8 @@ private JavaToolchainProvider(
215221
boolean javacSupportsWorkers,
216222
boolean javacSupportsMultiplexWorkers,
217223
boolean javacSupportsWorkerCancellation,
224+
boolean headerCompilerSupportsWorkers,
225+
boolean headerCompilerSupportsMultiplexWorkers,
218226
ImmutableList<JavaPackageConfigurationProvider> packageConfiguration,
219227
FilesToRunProvider jacocoRunner,
220228
FilesToRunProvider proguardAllowlister,
@@ -247,6 +255,8 @@ private JavaToolchainProvider(
247255
this.javacSupportsWorkers = javacSupportsWorkers;
248256
this.javacSupportsMultiplexWorkers = javacSupportsMultiplexWorkers;
249257
this.javacSupportsWorkerCancellation = javacSupportsWorkerCancellation;
258+
this.headerCompilerSupportsWorkers = headerCompilerSupportsWorkers;
259+
this.headerCompilerSupportsMultiplexWorkers = headerCompilerSupportsMultiplexWorkers;
250260
this.packageConfiguration = packageConfiguration;
251261
this.jacocoRunner = jacocoRunner;
252262
this.proguardAllowlister = proguardAllowlister;
@@ -419,6 +429,16 @@ public boolean getJavacSupportsMultiplexWorkers() {
419429
return javacSupportsMultiplexWorkers;
420430
}
421431

432+
/** Returns whether JavaHeaderCompiler supports running as a persistent worker or not. */
433+
public boolean getHeaderCompilerSupportsWorkers() {
434+
return headerCompilerSupportsWorkers;
435+
}
436+
437+
/** Returns whether JavaHeaderCompiler supports running persistent workers in multiplex mode */
438+
public boolean getHeaderCompilerSupportsMultiplexWorkers() {
439+
return headerCompilerSupportsMultiplexWorkers;
440+
}
441+
422442
/** Returns whether JavaBuilders supports running persistent workers with cancellation */
423443
public boolean getJavacSupportsWorkerCancellation() {
424444
return javacSupportsWorkerCancellation;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ The Java target version (e.g., '6' or '7'). It specifies for which Java runtime
129129
True if JavaBuilder supports cancellation of persistent workers, false if it doesn't.
130130
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
131131
.add(attr("javac_supports_worker_cancellation", BOOLEAN).value(true))
132+
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(header_compiler_supports_workers) -->
133+
True if JavaHeaderCompiler supports running as a persistent worker, false if it doesn't.
134+
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
135+
.add(attr("header_compiler_supports_workers", BOOLEAN).value(false))
136+
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(header_compiler_supports_multiplex_workers) -->
137+
True if JavaHeaderCompiler supports running as a multiplex persistent worker, false if it doesn't.
138+
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
139+
.add(attr("header_compiler_supports_multiplex_workers", BOOLEAN).value(false))
132140
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(tools) -->
133141
Labels of tools available for label-expansion in jvm_opts.
134142
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */

0 commit comments

Comments
 (0)