Search in sources :

Example 21 with NoSuchPackageException

use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.

the class PackageLookupFunction method computeExternalPackageLookupValue.

/**
   * Gets a PackageLookupValue from a different Bazel repository.
   *
   * <p>To do this, it looks up the "external" package and finds a path mapping for the repository
   * name.
   */
private PackageLookupValue computeExternalPackageLookupValue(SkyKey skyKey, Environment env, PackageIdentifier packageIdentifier) throws PackageLookupFunctionException, InterruptedException {
    PackageIdentifier id = (PackageIdentifier) skyKey.argument();
    SkyKey repositoryKey = RepositoryValue.key(id.getRepository());
    RepositoryValue repositoryValue;
    try {
        repositoryValue = (RepositoryValue) env.getValueOrThrow(repositoryKey, NoSuchPackageException.class, IOException.class, EvalException.class);
        if (repositoryValue == null) {
            return null;
        }
    } catch (NoSuchPackageException | IOException | EvalException e) {
        throw new PackageLookupFunctionException(new BuildFileNotFoundException(id, e.getMessage()), Transience.PERSISTENT);
    }
    // This checks for the build file names in the correct precedence order.
    for (BuildFileName buildFileName : buildFilesByPriority) {
        PathFragment buildFileFragment = id.getPackageFragment().getChild(buildFileName.getFilename());
        RootedPath buildFileRootedPath = RootedPath.toRootedPath(repositoryValue.getPath(), buildFileFragment);
        FileValue fileValue = getFileValue(buildFileRootedPath, env, packageIdentifier);
        if (fileValue == null) {
            return null;
        }
        if (fileValue.isFile()) {
            return PackageLookupValue.success(repositoryValue.getPath(), buildFileName);
        }
    }
    return PackageLookupValue.NO_BUILD_FILE_VALUE;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) BuildFileName(com.google.devtools.build.lib.skyframe.PackageLookupValue.BuildFileName) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException)

Example 22 with NoSuchPackageException

use of com.google.devtools.build.lib.packages.NoSuchPackageException 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 23 with NoSuchPackageException

use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.

the class EnvironmentBackedRecursivePackageProvider method getPackage.

@Override
public Package getPackage(ExtendedEventHandler eventHandler, PackageIdentifier packageName) throws NoSuchPackageException, MissingDepException, InterruptedException {
    SkyKey pkgKey = PackageValue.key(packageName);
    PackageValue pkgValue = (PackageValue) env.getValueOrThrow(pkgKey, NoSuchPackageException.class);
    if (pkgValue == null) {
        throw new MissingDepException();
    }
    Package pkg = pkgValue.getPackage();
    if (pkg.containsErrors()) {
        // continue. This gives the framework notification to shut down the build if it should.
        try {
            env.getValueOrThrow(PackageErrorFunction.key(packageName), BuildFileContainsErrorsException.class);
            Preconditions.checkState(env.valuesMissing(), "Should have thrown for %s", packageName);
            throw new MissingDepException();
        } catch (BuildFileContainsErrorsException e) {
        // Expected.
        }
    }
    return pkgValue.getPackage();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileContainsErrorsException(com.google.devtools.build.lib.packages.BuildFileContainsErrorsException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Package(com.google.devtools.build.lib.packages.Package)

Example 24 with NoSuchPackageException

use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.

the class GraphBackedRecursivePackageProvider method getPackage.

@Override
public Package getPackage(ExtendedEventHandler eventHandler, PackageIdentifier packageName) throws NoSuchPackageException, InterruptedException {
    SkyKey pkgKey = PackageValue.key(packageName);
    PackageValue pkgValue = (PackageValue) graph.getValue(pkgKey);
    if (pkgValue != null) {
        return pkgValue.getPackage();
    }
    NoSuchPackageException nspe = (NoSuchPackageException) graph.getException(pkgKey);
    if (nspe != null) {
        throw nspe;
    }
    if (graph.isCycle(pkgKey)) {
        throw new NoSuchPackageException(packageName, "Package depends on a cycle");
    } else {
        // because the SkyQuery environment has already loaded the universe.
        throw new BuildFileNotFoundException(packageName, "BUILD file not found on package path");
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException)

Example 25 with NoSuchPackageException

use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.

the class PrepareDepsOfPatternsFunctionTest method testDependencyTraversalNoSuchPackageException.

@Test
public void testDependencyTraversalNoSuchPackageException() throws Exception {
    // Given a package "//foo" with a target ":foo" that has a dependency on a non-existent target
    // "//bar:bar" in a non-existent package "//bar",
    createFooWithDependencyOnMissingBarPackage();
    // Given a target pattern sequence consisting of a single-target pattern for "//foo",
    ImmutableList<String> patternSequence = ImmutableList.of("//foo");
    // When PrepareDepsOfPatternsFunction completes evaluation,
    WalkableGraph walkableGraph = getGraphFromPatternsEvaluation(patternSequence);
    // Then the graph contains an entry for ":foo",
    assertValidValue(walkableGraph, getKeyForLabel(Label.create("@//foo", "foo")), /*expectTransitiveException=*/
    true);
    // And an entry with a NoSuchPackageException for "//bar:bar",
    Exception e = assertException(walkableGraph, getKeyForLabel(Label.create("@//bar", "bar")));
    assertThat(e).isInstanceOf(NoSuchPackageException.class);
}
Also used : WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) IOException(java.io.IOException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Test(org.junit.Test)

Aggregations

NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)27 SkyKey (com.google.devtools.build.skyframe.SkyKey)21 Package (com.google.devtools.build.lib.packages.Package)13 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)11 Label (com.google.devtools.build.lib.cmdline.Label)10 Target (com.google.devtools.build.lib.packages.Target)8 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)7 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)6 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)6 Nullable (javax.annotation.Nullable)6 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)5 IOException (java.io.IOException)5 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 SkyValue (com.google.devtools.build.skyframe.SkyValue)4 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Path (com.google.devtools.build.lib.vfs.Path)3 Map (java.util.Map)3 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)2 Attribute (com.google.devtools.build.lib.packages.Attribute)2