示例#1
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();
 }
示例#2
0
  @Override
  public Set<Target> getBuildFiles(
      QueryExpression caller,
      Set<Target> nodes,
      boolean buildFiles,
      boolean subincludes,
      boolean loads)
      throws QueryException {
    Set<Target> dependentFiles = new LinkedHashSet<>();
    Set<Package> seenPackages = new HashSet<>();
    // Keep track of seen labels, to avoid adding a fake subinclude label that also exists as a
    // real target.
    Set<Label> seenLabels = new HashSet<>();

    // Adds all the package definition files (BUILD files and build
    // extensions) for package "pkg", to "buildfiles".
    for (Target x : nodes) {
      Package pkg = x.getPackage();
      if (seenPackages.add(pkg)) {
        if (buildFiles) {
          addIfUniqueLabel(pkg.getBuildFile(), seenLabels, dependentFiles);
        }

        List<Label> extensions = new ArrayList<>();
        if (subincludes) {
          extensions.addAll(pkg.getSubincludeLabels());
        }
        if (loads) {
          extensions.addAll(pkg.getSkylarkFileDependencies());
        }

        for (Label subinclude : extensions) {
          addIfUniqueLabel(getSubincludeTarget(subinclude, pkg), seenLabels, dependentFiles);

          if (buildFiles) {
            // Also add the BUILD file of the subinclude.
            try {
              addIfUniqueLabel(
                  getSubincludeTarget(subinclude.getLocalTargetLabel("BUILD"), pkg),
                  seenLabels,
                  dependentFiles);

            } catch (LabelSyntaxException e) {
              throw new AssertionError("BUILD should always parse as a target name", e);
            }
          }
        }
      }
    }
    return dependentFiles;
  }
 private static ArtifactLocation makeArtifactLocation(Package pkg) {
   Root root = Root.asSourceRoot(pkg.getSourceRoot());
   PathFragment relativePath = pkg.getBuildFile().getPath().relativeTo(root.getPath());
   return makeArtifactLocation(root, relativePath);
 }