aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Liam Miller-Cushon <cushon@google.com>2017-01-31 19:29:58 +0000
committerGravatar Yun Peng <pcloudy@google.com>2017-02-01 08:55:21 +0000
commitf2f7839eefe1274bf9e25708201ec3cd89b19846 (patch)
tree8f60fe5d7c94f54406ca7bc2fff73ad01f8545df
parent75324c3893c920a3316ab9b70f5cf8d6454f6887 (diff)
Add a flag to make fallback from direct to transitive classpaths an error
-- PiperOrigin-RevId: 146143641 MOS_MIGRATED_REVID=146143641
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java30
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java11
3 files changed, 42 insertions, 10 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 0ed3506451..348aa049a1 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
@@ -128,6 +128,7 @@ public final class JavaConfiguration extends Fragment {
private final boolean useIjars;
private final boolean useHeaderCompilation;
private final boolean headerCompilationDirectClasspath;
+ private final boolean headerCompilationDirectClasspathFallbackError;
private final boolean generateJavaDeps;
private final boolean strictDepsJavaProtos;
private final JavaClasspathMode javaClasspath;
@@ -157,6 +158,8 @@ public final class JavaConfiguration extends Fragment {
this.useIjars = javaOptions.useIjars;
this.useHeaderCompilation = javaOptions.headerCompilation;
this.headerCompilationDirectClasspath = javaOptions.headerCompilationDirectClasspath;
+ this.headerCompilationDirectClasspathFallbackError =
+ javaOptions.headerCompilationDirectClasspathFallbackError;
this.generateJavaDeps = generateJavaDeps;
this.javaClasspath = javaOptions.javaClasspath;
this.defaultJvmFlags = ImmutableList.copyOf(defaultJvmFlags);
@@ -223,6 +226,14 @@ public final class JavaConfiguration extends Fragment {
}
/**
+ * Returns true if transitive classpath fallback should be an error when {@link
+ * #headerCompilationDirectClasspath} is enabled.
+ */
+ public boolean headerCompilationDirectClasspathFallbackError() {
+ return headerCompilationDirectClasspathFallbackError;
+ }
+
+ /**
* 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 0a9aa0ae25..7ffaee271a 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
@@ -18,12 +18,12 @@ import static com.google.devtools.build.lib.util.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
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.Action;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
+import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.ActionOwner;
import com.google.devtools.build.lib.actions.Artifact;
@@ -73,6 +73,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
private final Iterable<Artifact> directInputs;
@Nullable private final CommandLine directCommandLine;
+ private final boolean fallbackError;
/** Returns true if the header compilation will use direct dependencies only. */
@VisibleForTesting
@@ -98,6 +99,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
* @param directCommandLine the direct command line arguments for the java header compiler, or
* {@code null} if direct classpaths are disabled
* @param transitiveCommandLine the transitive command line arguments for the java header compiler
+ * @param fallbackError true if falling back from the direct classpath should be an error
* @param progressMessage the message printed during the progression of the build
*/
protected JavaHeaderCompileAction(
@@ -108,6 +110,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
Iterable<Artifact> outputs,
CommandLine directCommandLine,
CommandLine transitiveCommandLine,
+ boolean fallbackError,
String progressMessage) {
super(
owner,
@@ -122,6 +125,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
"Turbine");
this.directInputs = checkNotNull(directInputs);
this.directCommandLine = directCommandLine;
+ this.fallbackError = fallbackError;
}
@Override
@@ -130,7 +134,8 @@ public class JavaHeaderCompileAction extends SpawnAction {
new Fingerprint()
.addString(GUID)
.addString(super.computeKey())
- .addBoolean(useDirectClasspath());
+ .addBoolean(useDirectClasspath())
+ .addBoolean(fallbackError);
if (directCommandLine != null) {
fingerprint.addStrings(directCommandLine.arguments());
}
@@ -138,10 +143,10 @@ public class JavaHeaderCompileAction extends SpawnAction {
}
@Override
- protected void internalExecute(ActionExecutionContext actionExecutionContext)
- throws ExecException, InterruptedException {
+ public void execute(ActionExecutionContext actionExecutionContext)
+ throws ActionExecutionException, InterruptedException {
if (!useDirectClasspath()) {
- super.internalExecute(actionExecutionContext);
+ super.execute(actionExecutionContext);
return;
}
Executor executor = actionExecutionContext.getExecutor();
@@ -151,12 +156,14 @@ public class JavaHeaderCompileAction extends SpawnAction {
} catch (ExecException e) {
// if the direct input spawn failed, try again with transitive inputs to produce better
// better messages
- context.exec(getSpawn(actionExecutionContext.getClientEnv()), actionExecutionContext);
+ super.execute(actionExecutionContext);
// the compilation should never fail with direct deps but succeed with transitive inputs
- // TODO(cushon): make this an error before productionizing, we don't ever expect fallback
- String message =
- "header compilation failed unexpectedly: " + Throwables.getStackTraceAsString(e);
- executor.getEventHandler().handle(Event.warn(getOwner().getLocation(), message));
+ if (fallbackError) {
+ throw e.toActionExecutionException(
+ "header compilation failed unexpectedly", executor.getVerboseFailures(), this);
+ }
+ Event event = Event.warn(getOwner().getLocation(), "header compilation failed unexpectedly");
+ executor.getEventHandler().handle(event);
}
}
@@ -410,6 +417,9 @@ public class JavaHeaderCompileAction extends SpawnAction {
ImmutableList.of(outputJar, outputDepsProto),
directCommandLine,
transitiveCommandLine,
+ ruleContext
+ .getFragment(JavaConfiguration.class)
+ .headerCompilationDirectClasspathFallbackError(),
getProgressMessage());
ruleContext.registerAction(parameterFileWriteAction, javaHeaderCompileAction);
}
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 1b6c10b3de..5e7d599677 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
@@ -330,6 +330,15 @@ public class JavaOptions extends FragmentOptions {
)
public boolean headerCompilationDirectClasspath;
+ @Option(
+ name = "experimental_java_header_compilation_direct_classpath_fallback_error",
+ defaultValue = "false",
+ category = "undocumented",
+ help =
+ "If --experimental_java_header_compilation_direct_classpath is set, transitive classpath"
+ + " fallback is an error"
+ )
+ public boolean headerCompilationDirectClasspathFallbackError;
@Override
public FragmentOptions getHost(boolean fallback) {
@@ -348,6 +357,8 @@ public class JavaOptions extends FragmentOptions {
host.useIjars = useIjars;
host.headerCompilation = headerCompilation;
host.headerCompilationDirectClasspath = headerCompilationDirectClasspath;
+ host.headerCompilationDirectClasspathFallbackError =
+ headerCompilationDirectClasspathFallbackError;
host.javaDeps = javaDeps;
host.javaClasspath = javaClasspath;