Search in sources :

Example 1 with ValueOrException4

use of com.google.devtools.build.skyframe.ValueOrException4 in project bazel by bazelbuild.

the class ProcessPackageDirectory method getPackageExistenceAndSubdirDeps.

/**
   * Examines {@code rootedPath} to see if it is the location of a package, and to see if it has any
   * subdirectory children that should also be examined. Returns a {@link
   * ProcessPackageDirectoryResult}, or {@code null} if required dependencies were missing.
   */
@Nullable
ProcessPackageDirectoryResult getPackageExistenceAndSubdirDeps(RootedPath rootedPath, RepositoryName repositoryName, SkyFunction.Environment env, Set<PathFragment> excludedPaths) throws InterruptedException {
    PathFragment rootRelativePath = rootedPath.getRelativePath();
    SkyKey fileKey = FileValue.key(rootedPath);
    FileValue fileValue;
    try {
        fileValue = (FileValue) env.getValueOrThrow(fileKey, InconsistentFilesystemException.class, FileSymlinkException.class, IOException.class);
    } catch (InconsistentFilesystemException | FileSymlinkException | IOException e) {
        return reportErrorAndReturn("Failed to get information about path", e, rootRelativePath, env.getListener());
    }
    if (env.valuesMissing()) {
        return null;
    }
    if (!fileValue.isDirectory()) {
        return ProcessPackageDirectoryResult.EMPTY_RESULT;
    }
    PackageIdentifier packageId = PackageIdentifier.create(repositoryName, rootRelativePath);
    if ((packageId.getRepository().isDefault() || packageId.getRepository().isMain()) && fileValue.isSymlink() && fileValue.getUnresolvedLinkTarget().startsWith(directories.getOutputBase().asFragment())) {
        // somewhere in the directory tree manually.
        return ProcessPackageDirectoryResult.EMPTY_RESULT;
    }
    SkyKey pkgLookupKey = PackageLookupValue.key(packageId);
    SkyKey dirListingKey = DirectoryListingValue.key(rootedPath);
    Map<SkyKey, ValueOrException4<NoSuchPackageException, InconsistentFilesystemException, FileSymlinkException, IOException>> pkgLookupAndDirectoryListingDeps = env.getValuesOrThrow(ImmutableList.of(pkgLookupKey, dirListingKey), NoSuchPackageException.class, InconsistentFilesystemException.class, FileSymlinkException.class, IOException.class);
    if (env.valuesMissing()) {
        return null;
    }
    PackageLookupValue pkgLookupValue;
    try {
        pkgLookupValue = (PackageLookupValue) Preconditions.checkNotNull(pkgLookupAndDirectoryListingDeps.get(pkgLookupKey).get(), "%s %s %s", rootedPath, repositoryName, pkgLookupKey);
    } catch (NoSuchPackageException | InconsistentFilesystemException e) {
        return reportErrorAndReturn("Failed to load package", e, rootRelativePath, env.getListener());
    } catch (IOException | FileSymlinkException e) {
        throw new IllegalStateException(e);
    }
    DirectoryListingValue dirListingValue;
    try {
        dirListingValue = (DirectoryListingValue) Preconditions.checkNotNull(pkgLookupAndDirectoryListingDeps.get(dirListingKey).get(), "%s %s %s", rootedPath, repositoryName, dirListingKey);
    } catch (InconsistentFilesystemException | IOException e) {
        return reportErrorAndReturn("Failed to list directory contents", e, rootRelativePath, env.getListener());
    } catch (FileSymlinkException e) {
        // be able to avoid throwing there but throw here.
        throw new IllegalStateException("Symlink cycle found after not being found for \"" + rootedPath + "\"");
    } catch (NoSuchPackageException e) {
        throw new IllegalStateException(e);
    }
    return new ProcessPackageDirectoryResult(pkgLookupValue.packageExists() && pkgLookupValue.getRoot().equals(rootedPath.getRoot()), getSubdirDeps(dirListingValue, rootedPath, repositoryName, excludedPaths));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ValueOrException4(com.google.devtools.build.skyframe.ValueOrException4) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Nullable(javax.annotation.Nullable)

Aggregations

PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)1 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 ValueOrException4 (com.google.devtools.build.skyframe.ValueOrException4)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1