Search in sources :

Example 1 with OutputDirectory

use of build.bazel.remote.execution.v2.OutputDirectory 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 OutputDirectory

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

the class RemoteClient method printActionResult.

// Output for print action result command.
private void printActionResult(ActionResult result, int limit) throws IOException {
    System.out.println("Output files:");
    result.getOutputFilesList().stream().limit(limit).forEach(name -> printOutputFile(name));
    if (result.getOutputFilesList().size() > limit) {
        System.out.println(" ... (too many to list, some omitted)");
    } else if (result.getOutputFilesList().isEmpty()) {
        System.out.println("(none)");
    }
    System.out.println("\nOutput directories:");
    if (!result.getOutputDirectoriesList().isEmpty()) {
        for (OutputDirectory dir : result.getOutputDirectoriesList()) {
            listOutputDirectory(dir, limit);
        }
    } else {
        System.out.println("(none)");
    }
    System.out.println(String.format("\nExit code: %d", result.getExitCode()));
    System.out.println("\nStderr buffer:");
    if (result.hasStderrDigest()) {
        byte[] stderr = cache.downloadBlob(result.getStderrDigest());
        System.out.println(new String(stderr, UTF_8));
    } else {
        System.out.println(result.getStderrRaw().toStringUtf8());
    }
    System.out.println("\nStdout buffer:");
    if (result.hasStdoutDigest()) {
        byte[] stdout = cache.downloadBlob(result.getStdoutDigest());
        System.out.println(new String(stdout, UTF_8));
    } else {
        System.out.println(result.getStdoutRaw().toStringUtf8());
    }
}
Also used : OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory)

Example 3 with OutputDirectory

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

the class RemoteClient method doGetOutDir.

private static void doGetOutDir(GetOutDirCommand options, RemoteClient client) throws IOException {
    OutputDirectory dir;
    try {
        dir = OutputDirectory.parseFrom(client.getCache().downloadBlob(options.digest));
    } catch (IOException e) {
        throw new IOException("Failed to obtain OutputDirectory.", e);
    }
    client.getCache().downloadOutputDirectory(dir, options.path);
}
Also used : OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) IOException(java.io.IOException)

Example 4 with OutputDirectory

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

the class RemoteClient method doLsOutDir.

private static void doLsOutDir(LsOutDirCommand options, RemoteClient client) throws IOException {
    OutputDirectory dir;
    try {
        dir = OutputDirectory.parseFrom(client.getCache().downloadBlob(options.digest));
    } catch (IOException e) {
        throw new IOException("Failed to obtain OutputDirectory.", e);
    }
    client.listOutputDirectory(dir, options.limit);
}
Also used : OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) IOException(java.io.IOException)

Example 5 with OutputDirectory

use of build.bazel.remote.execution.v2.OutputDirectory in project bazel-buildfarm by bazelbuild.

the class OperationQueueWorkerContext method createExecDir.

@Override
public Path createExecDir(String operationName, Map<Digest, Directory> directoriesIndex, Action action, Command command) throws IOException, InterruptedException {
    OutputDirectory outputDirectory = OutputDirectory.parse(command.getOutputFilesList(), command.getOutputDirectoriesList(), command.getEnvironmentVariablesList());
    Path execDir = root.resolve(operationName);
    if (Files.exists(execDir)) {
        Directories.remove(execDir);
    }
    Files.createDirectories(execDir);
    ImmutableList.Builder<String> inputFiles = new ImmutableList.Builder<>();
    ImmutableList.Builder<Digest> inputDirectories = new ImmutableList.Builder<>();
    boolean fetched = false;
    try {
        fetchInputs(execDir, action.getInputRootDigest(), directoriesIndex, outputDirectory, inputFiles, inputDirectories);
        fetched = true;
    } finally {
        if (!fetched) {
            fileCache.decrementReferences(inputFiles.build(), inputDirectories.build());
        }
    }
    rootInputFiles.put(execDir, inputFiles.build());
    rootInputDirectories.put(execDir, inputDirectories.build());
    boolean stamped = false;
    try {
        outputDirectory.stamp(execDir);
        stamped = true;
    } finally {
        if (!stamped) {
            destroyExecDir(execDir);
        }
    }
    if (owner != null) {
        Directories.setAllOwner(execDir, owner);
    }
    return execDir;
}
Also used : Path(java.nio.file.Path) OutputDirectory(build.buildfarm.worker.OutputDirectory) Digest(build.bazel.remote.execution.v2.Digest) ImmutableList(com.google.common.collect.ImmutableList) ByteString(com.google.protobuf.ByteString)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)10 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)10 IOException (java.io.IOException)7 Directory (build.bazel.remote.execution.v2.Directory)6 Tree (build.bazel.remote.execution.v2.Tree)5 ByteString (com.google.protobuf.ByteString)5 OutputDirectory (build.buildfarm.worker.OutputDirectory)4 ImmutableList (com.google.common.collect.ImmutableList)4 Path (java.nio.file.Path)4 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.Test)3 Action (build.bazel.remote.execution.v2.Action)2 Command (build.bazel.remote.execution.v2.Command)2 FileNode (build.bazel.remote.execution.v2.FileNode)2 OutputFile (build.bazel.remote.execution.v2.OutputFile)2 SymlinkNode (build.bazel.remote.execution.v2.SymlinkNode)2 ContentAddressableStorage (build.buildfarm.cas.ContentAddressableStorage)2 DigestUtil (build.buildfarm.common.DigestUtil)2