Search in sources :

Example 56 with Path

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

the class TreeArtifactMetadataTest method testIOExceptionEndToEnd.

/**
   * Tests that ArtifactFunction rethrows transitive {@link IOException}s as
   * {@link MissingInputFileException}s.
   */
@Test
public void testIOExceptionEndToEnd() throws Throwable {
    final IOException exception = new IOException("boop");
    setupRoot(new CustomInMemoryFs() {

        @Override
        public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
            if (path.getBaseName().equals("one")) {
                throw exception;
            }
            return super.stat(path, followSymlinks);
        }
    });
    try {
        Artifact artifact = createTreeArtifact("outOne");
        TreeArtifactValue value = evaluateTreeArtifact(artifact, ImmutableList.of(new PathFragment("one")));
        fail("MissingInputFileException expected, got " + value);
    } catch (Exception e) {
        assertThat(Throwables.getRootCause(e).getMessage()).contains(exception.getMessage());
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException) SkyFunctionException(com.google.devtools.build.skyframe.SkyFunctionException) IOException(java.io.IOException) Test(org.junit.Test)

Example 57 with Path

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

the class FdoSupport method extractFdoZip.

/**
   * Extracts the FDO zip file and collects data from it that's needed during analysis.
   *
   * <p>When an {@code --fdo_optimize} compile is requested, unpacks the given
   * FDO gcda zip file into a clean working directory under execRoot.
   *
   * @throws FdoException if the FDO ZIP contains a file of unknown type
   */
private static FdoZipContents extractFdoZip(FdoMode fdoMode, LipoMode lipoMode, Path execRoot, Path fdoProfile, PathFragment fdoRootExecPath, String productName) throws IOException, FdoException {
    // The execRoot != null case is only there for testing. We cannot provide a real ZIP file in
    // tests because ZipFileSystem does not work with a ZIP on an in-memory file system.
    // IMPORTANT: Keep in sync with #declareSkyframeDependencies to avoid incrementality issues.
    ImmutableSet<PathFragment> gcdaFiles = ImmutableSet.of();
    ImmutableMultimap<PathFragment, PathFragment> imports = ImmutableMultimap.of();
    if (fdoProfile != null && execRoot != null) {
        Path fdoDirPath = execRoot.getRelative(fdoRootExecPath);
        FileSystemUtils.deleteTreesBelow(fdoDirPath);
        FileSystemUtils.createDirectoryAndParents(fdoDirPath);
        if (fdoMode == FdoMode.AUTO_FDO) {
            if (lipoMode != LipoMode.OFF) {
                imports = readAutoFdoImports(getAutoFdoImportsPath(fdoProfile));
            }
            FileSystemUtils.ensureSymbolicLink(execRoot.getRelative(getAutoProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
        } else if (fdoMode == FdoMode.LLVM_FDO) {
            FileSystemUtils.ensureSymbolicLink(execRoot.getRelative(getLLVMProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
        } else {
            Path zipFilePath = new ZipFileSystem(fdoProfile).getRootDirectory();
            String outputSymlinkName = productName + "-out";
            if (!zipFilePath.getRelative(outputSymlinkName).isDirectory()) {
                throw new ZipException("FDO zip files must be zipped directly above '" + outputSymlinkName + "' for the compiler to find the profile");
            }
            ImmutableSet.Builder<PathFragment> gcdaFilesBuilder = ImmutableSet.builder();
            ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder = ImmutableMultimap.builder();
            extractFdoZipDirectory(zipFilePath, fdoDirPath, gcdaFilesBuilder, importsBuilder);
            gcdaFiles = gcdaFilesBuilder.build();
            imports = importsBuilder.build();
        }
    }
    return new FdoZipContents(gcdaFiles, imports);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ZipException(java.util.zip.ZipException) ZipFileSystem(com.google.devtools.build.lib.vfs.ZipFileSystem)

Example 58 with Path

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

the class BlazeDirectoriesTest method testCreatingDirectories.

@Test
public void testCreatingDirectories() {
    FileSystem fs = scratch.getFileSystem();
    Path installBase = fs.getPath("/my/install");
    Path outputBase = fs.getPath("/my/output");
    Path workspace = fs.getPath("/my/ws");
    BlazeDirectories directories = new BlazeDirectories(installBase, outputBase, workspace, "foo");
    assertEquals(directories.getExecRoot(), outputBase.getChild("ws"));
    workspace = null;
    directories = new BlazeDirectories(installBase, outputBase, workspace, "foo");
    assertEquals(directories.getExecRoot(), outputBase.getChild(BlazeDirectories.DEFAULT_EXEC_ROOT));
    workspace = fs.getPath("/");
    directories = new BlazeDirectories(installBase, outputBase, workspace, "foo");
    assertEquals(directories.getExecRoot(), outputBase.getChild(BlazeDirectories.DEFAULT_EXEC_ROOT));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) Test(org.junit.Test)

Example 59 with Path

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

the class RunfilesSupplierImplTest method setRoot.

@Before
public final void setRoot() throws IOException {
    Scratch scratch = new Scratch();
    rootDir = Root.asDerivedRoot(scratch.dir("/fake/root/dont/matter"));
    Path middlemanExecPath = scratch.dir("/still/fake/root/dont/matter");
    middlemanRoot = Root.middlemanRoot(middlemanExecPath, middlemanExecPath.getChild("subdir"));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Scratch(com.google.devtools.build.lib.testutil.Scratch) Before(org.junit.Before)

Example 60 with Path

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

the class GrpcActionCache method downloadAllResults.

/**
   * Download all results of a remotely executed action locally. TODO(olaola): will need to amend to
   * include the {@link com.google.devtools.build.lib.remote.TreeNodeRepository} for updating.
   */
@Override
public void downloadAllResults(ActionResult result, Path execRoot) throws IOException, CacheNotFoundException {
    // Send all the file requests in a single synchronous batch.
    // TODO(olaola): profile to maybe replace with separate concurrent requests.
    CasDownloadBlobRequest.Builder request = CasDownloadBlobRequest.newBuilder();
    Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap = new HashMap<>();
    for (Output output : result.getOutputList()) {
        Path path = execRoot.getRelative(output.getPath());
        if (output.getContentCase() == ContentCase.FILE_METADATA) {
            FileMetadata fileMetadata = output.getFileMetadata();
            ContentDigest digest = fileMetadata.getDigest();
            if (digest.getSizeBytes() > 0) {
                request.addDigest(digest);
                metadataMap.put(digest, Pair.of(path, fileMetadata));
            } else {
                // Handle empty file locally.
                FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
                FileSystemUtils.writeContent(path, new byte[0]);
            }
        } else {
            downloadTree(output.getDigest(), path);
        }
    }
    Iterator<CasDownloadReply> replies = getBlockingStub().downloadBlob(request.build());
    Set<ContentDigest> results = new HashSet<>();
    while (replies.hasNext()) {
        results.add(createFileFromStream(metadataMap, replies));
    }
    for (ContentDigest digest : metadataMap.keySet()) {
        if (!results.contains(digest)) {
            throw new CacheNotFoundException(digest);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) FileMetadata(com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) CasDownloadReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply) Output(com.google.devtools.build.lib.remote.RemoteProtocol.Output) CasDownloadBlobRequest(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadBlobRequest) Pair(com.google.devtools.build.lib.util.Pair) HashSet(java.util.HashSet)

Aggregations

Path (com.google.devtools.build.lib.vfs.Path)492 Test (org.junit.Test)250 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)105 IOException (java.io.IOException)102 Artifact (com.google.devtools.build.lib.actions.Artifact)37 SkyKey (com.google.devtools.build.skyframe.SkyKey)37 ArrayList (java.util.ArrayList)29 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)17 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)17 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)17 HashMap (java.util.HashMap)17 WindowsPath (com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath)16 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)14 Before (org.junit.Before)14 Package (com.google.devtools.build.lib.packages.Package)13 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)13 Map (java.util.Map)12 Nullable (javax.annotation.Nullable)12 Executor (com.google.devtools.build.lib.actions.Executor)10