Search in sources :

Example 1 with Directory

use of build.bazel.remote.execution.v2.Directory in project tools_remote by bazelbuild.

the class GrpcRemoteCacheTest method testDownloadOutputDirectoryNested.

@Test
public void testDownloadOutputDirectoryNested() throws Exception {
    GrpcRemoteCache client = newClient();
    Digest fooDigest = DIGEST_UTIL.computeAsUtf8("foo-contents");
    Digest quxDigest = DIGEST_UTIL.computeAsUtf8("qux-contents");
    Directory wobbleDirMessage = Directory.newBuilder().addFiles(FileNode.newBuilder().setName("qux").setDigest(quxDigest)).build();
    Digest wobbleDigest = DIGEST_UTIL.compute(wobbleDirMessage);
    Tree barTreeMessage = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setName("qux").setDigest(quxDigest)).addDirectories(DirectoryNode.newBuilder().setName("wobble").setDigest(wobbleDigest))).addChildren(wobbleDirMessage).build();
    Digest barTreeDigest = DIGEST_UTIL.compute(barTreeMessage);
    OutputDirectory barDirMessage = OutputDirectory.newBuilder().setPath("test/bar").setTreeDigest(barTreeDigest).build();
    Digest barDirDigest = DIGEST_UTIL.compute(barDirMessage);
    serviceRegistry.addService(new FakeImmutableCacheByteStreamImpl(ImmutableMap.of(fooDigest, "foo-contents", barTreeDigest, barTreeMessage.toByteString(), quxDigest, "qux-contents", barDirDigest, barDirMessage.toByteString())));
    client.downloadOutputDirectory(barDirMessage, execRoot.resolve("test/bar"));
    assertThat(Files.exists(execRoot.resolve("test/bar"))).isTrue();
    assertThat(Files.isDirectory(execRoot.resolve("test/bar"))).isTrue();
    assertThat(Files.exists(execRoot.resolve("test/bar/wobble"))).isTrue();
    assertThat(Files.isDirectory(execRoot.resolve("test/bar/wobble"))).isTrue();
    assertThat(Files.exists(execRoot.resolve("test/bar/wobble/qux"))).isTrue();
    assertThat(Files.isRegularFile(execRoot.resolve("test/bar/wobble/qux"))).isTrue();
    assertThat(Files.exists(execRoot.resolve("test/bar/qux"))).isTrue();
    assertThat(Files.isRegularFile(execRoot.resolve("test/bar/qux"))).isTrue();
    if (!System.getProperty("os.name").startsWith("Windows")) {
        assertThat(isExecutable(execRoot.resolve("test/bar/wobble/qux"))).isFalse();
        assertThat(isExecutable(execRoot.resolve("test/bar/qux"))).isFalse();
    }
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Tree(build.bazel.remote.execution.v2.Tree) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Test(org.junit.Test)

Example 2 with Directory

use of build.bazel.remote.execution.v2.Directory in project tools_remote by bazelbuild.

the class RemoteClient method listFileNodes.

// List the files in a directory assuming the directory is at the given path. Returns the number
// of files listed.
private int listFileNodes(Path path, Directory dir, int limit) {
    int numFilesListed = 0;
    for (FileNode child : dir.getFilesList()) {
        if (numFilesListed >= limit) {
            System.out.println(" ... (too many files to list, some omitted)");
            break;
        }
        Path childPath = path.resolve(child.getName());
        printFileNodeDetails(child, childPath);
        numFilesListed++;
    }
    return numFilesListed;
}
Also used : Path(java.nio.file.Path) FileNode(build.bazel.remote.execution.v2.FileNode)

Example 3 with Directory

use of build.bazel.remote.execution.v2.Directory in project tools_remote by bazelbuild.

the class RemoteClient method printActionV1.

// Output for print action command.
private void printActionV1(com.google.devtools.remoteexecution.v1test.Action action, int limit) throws IOException {
    // Note: Command V2 is backward compatible to V1. It adds fields but does not remove them, so we
    // can use it here.
    Command command = getCommand(toV2(action.getCommandDigest()));
    System.out.printf("Command [digest: %s]:\n", digestUtil.toString(toV2(action.getCommandDigest())));
    printCommand(command);
    Tree tree = cache.getTree(toV2(action.getInputRootDigest()));
    System.out.printf("\nInput files [total: %d, root Directory digest: %s]:\n", getNumFiles(tree), digestUtil.toString(toV2(action.getInputRootDigest())));
    listTree(Paths.get(""), tree, limit);
    System.out.println("\nOutput files:");
    printList(action.getOutputFilesList(), limit);
    System.out.println("\nOutput directories:");
    printList(action.getOutputDirectoriesList(), limit);
    System.out.println("\nPlatform:");
    if (action.hasPlatform() && !action.getPlatform().getPropertiesList().isEmpty()) {
        System.out.println(action.getPlatform().toString());
    } else {
        System.out.println("(none)");
    }
}
Also used : GetOutDirCommand(com.google.devtools.build.remote.client.RemoteClientOptions.GetOutDirCommand) Command(build.bazel.remote.execution.v2.Command) LsOutDirCommand(com.google.devtools.build.remote.client.RemoteClientOptions.LsOutDirCommand) GetDirCommand(com.google.devtools.build.remote.client.RemoteClientOptions.GetDirCommand) FailedActionsCommand(com.google.devtools.build.remote.client.RemoteClientOptions.FailedActionsCommand) ShowActionCommand(com.google.devtools.build.remote.client.RemoteClientOptions.ShowActionCommand) CatCommand(com.google.devtools.build.remote.client.RemoteClientOptions.CatCommand) PrintLogCommand(com.google.devtools.build.remote.client.RemoteClientOptions.PrintLogCommand) RunCommand(com.google.devtools.build.remote.client.RemoteClientOptions.RunCommand) LsCommand(com.google.devtools.build.remote.client.RemoteClientOptions.LsCommand) ShowActionResultCommand(com.google.devtools.build.remote.client.RemoteClientOptions.ShowActionResultCommand) Tree(build.bazel.remote.execution.v2.Tree)

Example 4 with Directory

use of build.bazel.remote.execution.v2.Directory in project tools_remote by bazelbuild.

the class RemoteClient method listDirectory.

// Recursively list directory files/subdirectories with digests. Returns the number of files
// listed.
private int listDirectory(Path path, Directory dir, Map<Digest, Directory> childrenMap, int limit) throws IOException {
    // Try to list the files in this directory before listing the directories.
    int numFilesListed = listFileNodes(path, dir, limit);
    if (numFilesListed >= limit) {
        return numFilesListed;
    }
    for (DirectoryNode child : dir.getDirectoriesList()) {
        Path childPath = path.resolve(child.getName());
        printDirectoryNodeDetails(child, childPath);
        Digest childDigest = child.getDigest();
        Directory childDir = childrenMap.get(childDigest);
        numFilesListed += listDirectory(childPath, childDir, childrenMap, limit - numFilesListed);
        if (numFilesListed >= limit) {
            return numFilesListed;
        }
    }
    return numFilesListed;
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory)

Example 5 with Directory

use of build.bazel.remote.execution.v2.Directory in project tools_remote by bazelbuild.

the class AbstractRemoteActionCache method addChildDirectories.

/**
 * Recursively add all child directories of the given directory to the given list of directories.
 */
private void addChildDirectories(Directory dir, List<Directory> directories) throws IOException {
    for (DirectoryNode childNode : dir.getDirectoriesList()) {
        Directory childDir = Directory.parseFrom(downloadBlob(childNode.getDigest()));
        directories.add(childDir);
        addChildDirectories(childDir, directories);
    }
}
Also used : DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory)

Aggregations

Directory (build.bazel.remote.execution.v2.Directory)50 Digest (build.bazel.remote.execution.v2.Digest)46 ByteString (com.google.protobuf.ByteString)28 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)25 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)18 IOException (java.io.IOException)17 Path (java.nio.file.Path)16 Test (org.junit.Test)15 Tree (build.bazel.remote.execution.v2.Tree)12 FileNode (build.bazel.remote.execution.v2.FileNode)11 Command (build.bazel.remote.execution.v2.Command)9 Action (build.bazel.remote.execution.v2.Action)8 ImmutableList (com.google.common.collect.ImmutableList)8 ExecutionException (java.util.concurrent.ExecutionException)6 GetTreeResponse (build.bazel.remote.execution.v2.GetTreeResponse)5 OutputDirectory (build.buildfarm.worker.OutputDirectory)5 PreconditionFailure (com.google.rpc.PreconditionFailure)5 GetTreeRequest (build.bazel.remote.execution.v2.GetTreeRequest)4 EntryLimitException (build.buildfarm.common.EntryLimitException)4 DirectoryEntry (build.buildfarm.common.TreeIterator.DirectoryEntry)4