-
Notifications
You must be signed in to change notification settings - Fork 0
turbine support worker mode #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.google.devtools.build.java.turbine; | ||
|
||
import com.google.turbine.main.Main; | ||
import com.google.devtools.build.lib.worker.ProtoWorkerMessageProcessor; | ||
import com.google.devtools.build.lib.worker.WorkRequestHandler; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.io.PrintWriter; | ||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
/** | ||
* A Wrapper for Turbine to support multiplex worker | ||
*/ | ||
public class TurbineWorkerWrapper { | ||
|
||
public static void main(String[] args) throws IOException { | ||
if (args.length == 1 && args[0].equals("--persistent_worker")) { | ||
PrintStream realStdErr = System.err; | ||
WorkRequestHandler workerHandler = | ||
new WorkRequestHandler.WorkRequestHandlerBuilder( | ||
new WorkRequestHandler.WorkRequestCallback( | ||
(request, pw) -> | ||
turbine(request.getArgumentsList(), pw)), | ||
realStdErr, | ||
new ProtoWorkerMessageProcessor(System.in, System.out)) | ||
.setCpuUsageBeforeGc(Duration.ofSeconds(10)) | ||
.build(); | ||
int exitCode = 1; | ||
try { | ||
workerHandler.processRequests(); | ||
exitCode = 0; | ||
} catch (IOException e) { | ||
realStdErr.println(e.getMessage()); | ||
} finally { | ||
// Prevent hanging threads from keeping the worker alive. | ||
System.exit(exitCode); | ||
} | ||
} else { | ||
Main.main(args); | ||
} | ||
} | ||
|
||
private static int turbine(List<String> args, PrintWriter pw) { | ||
try { | ||
Main.compile(args.toArray(new String[0])); | ||
} catch (Throwable e) { | ||
pw.println(e.getMessage()); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ public static Builder newBuilder(RuleContext ruleContext) { | |
public static final class Builder { | ||
|
||
private static final ParamFileInfo PARAM_FILE_INFO = | ||
ParamFileInfo.builder(UNQUOTED).setCharset(ISO_8859_1).build(); | ||
ParamFileInfo.builder(UNQUOTED).setCharset(ISO_8859_1).setUseAlways(true).build(); | ||
|
||
private final RuleContext ruleContext; | ||
|
||
|
@@ -449,14 +449,21 @@ public void build(JavaToolchainProvider javaToolchain) { | |
} | ||
} | ||
|
||
ImmutableMap<String, String> executionInfo = | ||
TargetUtils.getExecutionInfo(ruleContext.getRule(), ruleContext.isAllowTagsPropagation()); | ||
ImmutableMap.Builder<String, String> executionInfoBuilder = ImmutableMap.builder(); | ||
executionInfoBuilder.putAll( | ||
TargetUtils.getExecutionInfo(ruleContext.getRule(), ruleContext.isAllowTagsPropagation())); | ||
if (javaConfiguration.inmemoryJdepsFiles()) { | ||
executionInfo = | ||
ImmutableMap.of( | ||
ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS, | ||
outputDepsProto.getExecPathString()); | ||
executionInfoBuilder.put( | ||
ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS, | ||
outputDepsProto.getExecPathString()); | ||
} | ||
if (javaToolchain.getHeaderCompilerSupportsWorkers()) { | ||
executionInfoBuilder.putAll(ExecutionRequirements.WORKER_MODE_ENABLED); | ||
} | ||
if (javaToolchain.getHeaderCompilerSupportsMultiplexWorkers()) { | ||
executionInfoBuilder.putAll(ExecutionRequirements.WORKER_MULTIPLEX_MODE_ENABLED); | ||
} | ||
ImmutableMap<String, String> executionInfo = executionInfoBuilder.build(); | ||
if (useDirectClasspath) { | ||
Comment on lines
+452
to
467
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible duplicate-key crash when rule tags already enable worker mode
Calling - if (javaToolchain.getHeaderCompilerSupportsWorkers()) {
- executionInfoBuilder.putAll(ExecutionRequirements.WORKER_MODE_ENABLED);
- }
+ if (javaToolchain.getHeaderCompilerSupportsWorkers()
+ && !executionInfoBuilder.buildOrThrow()
+ .containsKey(ExecutionRequirements.WORKER_MODE_ENABLED.keySet().iterator().next())) {
+ executionInfoBuilder.putAll(ExecutionRequirements.WORKER_MODE_ENABLED);
+ } (The same guard is needed for the multiplex variant.) Failing fast here would surface as an unexplained analysis exception to users.
|
||
NestedSet<Artifact> classpath; | ||
if (!directJars.isEmpty() || classpathEntries.isEmpty()) { | ||
|
@@ -485,7 +492,7 @@ public void build(JavaToolchainProvider javaToolchain) { | |
ruleContext.registerAction( | ||
new JavaHeaderCompileAction( | ||
/* owner= */ ruleContext.getActionOwner(), | ||
/* tools= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER), | ||
/* tools= */ headerCompiler.tool().getFilesToRun(), | ||
/* inputs= */ allInputs, | ||
/* outputs= */ outputs.build(), | ||
/* resourceSetOrBuilder= */ AbstractAction.DEFAULT_RESOURCE_SET, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -129,6 +129,14 @@ The Java target version (e.g., '6' or '7'). It specifies for which Java runtime | |||||||||||||||||||||
True if JavaBuilder supports cancellation of persistent workers, false if it doesn't. | ||||||||||||||||||||||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||||||||||||||||||||||
.add(attr("javac_supports_worker_cancellation", BOOLEAN).value(true)) | ||||||||||||||||||||||
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(header_compiler_supports_workers) --> | ||||||||||||||||||||||
True if JavaHeaderCompiler supports running as a persistent worker, false if it doesn't. | ||||||||||||||||||||||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||||||||||||||||||||||
.add(attr("header_compiler_supports_workers", BOOLEAN).value(false)) | ||||||||||||||||||||||
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(header_compiler_supports_multiplex_workers) --> | ||||||||||||||||||||||
True if JavaHeaderCompiler supports running as a multiplex persistent worker, false if it doesn't. | ||||||||||||||||||||||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||||||||||||||||||||||
.add(attr("header_compiler_supports_multiplex_workers", BOOLEAN).value(false)) | ||||||||||||||||||||||
Comment on lines
+135
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider setting the default value of
Suggested change
|
||||||||||||||||||||||
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(tools) --> | ||||||||||||||||||||||
Labels of tools available for label-expansion in jvm_opts. | ||||||||||||||||||||||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider logging the full stack trace of the
IOException
for better debugging. Printing only the message might not be sufficient to diagnose the root cause.