Search in sources :

Example 56 with RootedPath

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);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) ImmutableMap(com.google.common.collect.ImmutableMap) SkyValue(com.google.devtools.build.skyframe.SkyValue) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Package(com.google.devtools.build.lib.packages.Package) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 57 with RootedPath

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TraversalRequest(com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest) ArrayList(java.util.ArrayList) Dirent(com.google.devtools.build.lib.vfs.Dirent) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 58 with RootedPath

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

Example 59 with RootedPath

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());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Nullable(javax.annotation.Nullable)

Example 60 with RootedPath

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);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Aggregations

RootedPath (com.google.devtools.build.lib.vfs.RootedPath)84 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)43 SkyKey (com.google.devtools.build.skyframe.SkyKey)41 Test (org.junit.Test)33 Path (com.google.devtools.build.lib.vfs.Path)28 Artifact (com.google.devtools.build.lib.actions.Artifact)21 IOException (java.io.IOException)15 Package (com.google.devtools.build.lib.packages.Package)13 SkyValue (com.google.devtools.build.skyframe.SkyValue)11 TraversalRequest (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest)9 ResolvedFile (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile)8 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)7 EvalException (com.google.devtools.build.lib.syntax.EvalException)7 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)7 Dirent (com.google.devtools.build.lib.vfs.Dirent)6 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)5 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)5 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 FileValue (com.google.devtools.build.lib.skyframe.FileValue)5 Map (java.util.Map)5