aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-11-11 10:00:53 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-11 10:56:56 +0000
commit9f74dfbc7aba8e455150f8eba4b616c56467e598 (patch)
tree0fa37bdff01c4610c6b4adc982caa0980e5b0569 /src/main/java/com/google/devtools/build/lib/packages
parent279a061eb0873df4e8ea71755684037b4bdd511f (diff)
Implement build tag filtering.
If the --build_tag_filters option is specified, targets built will be filtered according to their tags (at least one included, none excluded) -- MOS_MIGRATED_REVID=138856195
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java32
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java25
2 files changed, 32 insertions, 25 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java
index 43b74739ff..00d15cd804 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java
@@ -14,11 +14,15 @@
package com.google.devtools.build.lib.packages;
+import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.util.Pair;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
@@ -193,6 +197,34 @@ public final class TargetUtils {
return visitor.isExplicit();
}
+ /**
+ * Returns a predicate to be used for test tag filtering, i.e., that only accepts tests that match
+ * all of the required tags and none of the excluded tags.
+ */
+ public static Predicate<Target> tagFilter(List<String> tagFilterList) {
+ Pair<Collection<String>, Collection<String>> tagLists =
+ TestTargetUtils.sortTagsBySense(tagFilterList);
+ final Collection<String> requiredTags = tagLists.first;
+ final Collection<String> excludedTags = tagLists.second;
+ return new Predicate<Target>() {
+ @Override
+ public boolean apply(Target input) {
+ if (requiredTags.isEmpty() && excludedTags.isEmpty()) {
+ return true;
+ }
+
+ if (!(input instanceof Rule)) {
+ return false;
+ }
+ // Note that test_tags are those originating from the XX_test rule,
+ // whereas the requiredTags and excludedTags originate from the command
+ // line or test_suite rule.
+ return TestTargetUtils.testMatchesFilters(((Rule) input).getRuleTags(),
+ requiredTags, excludedTags, false);
+ }
+ };
+ }
+
private static class ExplicitEdgeVisitor implements AttributeMap.AcceptsLabelAttribute {
private final Label expectedLabel;
private final Rule rule;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java b/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java
index 7045c16ee8..eb5755c73a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java
@@ -144,31 +144,6 @@ public final class TestTargetUtils {
}
/**
- * Returns a predicate to be used for test tag filtering, i.e., that only accepts tests that match
- * all of the required tags and none of the excluded tags.
- */
- // TODO(bazel-team): This also applies to non-test rules, so should probably be moved to
- // TargetUtils.
- public static Predicate<Target> tagFilter(List<String> tagFilterList) {
- Pair<Collection<String>, Collection<String>> tagLists = sortTagsBySense(tagFilterList);
- final Collection<String> requiredTags = tagLists.first;
- final Collection<String> excludedTags = tagLists.second;
- return new Predicate<Target>() {
- @Override
- public boolean apply(Target input) {
- if (!(input instanceof Rule)) {
- return false;
- }
- // Note that test_tags are those originating from the XX_test rule,
- // whereas the requiredTags and excludedTags originate from the command
- // line or test_suite rule.
- return testMatchesFilters(((Rule) input).getRuleTags(),
- requiredTags, excludedTags, false);
- }
- };
- }
-
- /**
* Separates a list of text "tags" into a Pair of Collections, where
* the first element are the required or positive tags and the second element
* are the excluded or negative tags.