Exemplo n.º 1
0
  @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;
  }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 @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);
 }
Exemplo n.º 5
0
 /** 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);
 }
Exemplo n.º 6
0
 public GroupedListHelper() {
   // Optimize for short lists.
   groupedList = new ArrayList<>(1);
   elements = CompactHashSet.create();
 }