diff options
author | Alex Humesky <ahumesky@google.com> | 2016-06-20 19:43:11 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2016-06-21 09:58:24 +0000 |
commit | 152feb04f940385edaab01435454188488509fb3 (patch) | |
tree | 6ca931c306b249dbd4d9dc3095b3b98a819454e0 /src/main/java/com/google/devtools/build/lib/analysis | |
parent | a973b61047c8f5b48597c6ab82e039e1610c84b0 (diff) |
Simplify the logic of determining output groups.
--
MOS_MIGRATED_REVID=125368119
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/OutputGroupProvider.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupProvider.java index dec4d407f9..e600550a59 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupProvider.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupProvider.java @@ -16,6 +16,8 @@ package com.google.devtools.build.lib.analysis; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Sets; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -136,4 +138,41 @@ public final class OutputGroupProvider implements TransitiveInfoProvider { } return new OutputGroupProvider(resultBuilder.build()); } + + public static ImmutableSortedSet<String> determineOutputGroups(List<String> outputGroups) { + return determineOutputGroups(DEFAULT_GROUPS, outputGroups); + } + + public static ImmutableSortedSet<String> determineOutputGroups( + Set<String> defaultOutputGroups, List<String> outputGroups) { + + Set<String> current = Sets.newHashSet(); + + // If all of the requested output groups start with "+" or "-", then these are added or + // subtracted to the set of default output groups. + // If any of them don't start with "+" or "-", then the list of requested output groups + // overrides the default set of output groups. + boolean addDefaultOutputGroups = true; + for (String outputGroup : outputGroups) { + if (!(outputGroup.startsWith("+") || outputGroup.startsWith("-"))) { + addDefaultOutputGroups = false; + break; + } + } + if (addDefaultOutputGroups) { + current.addAll(defaultOutputGroups); + } + + for (String outputGroup : outputGroups) { + if (outputGroup.startsWith("+")) { + current.add(outputGroup.substring(1)); + } else if (outputGroup.startsWith("-")) { + current.remove(outputGroup.substring(1)); + } else { + current.add(outputGroup); + } + } + + return ImmutableSortedSet.copyOf(current); + } } |