From 4efeac9cb5f85325ed73f64e133a078c483cac01 Mon Sep 17 00:00:00 2001 From: lberki Date: Fri, 19 Feb 2021 02:33:02 -0800 Subject: [PATCH] Make the Merkle tree computation work in the wake of https://github.com/bazelbuild/bazel/commit/7149f578006a4ad0d51df69830a6986749b34df5 . Fixes a bunch of downstream breakages: https://github.com/bazelbuild/continuous-integration/issues/1093 https://github.com/bazelbuild/continuous-integration/issues/1094 https://github.com/bazelbuild/rules_nodejs/issues/2464 https://github.com/bazelbuild/rules_python/issues/419 Turns out, the assertion that "Merkle tree computation uses `ActionInput.getExecPath()`" was only mostly correct: there was a place where the key of the input map was used instead. I'm somewhat surprised that this did not show up in our test battery, although, admittedly, "unsound directory as an input file in an external repository" doesn't sound like the most common use case. RELNOTES: None. PiperOrigin-RevId: 358366246 --- .../merkletree/DirectoryTreeBuilder.java | 2 +- src/test/shell/bazel/disk_cache_test.sh | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTreeBuilder.java b/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTreeBuilder.java index 80a34af8ab15db..4503f741dbbfae 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTreeBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTreeBuilder.java @@ -154,7 +154,7 @@ private static int buildFromActionInputs( case DIRECTORY: SortedMap directoryInputs = - explodeDirectory(path, execRoot); + explodeDirectory(input.getExecPath(), execRoot); return buildFromActionInputs( directoryInputs, metadataProvider, execRoot, digestUtil, tree); diff --git a/src/test/shell/bazel/disk_cache_test.sh b/src/test/shell/bazel/disk_cache_test.sh index 303134057ad74c..05c6546ebe5f73 100755 --- a/src/test/shell/bazel/disk_cache_test.sh +++ b/src/test/shell/bazel/disk_cache_test.sh @@ -66,4 +66,29 @@ EOF assert_equals "0" $(cat "${execution_file}") } +function test_input_directories_in_external_repo_with_sibling_repository_layout() { + create_new_workspace + l=$TEST_TMPDIR/l + mkdir -p "$l/dir" + touch "$l/WORKSPACE" + touch "$l/dir/f" + cat > "$l/BUILD" <<'EOF' +exports_files(["dir"]) +EOF + + cat >> WORKSPACE < BUILD <<'EOF' +genrule(name="g", srcs=["@l//:dir"], outs=["go"], cmd="find $< > $@") +EOF + + bazel build \ + --experimental_sibling_repository_layout \ + --disk_cache="$TEST_TMPDIR/cache" \ + //:g || fail "build failed" + +} + run_suite "local action cache test"