Search in sources :

Example 1 with RepositoryDirectoryValue

use of com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue in project bazel by bazelbuild.

the class GraphBackedRecursivePackageProvider method getPackagesUnderDirectory.

@Override
public Iterable<PathFragment> getPackagesUnderDirectory(ExtendedEventHandler eventHandler, RepositoryName repository, PathFragment directory, ImmutableSet<PathFragment> excludedSubdirectories) throws InterruptedException {
    PathFragment.checkAllPathsAreUnder(excludedSubdirectories, directory);
    // Check that this package is covered by at least one of our universe patterns.
    boolean inUniverse = false;
    for (TargetPatternKey patternKey : universeTargetPatternKeys) {
        TargetPattern pattern = patternKey.getParsedPattern();
        boolean isTBD = pattern.getType().equals(Type.TARGETS_BELOW_DIRECTORY);
        PackageIdentifier packageIdentifier = PackageIdentifier.create(repository, directory);
        if (isTBD && pattern.containsAllTransitiveSubdirectoriesForTBD(packageIdentifier)) {
            inUniverse = true;
            break;
        }
    }
    if (!inUniverse) {
        return ImmutableList.of();
    }
    List<Path> roots = new ArrayList<>();
    if (repository.isMain()) {
        roots.addAll(pkgPath.getPathEntries());
    } else {
        RepositoryDirectoryValue repositoryValue = (RepositoryDirectoryValue) graph.getValue(RepositoryDirectoryValue.key(repository));
        if (repositoryValue == null) {
            // "nothing".
            return ImmutableList.of();
        }
        roots.add(repositoryValue.getPath());
    }
    // If we found a TargetsBelowDirectory pattern in the universe that contains this directory,
    // then we can look for packages in and under it in the graph. If we didn't find one, then the
    // directory wasn't in the universe, so return an empty list.
    ImmutableList.Builder<PathFragment> builder = ImmutableList.builder();
    for (Path root : roots) {
        RootedPath rootedDir = RootedPath.toRootedPath(root, directory);
        TraversalInfo info = new TraversalInfo(rootedDir, excludedSubdirectories);
        collectPackagesUnder(eventHandler, repository, ImmutableSet.of(info), builder);
    }
    return builder.build();
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) TargetPatternKey(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) TargetPattern(com.google.devtools.build.lib.cmdline.TargetPattern) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) RepositoryDirectoryValue(com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue)

Example 2 with RepositoryDirectoryValue

use of com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue in project bazel by bazelbuild.

the class EnvironmentBackedRecursivePackageProvider method getPackagesUnderDirectory.

@Override
public Iterable<PathFragment> getPackagesUnderDirectory(ExtendedEventHandler eventHandler, RepositoryName repository, PathFragment directory, ImmutableSet<PathFragment> excludedSubdirectories) throws MissingDepException, InterruptedException {
    PathPackageLocator packageLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
    if (packageLocator == null) {
        throw new MissingDepException();
    }
    List<Path> roots = new ArrayList<>();
    if (repository.isMain()) {
        roots.addAll(packageLocator.getPathEntries());
    } else {
        RepositoryDirectoryValue repositoryValue = (RepositoryDirectoryValue) env.getValue(RepositoryDirectoryValue.key(repository));
        if (repositoryValue == null) {
            throw new MissingDepException();
        }
        roots.add(repositoryValue.getPath());
    }
    NestedSetBuilder<String> packageNames = NestedSetBuilder.stableOrder();
    for (Path root : roots) {
        PathFragment.checkAllPathsAreUnder(excludedSubdirectories, directory);
        RecursivePkgValue lookup = (RecursivePkgValue) env.getValue(RecursivePkgValue.key(repository, RootedPath.toRootedPath(root, directory), excludedSubdirectories));
        if (lookup == null) {
            // the exception types it can accept.
            throw new MissingDepException();
        }
        packageNames.addTransitive(lookup.getPackages());
    }
    // unnecessary.
    return Iterables.transform(packageNames.build(), PathFragment.TO_PATH_FRAGMENT);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) RepositoryDirectoryValue(com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue) ArrayList(java.util.ArrayList)

Aggregations

RepositoryDirectoryValue (com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue)2 Path (com.google.devtools.build.lib.vfs.Path)2 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)1 TargetPattern (com.google.devtools.build.lib.cmdline.TargetPattern)1 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)1 TargetPatternKey (com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1