Search in sources :

Example 1 with UniquifierImpl

use of com.google.devtools.build.lib.query2.engine.QueryUtil.UniquifierImpl in project bazel by bazelbuild.

the class SkyQueryEnvironment method getRBuildFiles.

/**
   * 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).
   */
@ThreadSafe
QueryTaskFuture<Void> getRBuildFiles(Collection<PathFragment> fileIdentifiers, Callback<Target> callback) {
    try {
        Collection<SkyKey> files = getSkyKeysForFileFragments(fileIdentifiers);
        Uniquifier<SkyKey> keyUniquifier = new UniquifierImpl<>(SkyKeyKeyExtractor.INSTANCE, /*concurrencyLevel=*/
        1);
        Collection<SkyKey> current = keyUniquifier.unique(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);
                    // too.
                    if (rdep.equals(PackageValue.key(Label.EXTERNAL_PACKAGE_IDENTIFIER))) {
                        if (keyUniquifier.unique(rdep)) {
                            current.add(rdep);
                        }
                    }
                } else if (!rdep.functionName().equals(SkyFunctions.PACKAGE_LOOKUP)) {
                    // to rbuildfiles.
                    if (keyUniquifier.unique(rdep)) {
                        current.add(rdep);
                    }
                }
            }
            if (resultKeys.size() >= BATCH_CALLBACK_SIZE) {
                for (Iterable<SkyKey> batch : Iterables.partition(resultKeys, BATCH_CALLBACK_SIZE)) {
                    callback.process(getBuildFilesForPackageValues(graph.getSuccessfulValues(batch).values()));
                }
                resultKeys.clear();
            }
        }
        callback.process(getBuildFilesForPackageValues(graph.getSuccessfulValues(resultKeys).values()));
        return immediateSuccessfulFuture(null);
    } catch (QueryException e) {
        return immediateFailedFuture(e);
    } catch (InterruptedException e) {
        return immediateCancelledFuture();
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) QueryException(com.google.devtools.build.lib.query2.engine.QueryException) MinDepthUniquifierImpl(com.google.devtools.build.lib.query2.engine.QueryUtil.MinDepthUniquifierImpl) UniquifierImpl(com.google.devtools.build.lib.query2.engine.QueryUtil.UniquifierImpl) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Aggregations

ThreadSafe (com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)1 QueryException (com.google.devtools.build.lib.query2.engine.QueryException)1 MinDepthUniquifierImpl (com.google.devtools.build.lib.query2.engine.QueryUtil.MinDepthUniquifierImpl)1 UniquifierImpl (com.google.devtools.build.lib.query2.engine.QueryUtil.UniquifierImpl)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1