Search in sources :

Example 1 with FilteringPolicy

use of com.google.devtools.build.lib.pkgcache.FilteringPolicy in project bazel by bazelbuild.

the class RecursivePackageProviderBackedTargetPatternResolver method findTargetsBeneathDirectoryAsyncImpl.

private <E extends Exception> ListenableFuture<Void> findTargetsBeneathDirectoryAsyncImpl(final RepositoryName repository, final String originalPattern, String directory, boolean rulesOnly, ImmutableSet<PathFragment> excludedSubdirectories, final ThreadSafeBatchCallback<Target, E> callback, ListeningExecutorService executor) {
    final FilteringPolicy actualPolicy = rulesOnly ? FilteringPolicies.and(FilteringPolicies.RULES_ONLY, policy) : policy;
    final PathFragment pathFragment;
    Iterable<PathFragment> packagesUnderDirectory;
    try {
        pathFragment = TargetPatternResolverUtil.getPathFragment(directory);
        packagesUnderDirectory = recursivePackageProvider.getPackagesUnderDirectory(eventHandler, repository, pathFragment, excludedSubdirectories);
    } catch (TargetParsingException e) {
        return Futures.immediateFailedFuture(e);
    } catch (InterruptedException e) {
        return Futures.immediateCancelledFuture();
    }
    Iterable<PackageIdentifier> pkgIds = Iterables.transform(packagesUnderDirectory, new Function<PathFragment, PackageIdentifier>() {

        @Override
        public PackageIdentifier apply(PathFragment path) {
            return PackageIdentifier.create(repository, path);
        }
    });
    final AtomicBoolean foundTarget = new AtomicBoolean(false);
    // For very large sets of packages, we may not want to process all of them at once, so we split
    // into batches.
    List<List<PackageIdentifier>> partitions = ImmutableList.copyOf(Iterables.partition(pkgIds, MAX_PACKAGES_BULK_GET));
    ArrayList<ListenableFuture<Void>> futures = new ArrayList<>(partitions.size());
    for (final Iterable<PackageIdentifier> pkgIdBatch : partitions) {
        futures.add(executor.submit(new Callable<Void>() {

            @Override
            public Void call() throws E, TargetParsingException, InterruptedException {
                ImmutableSet<PackageIdentifier> pkgIdBatchSet = ImmutableSet.copyOf(pkgIdBatch);
                packageSemaphore.acquireAll(pkgIdBatchSet);
                try {
                    Iterable<ResolvedTargets<Target>> resolvedTargets = bulkGetTargetsInPackage(originalPattern, pkgIdBatch, NO_FILTER).values();
                    List<Target> filteredTargets = new ArrayList<>(calculateSize(resolvedTargets));
                    for (ResolvedTargets<Target> targets : resolvedTargets) {
                        for (Target target : targets.getTargets()) {
                            // Perform the no-targets-found check before applying the filtering policy
                            // so we only return the error if the input directory's subtree really
                            // contains no targets.
                            foundTarget.set(true);
                            if (actualPolicy.shouldRetain(target, false)) {
                                filteredTargets.add(target);
                            }
                        }
                    }
                    callback.process(filteredTargets);
                } finally {
                    packageSemaphore.releaseAll(pkgIdBatchSet);
                }
                return null;
            }
        }));
    }
    return Futures.whenAllSucceed(futures).call(new Callable<Void>() {

        @Override
        public Void call() throws TargetParsingException {
            if (!foundTarget.get()) {
                throw new TargetParsingException("no targets found beneath '" + pathFragment + "'");
            }
            return null;
        }
    });
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) FilteringPolicy(com.google.devtools.build.lib.pkgcache.FilteringPolicy) Callable(java.util.concurrent.Callable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Target(com.google.devtools.build.lib.packages.Target) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) ResolvedTargets(com.google.devtools.build.lib.cmdline.ResolvedTargets) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with FilteringPolicy

use of com.google.devtools.build.lib.pkgcache.FilteringPolicy in project bazel by bazelbuild.

the class PrepareDepsOfTargetsUnderDirectoryFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    PrepareDepsOfTargetsUnderDirectoryKey argument = (PrepareDepsOfTargetsUnderDirectoryKey) skyKey.argument();
    final FilteringPolicy filteringPolicy = argument.getFilteringPolicy();
    RecursivePkgKey recursivePkgKey = argument.getRecursivePkgKey();
    ProcessPackageDirectory processPackageDirectory = new ProcessPackageDirectory(directories, new ProcessPackageDirectory.SkyKeyTransformer() {

        @Override
        public SkyKey makeSkyKey(RepositoryName repository, RootedPath subdirectory, ImmutableSet<PathFragment> excludedSubdirectoriesBeneathSubdirectory) {
            return PrepareDepsOfTargetsUnderDirectoryValue.key(repository, subdirectory, excludedSubdirectoriesBeneathSubdirectory, filteringPolicy);
        }
    });
    ProcessPackageDirectoryResult packageExistenceAndSubdirDeps = processPackageDirectory.getPackageExistenceAndSubdirDeps(recursivePkgKey.getRootedPath(), recursivePkgKey.getRepository(), env, recursivePkgKey.getExcludedPaths());
    if (env.valuesMissing()) {
        return null;
    }
    Iterable<SkyKey> keysToRequest = packageExistenceAndSubdirDeps.getChildDeps();
    if (packageExistenceAndSubdirDeps.packageExists()) {
        keysToRequest = Iterables.concat(ImmutableList.of(CollectTargetsInPackageValue.key(PackageIdentifier.create(recursivePkgKey.getRepository(), recursivePkgKey.getRootedPath().getRelativePath()), filteringPolicy)), keysToRequest);
    }
    env.getValuesOrThrow(keysToRequest, NoSuchPackageException.class);
    if (env.valuesMissing()) {
        return null;
    }
    return PrepareDepsOfTargetsUnderDirectoryValue.INSTANCE;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) RecursivePkgKey(com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) PrepareDepsOfTargetsUnderDirectoryKey(com.google.devtools.build.lib.skyframe.PrepareDepsOfTargetsUnderDirectoryValue.PrepareDepsOfTargetsUnderDirectoryKey) FilteringPolicy(com.google.devtools.build.lib.pkgcache.FilteringPolicy) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Aggregations

FilteringPolicy (com.google.devtools.build.lib.pkgcache.FilteringPolicy)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 ImmutableList (com.google.common.collect.ImmutableList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1 ResolvedTargets (com.google.devtools.build.lib.cmdline.ResolvedTargets)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 Target (com.google.devtools.build.lib.packages.Target)1 PrepareDepsOfTargetsUnderDirectoryKey (com.google.devtools.build.lib.skyframe.PrepareDepsOfTargetsUnderDirectoryValue.PrepareDepsOfTargetsUnderDirectoryKey)1 RecursivePkgKey (com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey)1 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1