use of com.google.devtools.build.lib.packages.BuildFileNotFoundException in project bazel by bazelbuild.
the class TargetMarkerFunctionTest method testTargetFunctionRethrowsExceptions.
@Test
public void testTargetFunctionRethrowsExceptions() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("a/BUILD", "sh_library(name = 'b/c')");
Path subpackageBuildFile = scratch.file("a/b/BUILD", "sh_library(name = 'c')");
fs.stubStatIOException(subpackageBuildFile, new IOException("nope"));
BuildFileNotFoundException exn = (BuildFileNotFoundException) getErrorFromTargetValue("//a:b/c");
assertThat(exn.getMessage()).contains("nope");
}
use of com.google.devtools.build.lib.packages.BuildFileNotFoundException in project bazel by bazelbuild.
the class ASTFileLookupFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
Label fileLabel = (Label) skyKey.argument();
PathFragment filePathFragment = fileLabel.toPathFragment();
//
// Determine whether the package designated by fileLabel exists.
//
SkyKey pkgSkyKey = PackageLookupValue.key(fileLabel.getPackageIdentifier());
PackageLookupValue pkgLookupValue = null;
try {
pkgLookupValue = (PackageLookupValue) env.getValueOrThrow(pkgSkyKey, BuildFileNotFoundException.class, InconsistentFilesystemException.class);
} catch (BuildFileNotFoundException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(e), Transience.PERSISTENT);
} catch (InconsistentFilesystemException e) {
throw new ASTLookupFunctionException(e, Transience.PERSISTENT);
}
if (pkgLookupValue == null) {
return null;
}
if (!pkgLookupValue.packageExists()) {
return ASTFileLookupValue.forBadPackage(fileLabel, pkgLookupValue.getErrorMsg());
}
//
// Determine whether the file designated by fileLabel exists.
//
Path packageRoot = pkgLookupValue.getRoot();
RootedPath rootedPath = RootedPath.toRootedPath(packageRoot, filePathFragment);
SkyKey fileSkyKey = FileValue.key(rootedPath);
FileValue fileValue = null;
try {
fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
} catch (IOException | FileSymlinkException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(e), Transience.PERSISTENT);
} catch (InconsistentFilesystemException e) {
throw new ASTLookupFunctionException(e, Transience.PERSISTENT);
}
if (fileValue == null) {
return null;
}
if (!fileValue.isFile()) {
return ASTFileLookupValue.forBadFile(fileLabel);
}
//
// Both the package and the file exist; load the file and parse it as an AST.
//
BuildFileAST ast = null;
Path path = rootedPath.asPath();
try {
long astFileSize = fileValue.getSize();
try (Mutability mutability = Mutability.create("validate")) {
ValidationEnvironment validationEnv = new ValidationEnvironment(ruleClassProvider.createSkylarkRuleClassEnvironment(fileLabel, mutability, env.getListener(), /*astFileContentHashCode=*/
null, /*importMap=*/
null).setupDynamic(Runtime.PKG_NAME, Runtime.NONE).setupDynamic(Runtime.REPOSITORY_NAME, Runtime.NONE));
ast = BuildFileAST.parseSkylarkFile(path, astFileSize, env.getListener());
ast = ast.validate(validationEnv, env.getListener());
}
} catch (IOException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(e), Transience.TRANSIENT);
}
return ASTFileLookupValue.withFile(ast);
}
use of com.google.devtools.build.lib.packages.BuildFileNotFoundException in project bazel by bazelbuild.
the class GraphBackedRecursivePackageProvider method bulkGetPackages.
@Override
public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) throws NoSuchPackageException, InterruptedException {
Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));
ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
for (Map.Entry<SkyKey, SkyValue> pkgEntry : packages.entrySet()) {
PackageIdentifier pkgId = (PackageIdentifier) pkgEntry.getKey().argument();
PackageValue pkgValue = (PackageValue) pkgEntry.getValue();
pkgResults.put(pkgId, Preconditions.checkNotNull(pkgValue.getPackage(), pkgId));
}
SetView<SkyKey> unknownKeys = Sets.difference(pkgKeys, packages.keySet());
if (!Iterables.isEmpty(unknownKeys)) {
LOGGER.warning("Unable to find " + unknownKeys + " in the batch lookup of " + pkgKeys + ". Successfully looked up " + packages.keySet());
}
for (Map.Entry<SkyKey, Exception> missingOrExceptionEntry : graph.getMissingAndExceptions(unknownKeys).entrySet()) {
PackageIdentifier pkgIdentifier = (PackageIdentifier) missingOrExceptionEntry.getKey().argument();
Exception exception = missingOrExceptionEntry.getValue();
if (exception == null) {
// package, because the SkyQuery environment has already loaded the universe.
throw new BuildFileNotFoundException(pkgIdentifier, "Package not found");
}
Throwables.propagateIfInstanceOf(exception, NoSuchPackageException.class);
Throwables.propagate(exception);
}
return pkgResults.build();
}
use of com.google.devtools.build.lib.packages.BuildFileNotFoundException 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);
}
use of com.google.devtools.build.lib.packages.BuildFileNotFoundException in project bazel by bazelbuild.
the class PackageLookupFunction method getFileValue.
@Nullable
private static FileValue getFileValue(RootedPath fileRootedPath, Environment env, PackageIdentifier packageIdentifier) throws PackageLookupFunctionException, InterruptedException {
String basename = fileRootedPath.asPath().getBaseName();
SkyKey fileSkyKey = FileValue.key(fileRootedPath);
FileValue fileValue = null;
try {
fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
} catch (IOException e) {
// BuildFileNotFoundException.
throw new PackageLookupFunctionException(new BuildFileNotFoundException(packageIdentifier, "IO errors while looking for " + basename + " file reading " + fileRootedPath.asPath() + ": " + e.getMessage(), e), Transience.PERSISTENT);
} catch (FileSymlinkException e) {
throw new PackageLookupFunctionException(new BuildFileNotFoundException(packageIdentifier, "Symlink cycle detected while trying to find " + basename + " file " + fileRootedPath.asPath()), Transience.PERSISTENT);
} catch (InconsistentFilesystemException e) {
// This error is not transient from the perspective of the PackageLookupFunction.
throw new PackageLookupFunctionException(e, Transience.PERSISTENT);
}
return fileValue;
}
Aggregations