From b86ef4211ef728f7de2cca58d8cc371442b615d9 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 25 Oct 2024 17:35:19 +0200 Subject: [PATCH] Skip over runfiles middleman artifacts without a RunfilesSupplier (#24086) Fixes #24061 --- .../lib/exec/CompactSpawnLogContext.java | 10 +++++++++ src/test/shell/bazel/bazel_execlog_test.sh | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/exec/CompactSpawnLogContext.java b/src/main/java/com/google/devtools/build/lib/exec/CompactSpawnLogContext.java index d9e57dc56ae646..936ce0f11e85b8 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/CompactSpawnLogContext.java +++ b/src/main/java/com/google/devtools/build/lib/exec/CompactSpawnLogContext.java @@ -399,6 +399,16 @@ private int logInputSet( for (ActionInput input : set.getLeaves()) { if (input instanceof Artifact artifact && artifact.isMiddlemanArtifact()) { RunfilesTree runfilesTree = runfilesTrees.get(artifact); + if (runfilesTree == null) { + // This happens for spawns that don't keep their RunfilesSuppliers in sync with + // the middleman artifacts in their inputs. + // The known examples are test spawns that include the lcov merger as a middleman + // artifact, but don't merge in its supplier, as well as split coverage + // postprocessing spawns, which include the test runfiles middleman but not its + // supplier. Since the supplier is what causes the runfiles tree to be materialized, + // we can safely ignore these stray middleman artifacts. + continue; + } builder.addInputIds( logRunfilesTree( runfilesTree, inputMetadataProvider, fileSystem, isTestRunnerSpawn)); diff --git a/src/test/shell/bazel/bazel_execlog_test.sh b/src/test/shell/bazel/bazel_execlog_test.sh index 660fb1639d2293..b2418a5fa2fd72 100755 --- a/src/test/shell/bazel/bazel_execlog_test.sh +++ b/src/test/shell/bazel/bazel_execlog_test.sh @@ -203,6 +203,27 @@ EOF [[ -e ../output.compact ]] || fail "no compact log produced" } +function test_coverage() { + cat > BUILD <<'EOF' +sh_test( + name = "test", + srcs = ["test.sh"], +) +EOF + cat > test.sh <<'EOF' +echo "hello world" +EOF + chmod +x test.sh + + bazel coverage //:test --execution_log_compact_file=output.compact >> $TEST_log 2>&1 || fail "coverage failed" + [[ -e output.compact ]] || fail "no compact log produced" + + rm output.compact + bazel coverage //:test --experimental_split_coverage_postprocessing --experimental_fetch_all_coverage_outputs \ + --execution_log_compact_file=output.compact >> $TEST_log 2>&1 || fail "coverage failed" + [[ -e output.compact ]] || fail "no compact log produced" +} + function test_no_remote_cache() { cat > BUILD <<'EOF' genrule(