diff options
author | cushon <cushon@google.com> | 2017-05-05 20:56:41 +0200 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-05-05 23:20:10 +0200 |
commit | 9eed8d6a7112d43e2b48c5658be70e0e310e9df2 (patch) | |
tree | b99bea60dd1f46a398475638f421988e99e9c037 /src/main/java | |
parent | 3b8ffd17b027ef692e001322f4ca3221a6e6ba3b (diff) |
Add experimental support for disabling turbine fallback to javac-turbine
PiperOrigin-RevId: 155223937
Diffstat (limited to 'src/main/java')
3 files changed, 91 insertions, 38 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java index 2bdfafbfb5..1c9364dc5c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java @@ -147,6 +147,7 @@ public final class JavaConfiguration extends Fragment { private final boolean useIjars; private final boolean useHeaderCompilation; private final boolean headerCompilationDirectClasspath; + private final boolean headerCompilationDisableJavacFallback; private final boolean generateJavaDeps; private final boolean strictDepsJavaProtos; private final OneVersionEnforcementLevel enforceOneVersion; @@ -179,6 +180,7 @@ public final class JavaConfiguration extends Fragment { this.useIjars = javaOptions.useIjars; this.useHeaderCompilation = javaOptions.headerCompilation; this.headerCompilationDirectClasspath = javaOptions.headerCompilationDirectClasspath; + this.headerCompilationDisableJavacFallback = javaOptions.headerCompilationDisableJavacFallback; this.generateJavaDeps = generateJavaDeps; this.javaClasspath = javaOptions.javaClasspath; this.defaultJvmFlags = ImmutableList.copyOf(defaultJvmFlags); @@ -265,6 +267,14 @@ public final class JavaConfiguration extends Fragment { } /** + * If --java_header_compilation is set, report diagnostics from turbine instead of falling back to + * javac. Diagnostics will be produced more quickly, but may be less helpful. + */ + public boolean headerCompilationDisableJavacFallback() { + return headerCompilationDisableJavacFallback; + } + + /** * Returns true iff dependency information is generated after compilation. */ public boolean getGenerateJavaDeps() { diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java index 5e05cc6f50..a92d5bbddf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ActionOwner; @@ -316,6 +317,10 @@ public class JavaHeaderCompileAction extends SpawnAction { } /** Builds and registers the {@link JavaHeaderCompileAction} for a header compilation. */ public void build(JavaToolchainProvider javaToolchain) { + ruleContext.registerAction(buildInternal(javaToolchain)); + } + + private ActionAnalysisMetadata[] buildInternal(JavaToolchainProvider javaToolchain) { checkNotNull(outputDepsProto, "outputDepsProto must not be null"); checkNotNull(sourceFiles, "sourceFiles must not be null"); checkNotNull(sourceJars, "sourceJars must not be null"); @@ -337,38 +342,62 @@ public class JavaHeaderCompileAction extends SpawnAction { compileTimeDependencyArtifacts = NestedSetBuilder.emptySet(Order.STABLE_ORDER); } boolean useDirectClasspath = useDirectClasspath(); - CommandLine directCommandLine = - useDirectClasspath - ? baseCommandLine(getBaseArgs(javaToolchain)) - .addExecPaths("--classpath", directJars) - .build() - : null; + boolean disableJavacFallback = + ruleContext.getFragment(JavaConfiguration.class).headerCompilationDisableJavacFallback(); + CommandLine directCommandLine = null; + if (useDirectClasspath) { + CustomCommandLine.Builder builder = + baseCommandLine(getBaseArgs(javaToolchain)).addExecPaths("--classpath", directJars); + if (disableJavacFallback) { + builder.add("--nojavac_fallback"); + } + directCommandLine = builder.build(); + } + Iterable<Artifact> tools = ImmutableList.of(javacJar, javaToolchain.getHeaderCompiler()); + ImmutableList<Artifact> outputs = ImmutableList.of(outputJar, outputDepsProto); + NestedSet<Artifact> directInputs = + NestedSetBuilder.<Artifact>stableOrder() + .addTransitive(javabaseInputs) + .addAll(bootclasspathEntries) + .addAll(sourceJars) + .addAll(sourceFiles) + .addTransitive(directJars) + .addAll(tools) + .build(); + + if (useDirectClasspath && disableJavacFallback) { + // use a regular SpawnAction to invoke turbine with direct deps only, + // and no fallback to javac-turbine + return new ActionAnalysisMetadata[] { + new SpawnAction( + ruleContext.getActionOwner(), + tools, + directInputs, + outputs, + LOCAL_RESOURCES, + directCommandLine, + JavaCompileAction.UTF8_ENVIRONMENT, + /*executionInfo=*/ ImmutableSet.<String>of(), + getProgressMessage(), + "Turbine") + }; + } + CommandLine transitiveParams = transitiveCommandLine(); PathFragment paramFilePath = ParameterFile.derivePath(outputJar.getRootRelativePath()); Artifact paramsFile = ruleContext .getAnalysisEnvironment() .getDerivedArtifact(paramFilePath, outputJar.getRoot()); - ruleContext.registerAction( + ParameterFileWriteAction parameterFileWriteAction = new ParameterFileWriteAction( ruleContext.getActionOwner(), paramsFile, transitiveParams, ParameterFile.ParameterFileType.UNQUOTED, - ISO_8859_1)); + ISO_8859_1); CommandLine transitiveCommandLine = getBaseArgs(javaToolchain).addPaths("@%s", paramsFile.getExecPath()).build(); - Iterable<Artifact> tools = ImmutableList.of(javacJar, javaToolchain.getHeaderCompiler()); - ImmutableList<Artifact> outputs = ImmutableList.of(outputJar, outputDepsProto); - NestedSet<Artifact> directInputs = - NestedSetBuilder.<Artifact>stableOrder() - .addTransitive(javabaseInputs) - .addAll(bootclasspathEntries) - .addAll(sourceJars) - .addAll(sourceFiles) - .addTransitive(directJars) - .addAll(tools) - .build(); NestedSet<Artifact> transitiveInputs = NestedSetBuilder.<Artifact>stableOrder() .addTransitive(directInputs) @@ -380,30 +409,33 @@ public class JavaHeaderCompileAction extends SpawnAction { if (!useDirectClasspath) { // If direct classpaths are disabled (e.g. because the compilation uses API-generating // annotation processors) skip the custom action implementation and just use SpawnAction. - ruleContext.registerAction( - new SpawnAction( - ruleContext.getActionOwner(), - tools, - transitiveInputs, - outputs, - LOCAL_RESOURCES, - transitiveCommandLine, - JavaCompileAction.UTF8_ENVIRONMENT, - /*executionInfo=*/ ImmutableSet.<String>of(), - getProgressMessage(), - "JavacTurbine")); - return; - } - ruleContext.registerAction( - new JavaHeaderCompileAction( + return new ActionAnalysisMetadata[] { + parameterFileWriteAction, + new SpawnAction( ruleContext.getActionOwner(), tools, - directInputs, transitiveInputs, outputs, - directCommandLine, + LOCAL_RESOURCES, transitiveCommandLine, - getProgressMessage())); + JavaCompileAction.UTF8_ENVIRONMENT, + /*executionInfo=*/ ImmutableSet.<String>of(), + getProgressMessage(), + "JavacTurbine") + }; + } + return new ActionAnalysisMetadata[] { + parameterFileWriteAction, + new JavaHeaderCompileAction( + ruleContext.getActionOwner(), + tools, + directInputs, + transitiveInputs, + outputs, + directCommandLine, + transitiveCommandLine, + getProgressMessage()) + }; } private String getProgressMessage() { diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java index 042976d7c5..55f83e5395 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java @@ -426,6 +426,16 @@ public class JavaOptions extends FragmentOptions { public boolean headerCompilationDirectClasspath; @Option( + name = "experimental_java_header_compilation_disable_javac_fallback", + defaultValue = "false", + optionUsageRestrictions = OptionUsageRestrictions.UNDOCUMENTED, + help = + "If --java_header_compilation is set, report diagnostics from turbine instead of falling " + + " back to javac. Diagnostics will be produced more quickly, but may be less helpful." + ) + public boolean headerCompilationDisableJavacFallback; + + @Option( name = "experimental_one_version_enforcement", defaultValue = "OFF", converter = OneVersionEnforcementLevelConverter.class, @@ -454,6 +464,7 @@ public class JavaOptions extends FragmentOptions { host.useIjars = useIjars; host.headerCompilation = headerCompilation; host.headerCompilationDirectClasspath = headerCompilationDirectClasspath; + host.headerCompilationDisableJavacFallback = headerCompilationDisableJavacFallback; host.javaDeps = javaDeps; host.javaClasspath = javaClasspath; |