@Override public Collection<Target> getReverseDeps(Iterable<Target> targets) { Set<Target> result = CompactHashSet.create(); Map<Target, Collection<Target>> rawReverseDeps = getRawReverseDeps(targets); warnIfMissingTargets(targets, rawReverseDeps.keySet()); CompactHashSet<Target> visited = CompactHashSet.create(); Set<Label> keys = CompactHashSet.create( Collections2.transform(rawReverseDeps.keySet(), TARGET_LABEL_FUNCTION)); for (Collection<Target> parentCollection : rawReverseDeps.values()) { for (Target parent : parentCollection) { if (visited.add(parent)) { if (parent instanceof Rule && dependencyFilter != DependencyFilter.ALL_DEPS) { for (Label label : getAllowedDeps((Rule) parent)) { if (keys.contains(label)) { result.add(parent); } } } else { result.add(parent); } } } } return result; }
/** * Calculates the set of {@link Package} objects, represented as source file targets, that depend * on the given list of BUILD files and subincludes (other files are filtered out). */ @Nullable Set<Target> getRBuildFiles(Collection<PathFragment> fileIdentifiers) { Collection<SkyKey> files = getSkyKeysForFileFragments(fileIdentifiers); Collection<SkyKey> current = graph.getSuccessfulValues(files).keySet(); Set<SkyKey> resultKeys = CompactHashSet.create(); while (!current.isEmpty()) { Collection<Iterable<SkyKey>> reverseDeps = graph.getReverseDeps(current).values(); current = new HashSet<>(); for (SkyKey rdep : Iterables.concat(reverseDeps)) { if (rdep.functionName().equals(SkyFunctions.PACKAGE)) { resultKeys.add(rdep); } else if (!rdep.functionName().equals(SkyFunctions.PACKAGE_LOOKUP)) { // Packages may depend on subpackages for existence, but we don't report them as rdeps. current.add(rdep); } } } Map<SkyKey, SkyValue> packageValues = graph.getSuccessfulValues(resultKeys); ImmutableSet.Builder<Target> result = ImmutableSet.builder(); for (SkyValue value : packageValues.values()) { Package pkg = ((PackageValue) value).getPackage(); if (!pkg.containsErrors()) { result.add(pkg.getBuildFile()); } } return result.build(); }
/** * Add an element to this list. If in a group, will be added to the current group. Otherwise, * goes in a group of its own. */ public void add(E elt) { Preconditions.checkState(elements.add(Preconditions.checkNotNull(elt)), "%s %s", elt, this); if (currentGroup == null) { groupedList.add(elt); } else { currentGroup.add(elt); } }
/** * Checks that two lists, neither of which may contain duplicates, have the same elements, * regardless of order. */ private static boolean checkUnorderedEqualityWithoutDuplicates(List<?> first, List<?> second) { if (first.size() != second.size()) { return false; } // The order-sensitive comparison usually returns true. When it does, the CompactHashSet // doesn't need to be constructed. return first.equals(second) || CompactHashSet.create(first).containsAll(second); }
@Override public void process(Iterable<Target> partialResult) throws QueryException, InterruptedException { Set<Target> targets = CompactHashSet.create(); for (Target target : partialResult) { if (validateScope(target.getLabel(), strictScope)) { targets.add(target); } } batchStreamedCallback.process(targets); }
private Map<Target, Collection<Target>> makeTargetsMap(Map<SkyKey, Iterable<SkyKey>> input) { ImmutableMap.Builder<Target, Collection<Target>> result = ImmutableMap.builder(); Map<SkyKey, Target> allTargets = makeTargetsFromSkyKeys(Sets.newHashSet(Iterables.concat(input.values()))); for (Map.Entry<SkyKey, Target> entry : makeTargetsFromSkyKeys(input.keySet()).entrySet()) { Iterable<SkyKey> skyKeys = input.get(entry.getKey()); Set<Target> targets = CompactHashSet.createWithExpectedSize(Iterables.size(skyKeys)); for (SkyKey key : skyKeys) { Target target = allTargets.get(key); if (target != null) { targets.add(target); } } result.put(entry.getValue(), targets); } return result.build(); }
@Override public Iterator<E> iterator() { return elements.iterator(); }
/** Returns true if list is empty. */ public boolean isEmpty() { return elements.isEmpty(); }
private int size() { return elements.size(); }
/** Returns true if elt is present in the list. */ public boolean contains(E elt) { return elements.contains(elt); }
/** * Remove all elements of toRemove from this list. It is a fatal error if any elements of * toRemove are not present. Takes time proportional to the size of the list, so should not be * called often. */ public void remove(Set<E> toRemove) { groupedList = GroupedList.remove(groupedList, toRemove); int oldSize = size(); elements.removeAll(toRemove); Preconditions.checkState(oldSize == size() + toRemove.size(), "%s %s", toRemove, this); }
/** Create with a copy of the contents of {@param elements} as the initial group. */ private GroupedListHelper(Collection<E> elements) { // Optimize for short lists. groupedList = new ArrayList<>(1); addItem(elements, groupedList); this.elements = CompactHashSet.create(elements); }
public GroupedListHelper() { // Optimize for short lists. groupedList = new ArrayList<>(1); elements = CompactHashSet.create(); }