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