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