Search in sources :

Example 1 with BuildFileNotFoundException

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");
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with BuildFileNotFoundException

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);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) ValidationEnvironment(com.google.devtools.build.lib.syntax.ValidationEnvironment) Label(com.google.devtools.build.lib.cmdline.Label) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Mutability(com.google.devtools.build.lib.syntax.Mutability) IOException(java.io.IOException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) BuildFileAST(com.google.devtools.build.lib.syntax.BuildFileAST)

Example 3 with BuildFileNotFoundException

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();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) SkyValue(com.google.devtools.build.skyframe.SkyValue) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) Package(com.google.devtools.build.lib.packages.Package) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with BuildFileNotFoundException

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);
}
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)

Example 5 with BuildFileNotFoundException

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)15 SkyKey (com.google.devtools.build.skyframe.SkyKey)12 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)7 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)7 Label (com.google.devtools.build.lib.cmdline.Label)5 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 Package (com.google.devtools.build.lib.packages.Package)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)5 IOException (java.io.IOException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)3 Path (com.google.devtools.build.lib.vfs.Path)3 Nullable (javax.annotation.Nullable)3 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)2 ErrorDeterminingRepositoryException (com.google.devtools.build.lib.packages.ErrorDeterminingRepositoryException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1