diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java index 55fcd83b526be6..1e9c84a0cc01f6 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java @@ -519,11 +519,18 @@ private ModifiedFileSet startBuildAndDetermineModifiedOutputFiles( startLocalOutputBuild(); } } - if (!request.getPackageOptions().checkOutputFiles - // Do not skip invalidation in case the output tree is empty -- this can happen - // after it's cleaned or corrupted. - && !modifiedOutputFiles.treatEverythingAsDeleted()) { - modifiedOutputFiles = ModifiedFileSet.NOTHING_MODIFIED; + if (!request.getPackageOptions().checkOutputFiles) { + // Do not skip invalidation for a run command, thereby making sure outputs are downloaded even + // if they were previously built with --remote_download_minimal. + // See https://github.com/bazelbuild/bazel/issues/20843. + if (request.getCommandName().equals("run")) { + return ModifiedFileSet.EVERYTHING_MODIFIED; + } + // Do not skip invalidation in case the output tree is empty -- this can happen after it's + // cleaned or corrupted. + if (!modifiedOutputFiles.treatEverythingAsDeleted()) { + return ModifiedFileSet.NOTHING_MODIFIED; + } } return modifiedOutputFiles; } diff --git a/src/test/shell/bazel/remote/build_without_the_bytes_test.sh b/src/test/shell/bazel/remote/build_without_the_bytes_test.sh index 29687aa6d3de92..7f2736e505cef8 100755 --- a/src/test/shell/bazel/remote/build_without_the_bytes_test.sh +++ b/src/test/shell/bazel/remote/build_without_the_bytes_test.sh @@ -2210,4 +2210,42 @@ EOF //:foo >& $TEST_log || fail "Failed to build //:foo" } +function test_incremental_run_command_with_no_check_output_files() { + # Regression test for https://github.com/bazelbuild/bazel/issues/20843. + cat > BUILD <<'EOF' +genrule( + name = "gen", + outs = ["out.txt"], + cmd = "touch $@", +) +sh_binary( + name = "foo", + srcs = ["foo.sh"], + data = ["out.txt"], +) +EOF + cat > foo.sh <<'EOF' +#!/bin/bash +if ! [[ -f "$0.runfiles/_main/out.txt" ]]; then + echo "runfile $0.runfiles/_main/out.txt not found" 1>&2 + exit 1 +fi +EOF + chmod +x foo.sh + + CACHEDIR=$(mktemp -d) + FLAGS=(--disk_cache="$CACHEDIR" --remote_download_minimal --noexperimental_check_output_files) + + # Populate the disk cache. + bazel build "${FLAGS[@]}" //:foo >& $TEST_log || fail "Failed to build //:foo" + + # Clean build. No outputs are considered top-level, so nothing is downloaded. + bazel clean "${FLAGS[@]}" + bazel build "${FLAGS[@]}" //:foo >& $TEST_log || fail "Failed to build //:foo" + + # Incremental run. Even though output checking is disabled, the dirtiness + # check must still occur to force them to be downloaded. + bazel run "${FLAGS[@]}" //:foo >& $TEST_log || fail "Failed to run //:foo" +} + run_suite "Build without the Bytes tests"