Add --output_filter option
Fixes #309.
--
MOS_MIGRATED_REVID=98639996
diff --git a/site/docs/bazel-user-manual.html b/site/docs/bazel-user-manual.html
index e44d375..df28a6d 100644
--- a/site/docs/bazel-user-manual.html
+++ b/site/docs/bazel-user-manual.html
@@ -1205,35 +1205,6 @@
<td>Don't show output.</td>
</tr>
</table>
-<p>
- If this option is not given, a default filter will be created according to the
- <a href="#flag--auto_output_filter"><code class='flag'>--auto_output_filter</code> option</a>.
-</p>
-
-<h4 id='flag--auto_output_filter'><code class='flag'>--auto_output_filter (none|packages|subpackages)</code></h4>
-
-<p>
- If no <a href="#flag--output_filter"><code class='flag'>--output_filter</code> option</a> is
- given, Bazel creates an output filter from the targets listed on the command
- line:
-</p>
-<ul>
- <li>
- <code>none</code> does no filtering and shows all output.
- </li>
- <li>
- <code>packages</code> shows only the output for the packages of targets
- requested on the command line. For example, the Bazel invocation
- <pre> % bazel build //foo:bar //baz/...</pre>
- will show the output for all targets in the package <code>foo</code> or any
- package under <code>baz</code>.
-
- </li>
- <li>
- <code>subpackages</code> (the default) works similar
- to <code>packages</code> but also includes output from subpackages.
- </li>
-</ul>
<h4 id='flag--analysis_warnings_as_errors'><code>--[no]analysis_warnings_as_errors</code></h4>
<p>
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java
index afe7597..f9277a9 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java
@@ -47,6 +47,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
+import java.util.regex.Pattern;
/**
* A BuildRequest represents a single invocation of the build tool by a user.
@@ -120,6 +121,14 @@
+ "Has no effect if --explain is not enabled.")
public boolean verboseExplanations;
+ @Option(name = "output_filter",
+ converter = Converters.RegexPatternConverter.class,
+ defaultValue = "null",
+ category = "flags",
+ help = "Only shows warnings for rules with a name matching the provided regular "
+ + "expression.")
+ public Pattern outputFilter;
+
@Deprecated
@Option(name = "dump_makefile",
defaultValue = "false",
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
index d728c63..0fe2562 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
@@ -53,6 +53,7 @@
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.events.Event;
+import com.google.devtools.build.lib.events.OutputFilter;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.packages.InputFile;
import com.google.devtools.build.lib.packages.License;
@@ -83,6 +84,7 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
+import java.util.regex.Pattern;
/**
* Provides the bulk of the implementation of the 'blaze build' command.
@@ -397,6 +399,8 @@
Profiler.instance().markPhase(ProfilePhase.LOAD);
runtime.throwPendingException();
+ initializeOutputFilter(request);
+
final boolean keepGoing = request.getViewOptions().keepGoing;
Callback callback = new Callback() {
@@ -422,6 +426,16 @@
}
/**
+ * Initializes the output filter to the value given with {@code --output_filter}.
+ */
+ private void initializeOutputFilter(BuildRequest request) {
+ Pattern outputFilter = request.getBuildOptions().outputFilter;
+ if (outputFilter != null) {
+ getReporter().setOutputFilter(OutputFilter.RegexOutputFilter.forPattern(outputFilter));
+ }
+ }
+
+ /**
* Performs the initial phases 0-2 of the build: Setup, Loading and Analysis.
* <p>
* Postcondition: On success, populates the BuildRequest's set of targets to