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;
}
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);
}
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();
}
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");
}
}
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);
}
Aggregations