use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveDirectoryTraversalFunction method visitDirectory.
/**
* Looks in the directory specified by {@code recursivePkgKey} for a package, does some work as
* specified by {@link Visitor} if such a package exists, then recursively does work in each
* non-excluded subdirectory as specified by {@link #getSkyKeyForSubdirectory}, and finally
* aggregates the {@link Visitor} value along with values from each subdirectory as specified by
* {@link #aggregateWithSubdirectorySkyValues}, and returns that aggregation.
*
* <p>Returns null if {@code env.valuesMissing()} is true, checked after each call to one of
* {@link RecursiveDirectoryTraversalFunction}'s abstract methods that were given {@code env}.
* (And after each of {@code visitDirectory}'s own uses of {@code env}, of course.)
*/
TReturn visitDirectory(RecursivePkgKey recursivePkgKey, Environment env) throws InterruptedException {
RootedPath rootedPath = recursivePkgKey.getRootedPath();
ProcessPackageDirectoryResult packageExistenceAndSubdirDeps = processPackageDirectory.getPackageExistenceAndSubdirDeps(rootedPath, recursivePkgKey.getRepository(), env, recursivePkgKey.getExcludedPaths());
if (env.valuesMissing()) {
return null;
}
Iterable<SkyKey> childDeps = packageExistenceAndSubdirDeps.getChildDeps();
TVisitor visitor = getInitialVisitor();
Map<SkyKey, SkyValue> subdirectorySkyValues;
if (packageExistenceAndSubdirDeps.packageExists()) {
PathFragment rootRelativePath = rootedPath.getRelativePath();
SkyKey packageKey = PackageValue.key(PackageIdentifier.create(recursivePkgKey.getRepository(), rootRelativePath));
Map<SkyKey, ValueOrException<NoSuchPackageException>> dependentSkyValues = env.getValuesOrThrow(Iterables.concat(childDeps, ImmutableList.of(packageKey)), NoSuchPackageException.class);
if (env.valuesMissing()) {
return null;
}
Package pkg = null;
try {
PackageValue pkgValue = (PackageValue) dependentSkyValues.get(packageKey).get();
if (pkgValue == null) {
return null;
}
pkg = pkgValue.getPackage();
if (pkg.containsErrors()) {
env.getListener().handle(Event.error("package contains errors: " + rootRelativePath.getPathString()));
}
} catch (NoSuchPackageException e) {
// The package had errors, but don't fail-fast as there might be subpackages below the
// current directory.
env.getListener().handle(Event.error(e.getMessage()));
visitor.visitPackageError(e, env);
if (env.valuesMissing()) {
return null;
}
}
if (pkg != null) {
visitor.visitPackageValue(pkg, env);
if (env.valuesMissing()) {
return null;
}
}
ImmutableMap.Builder<SkyKey, SkyValue> subdirectoryBuilder = ImmutableMap.builder();
for (Map.Entry<SkyKey, ValueOrException<NoSuchPackageException>> entry : Maps.filterKeys(dependentSkyValues, Predicates.not(Predicates.equalTo(packageKey))).entrySet()) {
try {
subdirectoryBuilder.put(entry.getKey(), entry.getValue().get());
} catch (NoSuchPackageException e) {
// ignored.
}
}
subdirectorySkyValues = subdirectoryBuilder.build();
} else {
subdirectorySkyValues = env.getValues(childDeps);
}
if (env.valuesMissing()) {
return null;
}
return aggregateWithSubdirectorySkyValues(visitor, subdirectorySkyValues);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunction method createRecursiveTraversalKeys.
/**
* List the directory and create {@code SkyKey}s to request contents of its children recursively.
*
* <p>The returned keys are of type {@link SkyFunctions#RECURSIVE_FILESYSTEM_TRAVERSAL}.
*/
private static Collection<SkyKey> createRecursiveTraversalKeys(Environment env, TraversalRequest traversal) throws MissingDepException, InterruptedException {
// Use the traversal's path, even if it's a symlink. The contents of the directory, as listed
// in the result, must be relative to it.
DirectoryListingValue dirListing = (DirectoryListingValue) getDependentSkyValue(env, DirectoryListingValue.key(traversal.path));
List<SkyKey> result = new ArrayList<>();
for (Dirent dirent : dirListing.getDirents()) {
RootedPath childPath = RootedPath.toRootedPath(traversal.path.getRoot(), traversal.path.getRelativePath().getRelative(dirent.getName()));
TraversalRequest childTraversal = traversal.forChildEntry(childPath);
result.add(RecursiveFilesystemTraversalValue.key(childTraversal));
}
return result;
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class ExternalFilesHelper method getAndNoteFileType.
FileType getAndNoteFileType(RootedPath rootedPath) {
PathPackageLocator packageLocator = pkgLocator.get();
if (packageLocator.getPathEntries().contains(rootedPath.getRoot())) {
return FileType.INTERNAL;
}
// The outputBase may be null if we're not actually running a build.
Path outputBase = packageLocator.getOutputBase();
if (outputBase == null) {
anyNonOutputExternalFilesSeen = true;
return FileType.EXTERNAL;
}
if (rootedPath.asPath().startsWith(outputBase)) {
Path externalRepoDir = outputBase.getRelative(Label.EXTERNAL_PACKAGE_NAME);
if (rootedPath.asPath().startsWith(externalRepoDir)) {
anyNonOutputExternalFilesSeen = true;
return FileType.EXTERNAL_REPO;
} else {
anyOutputFilesSeen = true;
return FileType.OUTPUT;
}
}
anyNonOutputExternalFilesSeen = true;
return FileType.EXTERNAL;
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class ExternalPackageFunction method compute.
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
RootedPath workspacePath = (RootedPath) skyKey.argument();
SkyKey key = WorkspaceFileValue.key(workspacePath);
WorkspaceFileValue value = (WorkspaceFileValue) env.getValue(key);
if (value == null) {
return null;
}
// file.
while (value.next() != null) {
value = (WorkspaceFileValue) env.getValue(value.next());
if (value == null) {
return null;
}
}
return new PackageValue(value.getPackage());
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class FileFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws FileFunctionException, InterruptedException {
RootedPath rootedPath = (RootedPath) skyKey.argument();
RootedPath realRootedPath = null;
FileStateValue realFileStateValue = null;
PathFragment relativePath = rootedPath.getRelativePath();
// than we'd get doing bogus filesystem operations.
if (!relativePath.equals(PathFragment.EMPTY_FRAGMENT)) {
Pair<RootedPath, FileStateValue> resolvedState = resolveFromAncestors(rootedPath, env);
if (resolvedState == null) {
return null;
}
realRootedPath = resolvedState.getFirst();
realFileStateValue = resolvedState.getSecond();
if (realFileStateValue.getType() == Type.NONEXISTENT) {
return FileValue.value(rootedPath, FileStateValue.NONEXISTENT_FILE_STATE_NODE, realRootedPath, realFileStateValue);
}
}
FileStateValue fileStateValue;
if (rootedPath.equals(realRootedPath)) {
fileStateValue = Preconditions.checkNotNull(realFileStateValue, rootedPath);
} else {
fileStateValue = (FileStateValue) env.getValue(FileStateValue.key(rootedPath));
if (fileStateValue == null) {
return null;
}
}
if (realFileStateValue == null) {
realRootedPath = rootedPath;
realFileStateValue = fileStateValue;
}
ArrayList<RootedPath> symlinkChain = new ArrayList<>();
TreeSet<Path> orderedSeenPaths = Sets.newTreeSet();
while (realFileStateValue.getType().equals(FileStateValue.Type.SYMLINK)) {
symlinkChain.add(realRootedPath);
orderedSeenPaths.add(realRootedPath.asPath());
Pair<RootedPath, FileStateValue> resolvedState = getSymlinkTargetRootedPath(realRootedPath, realFileStateValue.getSymlinkTarget(), orderedSeenPaths, symlinkChain, env);
if (resolvedState == null) {
return null;
}
realRootedPath = resolvedState.getFirst();
realFileStateValue = resolvedState.getSecond();
}
return FileValue.value(rootedPath, fileStateValue, realRootedPath, realFileStateValue);
}
Aggregations