Add a flag, --experimental_verbose_failures_filter, that gives finer control over failure reporting: rather than dump command lines for all failed actions, dump only for actions whose labels match a regular expression filter.
The existing --verbose_failures flag is still available as an equivalent for --experimental_verbose_failures_filter=.*
PiperOrigin-RevId: 312352624
diff --git a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java
index c8c7a7c..9656851 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java
@@ -168,7 +168,8 @@
!Strings.isNullOrEmpty(resultMessage)
? resultMessage
: CommandFailureUtils.describeCommandFailure(
- actionExecutionContext.getVerboseFailures(),
+ actionExecutionContext.showVerboseFailures(
+ spawn.getResourceOwner().getOwner().getLabel()),
spawn.getArguments(),
spawn.getEnvironment(),
cwd,
diff --git a/src/main/java/com/google/devtools/build/lib/exec/BUILD b/src/main/java/com/google/devtools/build/lib/exec/BUILD
index b9df475..e25903d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/exec/BUILD
@@ -59,6 +59,7 @@
":spawn_strategy_registry",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/clock",
+ "//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/vfs",
@@ -87,6 +88,7 @@
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
"//src/main/java/com/google/devtools/build/lib/analysis:config/per_label_options",
+ "//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:resource_converter",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
diff --git a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
index 96bba6f..584cd77 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
@@ -17,11 +17,13 @@
import com.google.devtools.build.lib.actions.ActionExecutionContext.ShowSubcommands;
import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.clock.Clock;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.OptionsProvider;
+import java.util.function.Predicate;
import javax.annotation.Nullable;
/**
@@ -34,8 +36,7 @@
*/
@ThreadSafe
public final class BlazeExecutor implements Executor {
-
- private final boolean verboseFailures;
+ private final Predicate<Label> verboseFailures;
private final ShowSubcommands showSubcommands;
private final FileSystem fileSystem;
private final Path execRoot;
@@ -63,7 +64,7 @@
ModuleActionContextRegistry actionContextRegistry,
SpawnStrategyRegistry spawnStrategyRegistry) {
ExecutionOptions executionOptions = options.getOptions(ExecutionOptions.class);
- this.verboseFailures = executionOptions.verboseFailures;
+ this.verboseFailures = executionOptions.getVerboseFailuresPredicate();
this.showSubcommands = executionOptions.showSubcommands;
this.fileSystem = fileSystem;
this.execRoot = execRoot;
@@ -106,9 +107,8 @@
return actionContextRegistry.getContext(type);
}
- /** Returns true iff the --verbose_failures option was enabled. */
@Override
- public boolean getVerboseFailures() {
+ public Predicate<Label> getVerboseFailuresPredicate() {
return verboseFailures;
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index 8b589bf..28464e8 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -20,6 +20,7 @@
import com.google.devtools.build.lib.actions.LocalHostCapacity;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.analysis.config.PerLabelOptions;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.util.RegexFilter;
import com.google.devtools.build.lib.util.ResourceConverter;
@@ -38,6 +39,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.function.Predicate;
/**
* Options affecting the execution phase of a build.
@@ -126,9 +128,9 @@
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.EXECUTION},
help =
- "Writes intermediate parameter files to output tree even when using "
- + "remote action execution. Useful when debugging actions. "
- + "This is implied by --subcommands and --verbose_failures.")
+ "Writes intermediate parameter files to output tree even when using remote action"
+ + " execution. Useful when debugging actions. This is implied by --subcommands,"
+ + " --verbose_failures, and --experimental_verbose_failures_filter.")
public boolean materializeParamFiles;
@Option(
@@ -140,10 +142,13 @@
public boolean materializeParamFilesDirectly;
public boolean shouldMaterializeParamFiles() {
- // Implied by --subcommands and --verbose_failures
+ // Implied by --subcommands and verbose_failures
return materializeParamFiles
|| showSubcommands != ActionExecutionContext.ShowSubcommands.FALSE
- || verboseFailures;
+ // Conservatively materialize params files if any failures may be verbose.
+ // TODO(janakr): Could try to thread action label through to here and only materialize for
+ // those actions, but seems pretty gnarly.
+ || hasSomeVerboseFailures();
}
@Option(
@@ -151,10 +156,33 @@
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
- help = "If a command fails, print out the full command line.")
+ help = "If any command fails, print out the full command line.")
public boolean verboseFailures;
@Option(
+ name = "experimental_verbose_failures_filter",
+ defaultValue = "null",
+ converter = RegexFilter.RegexFilterConverter.class,
+ documentationCategory = OptionDocumentationCategory.LOGGING,
+ effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
+ help =
+ "If a command fails, print out the full command line if its label matches the given"
+ + " regex filter.")
+ public RegexFilter verboseFailuresFilter;
+
+ public boolean hasSomeVerboseFailures() {
+ return verboseFailures || verboseFailuresFilter != null;
+ }
+
+ public Predicate<Label> getVerboseFailuresPredicate() {
+ return verboseFailures
+ ? l -> true
+ : verboseFailuresFilter == null
+ ? l -> false
+ : l -> l == null || verboseFailuresFilter.isIncluded(l.getCanonicalForm());
+ }
+
+ @Option(
name = "subcommands",
abbrev = 's',
defaultValue = "false",
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java
index e9c3cd7..63ffb8d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java
@@ -125,7 +125,9 @@
}
} catch (ExecException e) {
throw e.toActionExecutionException(
- action.getProgressMessage(), actionExecutionContext.getVerboseFailures(), action);
+ action.getProgressMessage(),
+ actionExecutionContext.showVerboseFailures(action.getOwner().getLabel()),
+ action);
}
}
}