コード例 #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;
  }
コード例 #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();
 }
コード例 #3
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 /**
  * 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);
   }
 }
コード例 #4
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 /**
  * 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);
 }
コード例 #5
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);
 }
コード例 #6
0
  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();
  }
コード例 #7
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 @Override
 public Iterator<E> iterator() {
   return elements.iterator();
 }
コード例 #8
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 /** Returns true if list is empty. */
 public boolean isEmpty() {
   return elements.isEmpty();
 }
コード例 #9
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 private int size() {
   return elements.size();
 }
コード例 #10
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 /** Returns true if elt is present in the list. */
 public boolean contains(E elt) {
   return elements.contains(elt);
 }
コード例 #11
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 /**
  * 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);
 }
コード例 #12
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 /** 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);
 }
コード例 #13
0
ファイル: GroupedList.java プロジェクト: wgapl/bazel
 public GroupedListHelper() {
   // Optimize for short lists.
   groupedList = new ArrayList<>(1);
   elements = CompactHashSet.create();
 }