Skip to content
Snippets Groups Projects
Commit 555b4d25 authored by Googler's avatar Googler Committed by Copybara-Service
Browse files

skyfocus: add test for directories in working set.

Due to how Skyframe and Skyfocus already works, defining directories in
`--experimental_working_set` automatically keeps the `FILE_STATE` SkyKeys of the files in those directories for focusing. Take this rdep graph for example:

`FILE_STATE:[dir] -> FILE:[dir] -> FILE:[dir/BUILD], FILE:[dir/file.txt] -> .. -> BUILD_DRIVER[..]`

If we focus on `dir/`, then Skyfocus will keep these above rdeps, and also the
`FILE_STATE` SkyKeys of the individual files, because `FILE` depends on `FILE_STATE`. This allows the diff invalidators
in `SkyframeExecutor#handleDiff` to correctly invalidate those `FILE_STATE` SkyKeys should
their associated files change.

RELNOTES:
PiperOrigin-RevId: 609694514
Change-Id: I1ea0de36b47e4151045df1d3f7f82807d8ea312f
parent 77c27912
No related merge requests found
......@@ -89,7 +89,7 @@ EOF
expect_log "Focusing on"
}
function test_correctly_rebuilds_after_using_focus() {
function test_correctly_rebuilds_with_working_set_containing_files() {
local -r pkg=${FUNCNAME[0]}
mkdir ${pkg}|| fail "cannot mkdir ${pkg}"
mkdir -p ${pkg}
......@@ -117,6 +117,58 @@ EOF
assert_contains "second change" $out
}
function test_correctly_rebuilds_with_working_set_containing_directories() {
# Setting directories in the working set works, because the rdep edges look like:
#
# FILE_STATE:[dir] -> FILE:[dir] -> FILE:[dir/BUILD], FILE:[dir/file.txt]
#
# ...and the FILE SkyKeys directly depend on their respective FILE_STATE SkyKeys,
# which are the nodes that are invalidated by SkyframeExecutor#handleDiffs
# at the start of every build, and are also kept by Skyfocus.
#
# In other words, defining a working set of directories will automatically
# include all the files under those directories for focusing.
local -r pkg=${FUNCNAME[0]}
mkdir ${pkg}|| fail "cannot mkdir ${pkg}"
mkdir -p ${pkg}
echo "input" > ${pkg}/in.txt
cat > ${pkg}/BUILD <<EOF
genrule(
name = "g",
srcs = ["in.txt"],
outs = ["out.txt"],
cmd = "cp \$< \$@",
)
EOF
out=$(bazel info "${PRODUCT_NAME}-genfiles")/${pkg}/out.txt
# Define working set to be a directory, not file
bazel build //${pkg}:g --experimental_working_set=${pkg}
assert_contains "input" $out
# Incrementally builds ${pkg}/in.txt file
echo "first change" >> ${pkg}/in.txt
bazel build //${pkg}:g
assert_contains "first change" $out
echo "second change" >> ${pkg}/in.txt
bazel build //${pkg}:g
assert_contains "second change" $out
# Incrementally builds new target in ${pkg}/BUILD file
cat >> ${pkg}/BUILD <<EOF
genrule(
name = "another_genrule",
srcs = ["in.txt"],
outs = ["out2.txt"],
cmd = "cp \$< \$@",
)
EOF
bazel build //${pkg}:another_genrule || fail "expected build success"
}
function test_focus_command_prints_info_about_graph() {
local -r pkg=${FUNCNAME[0]}
mkdir ${pkg}|| fail "cannot mkdir ${pkg}"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment