use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class GraphBackedRecursivePackageProvider method collectPackagesUnder.
private void collectPackagesUnder(ExtendedEventHandler eventHandler, final RepositoryName repository, Set<TraversalInfo> traversals, ImmutableList.Builder<PathFragment> builder) throws InterruptedException {
Map<TraversalInfo, SkyKey> traversalToKeyMap = Maps.asMap(traversals, new Function<TraversalInfo, SkyKey>() {
@Override
public SkyKey apply(TraversalInfo traversalInfo) {
return CollectPackagesUnderDirectoryValue.key(repository, traversalInfo.rootedDir, traversalInfo.excludedSubdirectories);
}
});
Map<SkyKey, SkyValue> values = graph.getSuccessfulValues(traversalToKeyMap.values());
ImmutableSet.Builder<TraversalInfo> subdirTraversalBuilder = ImmutableSet.builder();
for (Map.Entry<TraversalInfo, SkyKey> entry : traversalToKeyMap.entrySet()) {
TraversalInfo info = entry.getKey();
SkyKey key = entry.getValue();
SkyValue val = values.get(key);
CollectPackagesUnderDirectoryValue collectPackagesValue = (CollectPackagesUnderDirectoryValue) val;
if (collectPackagesValue != null) {
if (collectPackagesValue.isDirectoryPackage()) {
builder.add(info.rootedDir.getRelativePath());
}
if (collectPackagesValue.getErrorMessage() != null) {
eventHandler.handle(Event.error(collectPackagesValue.getErrorMessage()));
}
ImmutableMap<RootedPath, Boolean> subdirectoryTransitivelyContainsPackages = collectPackagesValue.getSubdirectoryTransitivelyContainsPackagesOrErrors();
for (RootedPath subdirectory : subdirectoryTransitivelyContainsPackages.keySet()) {
if (subdirectoryTransitivelyContainsPackages.get(subdirectory)) {
PathFragment subdirectoryRelativePath = subdirectory.getRelativePath();
ImmutableSet<PathFragment> excludedSubdirectoriesBeneathThisSubdirectory = PathFragment.filterPathsStartingWith(info.excludedSubdirectories, subdirectoryRelativePath);
subdirTraversalBuilder.add(new TraversalInfo(subdirectory, excludedSubdirectoriesBeneathThisSubdirectory));
}
}
}
}
ImmutableSet<TraversalInfo> subdirTraversals = subdirTraversalBuilder.build();
if (!subdirTraversals.isEmpty()) {
collectPackagesUnder(eventHandler, repository, subdirTraversals, builder);
}
}
use of com.google.devtools.build.lib.vfs.RootedPath 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.vfs.RootedPath in project bazel by bazelbuild.
the class LocalRepositoryLookupFunction method compute.
// Implementation note: Although LocalRepositoryLookupValue.NOT_FOUND exists, it should never be
// returned from this method.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
RootedPath directory = (RootedPath) skyKey.argument();
// before this can be called if that is incorrect.
if (directory.getRelativePath().equals(PathFragment.EMPTY_FRAGMENT)) {
return LocalRepositoryLookupValue.mainRepository();
}
// Does this directory contain a WORKSPACE file?
Optional<Boolean> maybeWorkspaceFileExists = maybeGetWorkspaceFileExistence(env, directory);
if (!maybeWorkspaceFileExists.isPresent()) {
return null;
} else if (maybeWorkspaceFileExists.get()) {
Optional<LocalRepositoryLookupValue> maybeRepository = maybeCheckWorkspaceForRepository(env, directory);
if (!maybeRepository.isPresent()) {
return null;
}
LocalRepositoryLookupValue repository = maybeRepository.get();
// If the repository that was discovered doesn't exist, continue recursing.
if (repository.exists()) {
return repository;
}
}
// If we haven't found a repository yet, check the parent directory.
RootedPath parentDirectory = RootedPath.toRootedPath(directory.getRoot(), directory.getRelativePath().getParentDirectory());
return env.getValue(LocalRepositoryLookupValue.key(parentDirectory));
}
use of com.google.devtools.build.lib.vfs.RootedPath 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;
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class SkyframeIncrementalBuildMonitor method accrue.
public void accrue(Iterable<SkyKey> invalidatedValues) {
for (SkyKey skyKey : invalidatedValues) {
if (skyKey.functionName().equals(SkyFunctions.FILE_STATE)) {
RootedPath file = (RootedPath) skyKey.argument();
maybeAddFile(file.getRelativePath());
}
}
}
Aggregations