From 9f74dfbc7aba8e455150f8eba4b616c56467e598 Mon Sep 17 00:00:00 2001 From: Lukacs Berki Date: Fri, 11 Nov 2016 10:00:53 +0000 Subject: 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 --- .../devtools/build/lib/packages/TargetUtils.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java') 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 tagFilter(List tagFilterList) { + Pair, Collection> tagLists = + TestTargetUtils.sortTagsBySense(tagFilterList); + final Collection requiredTags = tagLists.first; + final Collection excludedTags = tagLists.second; + return new Predicate() { + @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; -- cgit v1.2.3