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();
}
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);
}
Aggregations