Search in sources :

Example 1 with FileStatus

use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.

the class PathPackageLocator method getPackageBuildFileNullable.

/**
   * Like #getPackageBuildFile(), but returns null instead of throwing.
   *  @param packageIdentifier the name of the package.
   * @param cache a filesystem-level cache of stat() calls.
   */
public Path getPackageBuildFileNullable(PackageIdentifier packageIdentifier, AtomicReference<? extends UnixGlob.FilesystemCalls> cache) {
    Preconditions.checkArgument(!packageIdentifier.getRepository().isDefault());
    if (packageIdentifier.getRepository().isMain()) {
        return getFilePath(packageIdentifier.getPackageFragment().getRelative("BUILD"), cache);
    } else {
        Verify.verify(outputBase != null, String.format("External package '%s' needs to be loaded but this PathPackageLocator instance does not " + "support external packages", packageIdentifier));
        // This works only to some degree, because it relies on the presence of the repository under
        // $OUTPUT_BASE/external, which is created by the appropriate RepositoryDirectoryValue. This
        // is true for the invocation in GlobCache, but not for the locator.getBuildFileForPackage()
        // invocation in Parser#include().
        Path buildFile = outputBase.getRelative(packageIdentifier.getSourceRoot()).getRelative("BUILD");
        FileStatus stat = cache.get().statNullable(buildFile, Symlinks.FOLLOW);
        if (stat != null && stat.isFile()) {
            return buildFile;
        } else {
            return null;
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus)

Example 2 with FileStatus

use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.

the class InMemoryFileSystem method getDirectoryEntries.

@Override
protected Collection<Path> getDirectoryEntries(Path path) throws IOException {
    InMemoryDirectoryInfo dirInfo;
    synchronized (this) {
        dirInfo = getDirectory(path);
        if (!dirInfo.outOfScope()) {
            FileStatus status = stat(path, false);
            Preconditions.checkState(status instanceof InMemoryContentInfo);
            if (!((InMemoryContentInfo) status).isReadable()) {
                throw new IOException("Directory is not readable");
            }
            Collection<String> allChildren = dirInfo.getAllChildren();
            List<Path> result = new ArrayList<>(allChildren.size());
            for (String child : allChildren) {
                if (!(child.equals(".") || child.equals(".."))) {
                    result.add(path.getChild(child));
                }
            }
            return result;
        }
    }
    // If we get here, we're out of scope.
    return getDelegatedPath(dirInfo.getEscapingPath()).getDirectoryEntries();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 3 with FileStatus

use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.

the class SkyframeLabelVisitorTest method testRootCauseOnInconsistentFilesystem.

// Regression test for: "ClassCastException in SkyframeLabelVisitor.sync()"
@Test
public void testRootCauseOnInconsistentFilesystem() throws Exception {
    reporter.removeHandler(failFastHandler);
    scratch.file("foo/BUILD", "sh_library(name = 'foo', deps = ['//bar:baz/fizz'])");
    Path barBuildFile = scratch.file("bar/BUILD", "sh_library(name = 'bar/baz')");
    Path bazDir = barBuildFile.getParentDirectory().getRelative("baz");
    scratch.file("bar/baz/BUILD");
    FileStatus inconsistentParentFileStatus = new FileStatus() {

        @Override
        public boolean isFile() {
            return true;
        }

        @Override
        public boolean isSpecialFile() {
            return false;
        }

        @Override
        public boolean isDirectory() {
            return false;
        }

        @Override
        public boolean isSymbolicLink() {
            return false;
        }

        @Override
        public long getSize() throws IOException {
            return 0;
        }

        @Override
        public long getLastModifiedTime() throws IOException {
            return 0;
        }

        @Override
        public long getLastChangeTime() throws IOException {
            return 0;
        }

        @Override
        public long getNodeId() throws IOException {
            return 0;
        }
    };
    fs.stubStat(bazDir, inconsistentParentFileStatus);
    Set<Label> labels = ImmutableSet.of(Label.parseAbsolute("//foo:foo"));
    getSkyframeExecutor().getPackageManager().newTransitiveLoader().sync(reporter, labels, /*keepGoing=*/
    true, /*parallelThreads=*/
    100);
    assertContainsEvent("Inconsistent filesystem operations");
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) Label(com.google.devtools.build.lib.cmdline.Label) Test(org.junit.Test)

Example 4 with FileStatus

use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.

the class TreeArtifactBuildTest method testDigestInjection.

// This is more a smoke test than anything, because it turns out that:
// 1) there is no easy way to turn fast digests on/off for these test cases, and
// 2) injectDigest() doesn't really complain if you inject bad digests or digests
// for nonexistent files. Instead some weird error shows up down the line.
// In fact, there are no tests for injectDigest anywhere in the codebase.
// So all we're really testing here is that injectDigest() doesn't throw a weird exception.
// TODO(bazel-team): write real tests for injectDigest, here and elsewhere.
@Test
public void testDigestInjection() throws Exception {
    TreeArtifactTestAction action = new TreeArtifactTestAction(outOne) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
            try {
                writeFile(outOneFileOne, "one");
                writeFile(outOneFileTwo, "two");
                MetadataHandler md = actionExecutionContext.getMetadataHandler();
                FileStatus stat = outOneFileOne.getPath().stat(Symlinks.NOFOLLOW);
                md.injectDigest(outOneFileOne, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("one", Charset.forName("UTF-8")).asBytes());
                stat = outOneFileTwo.getPath().stat(Symlinks.NOFOLLOW);
                md.injectDigest(outOneFileTwo, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("two", Charset.forName("UTF-8")).asBytes());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    buildArtifact(action.getSoleOutput());
}
Also used : FileStatus(com.google.devtools.build.lib.vfs.FileStatus) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) InjectedStat(com.google.devtools.build.lib.actions.cache.InjectedStat) MetadataHandler(com.google.devtools.build.lib.actions.cache.MetadataHandler) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with FileStatus

use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.

the class ParallelBuilderTest method testUpdateCacheError.

@Test
public void testUpdateCacheError() throws Exception {
    FileSystem fs = new InMemoryFileSystem() {

        @Override
        public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
            final FileStatus stat = super.stat(path, followSymlinks);
            if (path.toString().endsWith("/out/foo")) {
                return new FileStatus() {

                    private final FileStatus original = stat;

                    @Override
                    public boolean isSymbolicLink() {
                        return original.isSymbolicLink();
                    }

                    @Override
                    public boolean isFile() {
                        return original.isFile();
                    }

                    @Override
                    public boolean isDirectory() {
                        return original.isDirectory();
                    }

                    @Override
                    public boolean isSpecialFile() {
                        return original.isSpecialFile();
                    }

                    @Override
                    public long getSize() throws IOException {
                        return original.getSize();
                    }

                    @Override
                    public long getNodeId() throws IOException {
                        return original.getNodeId();
                    }

                    @Override
                    public long getLastModifiedTime() throws IOException {
                        throw new IOException();
                    }

                    @Override
                    public long getLastChangeTime() throws IOException {
                        return original.getLastChangeTime();
                    }
                };
            }
            return stat;
        }
    };
    Artifact foo = createDerivedArtifact(fs, "foo");
    registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(foo)));
    reporter.removeHandler(failFastHandler);
    try {
        buildArtifacts(foo);
        fail("Expected to fail");
    } catch (BuildFailedException e) {
        assertContainsEvent("not all outputs were created or valid");
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Aggregations

FileStatus (com.google.devtools.build.lib.vfs.FileStatus)18 Path (com.google.devtools.build.lib.vfs.Path)13 Test (org.junit.Test)9 IOException (java.io.IOException)8 Artifact (com.google.devtools.build.lib.actions.Artifact)3 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)3 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)3 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)3 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 MissingInputFileException (com.google.devtools.build.lib.actions.MissingInputFileException)2 SkyValue (com.google.devtools.build.skyframe.SkyValue)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 InjectedStat (com.google.devtools.build.lib.actions.cache.InjectedStat)1 MetadataHandler (com.google.devtools.build.lib.actions.cache.MetadataHandler)1