Skip to content

Commit

Permalink
[7.0.1] Force output checking for incremental run commands without th…
Browse files Browse the repository at this point in the history
…e bytes. (#20881)

When building without the bytes, outputs are only materialized when
either (1) an action prefetches them, or (2) they've been explicitly
requested. When both --remote_download_minimal and
--noexperimental_check_output_files are set, this presents a problem for
a build command followed by a run command for the same target: the build
command won't download the outputs and the run command won't check for
their presence, proceeding without them. A non-incremental run command
works, because the outputs are considered top-level even in minimal
mode.

This is only a problem for a run command because it exists outside of
action execution, and doesn't get a chance to prefetch inputs; it would
have been better to implement the run command by injecting a specially
crafted action into the build graph, but that will have to wait for
another day. The present fix might theoretically slow things down if
output checking is truly unnecessary, but I doubt that would cause a
significant regression in practice.

Fixes #20843.

Closes #20853.

Commit
2f899ef

PiperOrigin-RevId: 597909909
Change-Id: I66aedef4994fbda41fe5378c80940fa8ba637bfd

Co-authored-by: Tiago Quelhas <[email protected]>
  • Loading branch information
bazel-io and tjgq authored Jan 15, 2024
1 parent 476e183 commit f4da34d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,15 @@ 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 output invalidation in the following cases:
// 1. If the output tree is empty: this can happen after it's cleaned or corrupted.
// 2. For a run command: so that outputs are downloaded even if they were previously built
// with --remote_download_minimal. See https://github.com/bazelbuild/bazel/issues/20843.
if (!modifiedOutputFiles.treatEverythingAsDeleted()
&& !request.getCommandName().equals("run")) {
return ModifiedFileSet.NOTHING_MODIFIED;
}
}
return modifiedOutputFiles;
}
Expand Down
38 changes: 38 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 @@ -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, invalidation must
# 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"

0 comments on commit f4da34d

Please sign in to comment.