Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ PathFragment resolveSymbolicLinks(PathFragment path) throws IOException {
/** Removes cached information for a path prefix. */
void clearPrefix(PathFragment pathPrefix) {
Node node = getRootNode(pathPrefix);
NonSymlinkNode parent = null;
String parentSegment = null;
Iterator<String> segments = pathPrefix.segments().iterator();
boolean hasNext = segments.hasNext();

Expand All @@ -184,14 +186,19 @@ void clearPrefix(PathFragment pathPrefix) {

switch (node) {
case SymlinkNode symlinkNode -> {
// Path prefix not in trie.
// Invalidate all intermediate symlinks.
if (parent != null) {
parent.remove(parentSegment);
}
return;
}
case NonSymlinkNode nonSymlinkNode -> {
if (!hasNext) {
// Found the path prefix.
nonSymlinkNode.remove(segment);
} else {
parent = nonSymlinkNode;
parentSegment = segment;
node = nonSymlinkNode.get(segment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ private PathFragment resolveSymbolicLinksForParent(PathFragment path) throws IOE

@Override
public boolean delete(PathFragment path) throws IOException {
PathFragment originalPath = path;
try {
path = resolveSymbolicLinksForParent(path);
} catch (FileNotFoundException ignored) {
Expand All @@ -363,7 +364,7 @@ public boolean delete(PathFragment path) throws IOException {

// No action implementations call renameTo concurrently with other filesystem operations, so
// there's no risk of a race condition below.
pathCanonicalizer.clearPrefix(path);
pathCanonicalizer.clearPrefix(originalPath);

boolean deleted = localFs.getPath(path).delete();
if (isOutput(path)) {
Expand Down
49 changes: 49 additions & 0 deletions src/test/shell/bazel/remote/build_without_the_bytes_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2664,4 +2664,53 @@ EOF
bazel run "${FLAGS[@]}" //:foo >& $TEST_log || fail "Failed to run //:foo"
}

function test_symlink_output_replaced_by_subpackage() {
# Regression test for https://github.com/bazelbuild/bazel/issues/29480.
add_rules_shell "MODULE.bazel"
mkdir -p tools
cat > tools/wrapper_script.sh <<'EOF'
#!/bin/bash
echo hello
EOF
chmod +x tools/wrapper_script.sh

cat > tools/BUILD <<'EOF'
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

sh_binary(
name = "bazel_wrapper",
srcs = ["wrapper_script.sh"],
)
EOF

bazel build \
--remote_cache=grpc://localhost:${worker_port} \
//tools:bazel_wrapper >& $TEST_log \
|| fail "Failed first build of //tools:bazel_wrapper"

[[ -L bazel-bin/tools/bazel_wrapper ]] \
|| fail "Expected bazel-bin/tools/bazel_wrapper to be a symlink"

# Move the sh_binary into a same-named subpackage. The output that was
# previously a symlinked file at .../tools/bazel_wrapper must now become a
# directory at .../tools/bazel_wrapper/ which contains the new outputs.
mkdir -p tools/bazel_wrapper
cat > tools/bazel_wrapper/BUILD <<'EOF'
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

sh_binary(
name = "bazel_wrapper",
srcs = ["//tools:wrapper_script.sh"],
)
EOF
cat > tools/BUILD <<'EOF'
exports_files(["wrapper_script.sh"])
EOF

bazel build \
--remote_cache=grpc://localhost:${worker_port} \
//tools/bazel_wrapper:bazel_wrapper >& $TEST_log \
|| fail "Failed second build after moving sh_binary to a subpackage"
}

run_suite "Build without the Bytes tests"