Search in sources :

Example 1 with ValueOrException3

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

the class PackageFunction method handleLabelsCrossingSubpackagesAndPropagateInconsistentFilesystemExceptions.

private static void handleLabelsCrossingSubpackagesAndPropagateInconsistentFilesystemExceptions(Path pkgRoot, PackageIdentifier pkgId, Package.Builder pkgBuilder, Environment env) throws InternalInconsistentFilesystemException, InterruptedException {
    Set<SkyKey> containingPkgLookupKeys = Sets.newHashSet();
    Map<Target, SkyKey> targetToKey = new HashMap<>();
    for (Target target : pkgBuilder.getTargets()) {
        PathFragment dir = target.getLabel().toPathFragment().getParentDirectory();
        PackageIdentifier dirId = PackageIdentifier.create(pkgId.getRepository(), dir);
        if (dir.equals(pkgId.getPackageFragment())) {
            continue;
        }
        SkyKey key = ContainingPackageLookupValue.key(dirId);
        targetToKey.put(target, key);
        containingPkgLookupKeys.add(key);
    }
    Map<Label, SkyKey> subincludeToKey = new HashMap<>();
    for (Label subincludeLabel : pkgBuilder.getSubincludeLabels()) {
        PathFragment dir = subincludeLabel.toPathFragment().getParentDirectory();
        PackageIdentifier dirId = PackageIdentifier.create(pkgId.getRepository(), dir);
        if (dir.equals(pkgId.getPackageFragment())) {
            continue;
        }
        SkyKey key = ContainingPackageLookupValue.key(dirId);
        subincludeToKey.put(subincludeLabel, key);
        containingPkgLookupKeys.add(ContainingPackageLookupValue.key(dirId));
    }
    Map<SkyKey, ValueOrException3<BuildFileNotFoundException, InconsistentFilesystemException, FileSymlinkException>> containingPkgLookupValues = env.getValuesOrThrow(containingPkgLookupKeys, BuildFileNotFoundException.class, InconsistentFilesystemException.class, FileSymlinkException.class);
    if (env.valuesMissing()) {
        return;
    }
    for (Target target : ImmutableSet.copyOf(pkgBuilder.getTargets())) {
        SkyKey key = targetToKey.get(target);
        if (!containingPkgLookupValues.containsKey(key)) {
            continue;
        }
        ContainingPackageLookupValue containingPackageLookupValue = getContainingPkgLookupValueAndPropagateInconsistentFilesystemExceptions(pkgId, containingPkgLookupValues.get(key), env);
        if (maybeAddEventAboutLabelCrossingSubpackage(pkgBuilder, pkgRoot, target.getLabel(), target.getLocation(), containingPackageLookupValue)) {
            pkgBuilder.removeTarget(target);
            pkgBuilder.setContainsErrors();
        }
    }
    for (Label subincludeLabel : pkgBuilder.getSubincludeLabels()) {
        SkyKey key = subincludeToKey.get(subincludeLabel);
        if (!containingPkgLookupValues.containsKey(key)) {
            continue;
        }
        ContainingPackageLookupValue containingPackageLookupValue = getContainingPkgLookupValueAndPropagateInconsistentFilesystemExceptions(pkgId, containingPkgLookupValues.get(key), env);
        if (maybeAddEventAboutLabelCrossingSubpackage(pkgBuilder, pkgRoot, subincludeLabel, /*location=*/
        null, containingPackageLookupValue)) {
            pkgBuilder.setContainsErrors();
        }
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Target(com.google.devtools.build.lib.packages.Target) ValueOrException3(com.google.devtools.build.skyframe.ValueOrException3) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Label(com.google.devtools.build.lib.cmdline.Label)

Example 2 with ValueOrException3

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

the class PackageFunction method getPackageLookupDepsAndPropagateInconsistentFilesystemExceptions.

/**
   * Marks the given dependencies, and returns those already present. Ignores any exception thrown
   * while building the dependency, except for filesystem inconsistencies.
   *
   * <p>We need to mark dependencies implicitly used by the legacy package loading code, but we
   * don't care about any skyframe errors since the package knows whether it's in error or not.
   */
private static Pair<? extends Map<PathFragment, PackageLookupValue>, Boolean> getPackageLookupDepsAndPropagateInconsistentFilesystemExceptions(PackageIdentifier packageIdentifier, Iterable<SkyKey> depKeys, Environment env, boolean packageWasInError) throws InternalInconsistentFilesystemException, InterruptedException {
    Preconditions.checkState(Iterables.all(depKeys, SkyFunctions.isSkyFunction(SkyFunctions.PACKAGE_LOOKUP)), depKeys);
    boolean packageShouldBeInError = packageWasInError;
    ImmutableMap.Builder<PathFragment, PackageLookupValue> builder = ImmutableMap.builder();
    for (Map.Entry<SkyKey, ValueOrException3<BuildFileNotFoundException, InconsistentFilesystemException, FileSymlinkException>> entry : env.getValuesOrThrow(depKeys, BuildFileNotFoundException.class, InconsistentFilesystemException.class, FileSymlinkException.class).entrySet()) {
        PathFragment pkgName = ((PackageIdentifier) entry.getKey().argument()).getPackageFragment();
        try {
            PackageLookupValue value = (PackageLookupValue) entry.getValue().get();
            if (value != null) {
                builder.put(pkgName, value);
            }
        } catch (BuildFileNotFoundException e) {
            maybeThrowFilesystemInconsistency(packageIdentifier, e, packageWasInError);
        } catch (InconsistentFilesystemException e) {
            throw new InternalInconsistentFilesystemException(packageIdentifier, e);
        } catch (FileSymlinkException e) {
            // Legacy doesn't detect symlink cycles.
            packageShouldBeInError = true;
        }
    }
    return Pair.of(builder.build(), packageShouldBeInError);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ValueOrException3(com.google.devtools.build.skyframe.ValueOrException3) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ImmutableMap(com.google.common.collect.ImmutableMap) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 ValueOrException3 (com.google.devtools.build.skyframe.ValueOrException3)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Label (com.google.devtools.build.lib.cmdline.Label)1 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)1 Target (com.google.devtools.build.lib.packages.Target)1 Map (java.util.Map)1