Search in sources :

Example 11 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier 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();
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) TargetPatternKey(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) TargetPattern(com.google.devtools.build.lib.cmdline.TargetPattern) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) RepositoryDirectoryValue(com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue)

Example 12 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class SequencedSkyframeExecutor method invalidateDeletedPackages.

private void invalidateDeletedPackages(Iterable<PackageIdentifier> deletedPackages) {
    ArrayList<SkyKey> packagesToInvalidate = Lists.newArrayList();
    for (PackageIdentifier deletedPackage : deletedPackages) {
        packagesToInvalidate.add(PackageLookupValue.key(deletedPackage));
    }
    recordingDiffer.invalidate(packagesToInvalidate);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier)

Example 13 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class PackageErrorFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws PackageErrorFunctionException, InterruptedException {
    PackageIdentifier packageIdentifier = (PackageIdentifier) skyKey.argument();
    try {
        SkyKey packageKey = PackageValue.key(packageIdentifier);
        // Callers must have tried to load the package already and gotten the package successfully.
        Package pkg = ((PackageValue) env.getValueOrThrow(packageKey, NoSuchPackageException.class)).getPackage();
        Preconditions.checkState(pkg.containsErrors(), skyKey);
        throw new PackageErrorFunctionException(new BuildFileContainsErrorsException(packageIdentifier), Transience.PERSISTENT);
    } catch (NoSuchPackageException e) {
        throw new IllegalStateException("Function should not have been called on package with exception", e);
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileContainsErrorsException(com.google.devtools.build.lib.packages.BuildFileContainsErrorsException) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Package(com.google.devtools.build.lib.packages.Package) Nullable(javax.annotation.Nullable)

Example 14 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier 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 15 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier 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)49 SkyKey (com.google.devtools.build.skyframe.SkyKey)17 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)16 Package (com.google.devtools.build.lib.packages.Package)14 Label (com.google.devtools.build.lib.cmdline.Label)12 Path (com.google.devtools.build.lib.vfs.Path)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)8 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)7 Target (com.google.devtools.build.lib.packages.Target)7 Nullable (javax.annotation.Nullable)7 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)6 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)5 Map (java.util.Map)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 ResolvedTargets (com.google.devtools.build.lib.cmdline.ResolvedTargets)3