Skip to content

Commit

Permalink
remote: set executable bit of an input file based on its real value.
Browse files Browse the repository at this point in the history
The "always mark" was introduced by 3e3b71a which was a workaround for bazelbuild#4751. However, that issue was then fixed by fc44891. There is no reason to keep the workaround which is causing other issues e.g. bazelbuild#12818.
  • Loading branch information
coeuvre committed Jan 13, 2021
1 parent 28fa193 commit b408a3b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.protobuf.ByteString;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -34,7 +36,7 @@
final class DirectoryTree {

interface Visitor {
void visitDirectory(PathFragment dirname, List<FileNode> files, List<DirectoryNode> dirs);
void visitDirectory(PathFragment dirname, List<FileNode> files, List<DirectoryNode> dirs) throws IOException;
}

abstract static class Node implements Comparable<Node> {
Expand Down Expand Up @@ -165,15 +167,15 @@ boolean isEmpty() {
}

/**
* Traverses the {@link ActionInputsTree} in a depth first search manner. The children are visited
* Traverses the {@link DirectoryTree} in a depth first search manner. The children are visited
* in lexographical order.
*/
void visit(Visitor visitor) {
void visit(Visitor visitor) throws IOException {
Preconditions.checkNotNull(visitor, "visitor");
visit(visitor, PathFragment.EMPTY_FRAGMENT);
}

private void visit(Visitor visitor, PathFragment dirname) {
private void visit(Visitor visitor, PathFragment dirname) throws IOException {
DirectoryNode dir = tree.get(dirname);
if (dir == null) {
return;
Expand All @@ -198,30 +200,34 @@ private void visit(Visitor visitor, PathFragment dirname) {
@Override
public String toString() {
Map<PathFragment, StringBuilder> m = new HashMap<>();
visit(
(dirname, files, dirs) -> {
int depth = dirname.segmentCount() - 1;
StringBuilder sb = new StringBuilder();

if (!dirname.equals(PathFragment.EMPTY_FRAGMENT)) {
sb.append(Strings.repeat(" ", depth));
sb.append(dirname.getBaseName());
sb.append("\n");
}
if (!files.isEmpty()) {
for (FileNode file : files) {
sb.append(Strings.repeat(" ", depth + 1));
sb.append(formatFile(file));
try {
visit(
(dirname, files, dirs) -> {
int depth = dirname.segmentCount() - 1;
StringBuilder sb = new StringBuilder();

if (!dirname.equals(PathFragment.EMPTY_FRAGMENT)) {
sb.append(Strings.repeat(" ", depth));
sb.append(dirname.getBaseName());
sb.append("\n");
}
}
if (!dirs.isEmpty()) {
for (DirectoryNode dir : dirs) {
sb.append(m.remove(dirname.getRelative(dir.getPathSegment())));
if (!files.isEmpty()) {
for (FileNode file : files) {
sb.append(Strings.repeat(" ", depth + 1));
sb.append(formatFile(file));
sb.append("\n");
}
}
if (!dirs.isEmpty()) {
for (DirectoryNode dir : dirs) {
sb.append(m.remove(dirname.getRelative(dir.getPathSegment())));
}
}
}
m.put(dirname, sb);
});
m.put(dirname, sb);
});
} catch (IOException e) {
return e.toString();
}
return m.get(PathFragment.EMPTY_FRAGMENT).toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static MerkleTree build(SortedMap<PathFragment, Path> inputFiles, DigestU
}
}

private static MerkleTree build(DirectoryTree tree, DigestUtil digestUtil) {
private static MerkleTree build(DirectoryTree tree, DigestUtil digestUtil) throws IOException {
Preconditions.checkNotNull(tree);
if (tree.isEmpty()) {
return new MerkleTree(
Expand Down Expand Up @@ -194,12 +194,14 @@ private static MerkleTree build(DirectoryTree tree, DigestUtil digestUtil) {
digestDirectoryMap, digestPathMap, rootDigest, tree.numFiles(), inputBytes.get());
}

private static FileNode buildProto(DirectoryTree.FileNode file) {
return FileNode.newBuilder()
private static FileNode buildProto(DirectoryTree.FileNode file) throws IOException {
FileNode.Builder builder = FileNode.newBuilder()
.setName(file.getPathSegment())
.setDigest(file.getDigest())
.setIsExecutable(true)
.build();
.setDigest(file.getDigest());
if (file.getPath() != null) {
builder.setIsExecutable(file.getPath().isExecutable());
}
return builder.build();
}

private static DirectoryNode buildProto(DirectoryTree.DirectoryNode dir, Digest protoDirDigest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected Path createFile(String path, String content) throws IOException {
return p;
}

static void assertLexicographicalOrder(DirectoryTree tree) {
static void assertLexicographicalOrder(DirectoryTree tree) throws IOException {
// Assert the lexicographical order as defined by the remote execution protocol
tree.visit(
(PathFragment dirname, List<FileNode> files, List<DirectoryNode> dirs) -> {
Expand All @@ -120,15 +120,15 @@ static void assertLexicographicalOrder(DirectoryTree tree) {
});
}

static List<String> directoriesAtDepth(int depth, DirectoryTree tree) {
static List<String> directoriesAtDepth(int depth, DirectoryTree tree) throws IOException {
return asPathSegments(directoryNodesAtDepth(tree, depth));
}

private static List<String> asPathSegments(List<? extends Node> nodes) {
return nodes.stream().map(Node::getPathSegment).collect(Collectors.toList());
}

private static List<DirectoryNode> directoryNodesAtDepth(DirectoryTree tree, int depth) {
private static List<DirectoryNode> directoryNodesAtDepth(DirectoryTree tree, int depth) throws IOException {
List<DirectoryNode> directoryNodes = new ArrayList<>();
tree.visit(
(PathFragment dirname, List<FileNode> files, List<DirectoryNode> dirs) -> {
Expand All @@ -140,7 +140,7 @@ private static List<DirectoryNode> directoryNodesAtDepth(DirectoryTree tree, int
return directoryNodes;
}

static List<FileNode> fileNodesAtDepth(DirectoryTree tree, int depth) {
static List<FileNode> fileNodesAtDepth(DirectoryTree tree, int depth) throws IOException {
List<FileNode> fileNodes = new ArrayList<>();
tree.visit(
(PathFragment dirname, List<FileNode> files, List<DirectoryNode> dirs) -> {
Expand Down

0 comments on commit b408a3b

Please sign in to comment.