Skip to content

Commit

Permalink
Do not zip undeclared test outputs by default.
Browse files Browse the repository at this point in the history
Zipping was originally introduced as a workaround for the lack of support for directory outputs (aka tree artifacts). It creates unnecessary work and introduces a dependency on an external tool.

RELNOTES[INC]: `--zip_undeclared_test_outputs` now defaults to false, causing undeclared test outputs (i.e., files written to `$TEST_UNDECLARED_OUTPUTS_DIR` by a test) to be produced as a directory instead of a zip file.

PiperOrigin-RevId: 671305051
Change-Id: I070c2f8de8e1dcf204c8e0ffa1326afc7ac20219
  • Loading branch information
tjgq authored and copybara-github committed Sep 5, 2024
1 parent 3e464fc commit 489d08b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public static class TestOptions extends FragmentOptions {

@Option(
name = "zip_undeclared_test_outputs",
defaultValue = "true",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.TESTING,
effectTags = {OptionEffectTag.TEST_RUNNER},
help = "If true, undeclared test outputs will be archived in a zip file.")
Expand Down
1 change: 1 addition & 0 deletions src/test/py/bazel/test_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def _AssertUndeclaredOutputs(self, flags):
'//foo:undecl_test',
'-t-',
'--test_output=errors',
'--zip_undeclared_test_outputs',
]
+ flags
)
Expand Down
12 changes: 6 additions & 6 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ function test_undeclared_outputs_are_zipped() {
local -r output_text=$outputs_dir/text.txt
local -r output_html=$outputs_dir/fake.html

bazel test -s //dir:test &> $TEST_log || fail "expected success"
bazel test -s --zip_undeclared_test_outputs //dir:test &> $TEST_log || fail "expected success"

# Newlines are useful around diffs. This helps us get them in bash strings.
N=$'\n'
Expand Down Expand Up @@ -867,7 +867,7 @@ function test_undeclared_outputs_are_not_zipped() {
local -r output_text=$outputs_dir/text.txt
local -r output_html=$outputs_dir/fake.html

bazel test -s --nozip_undeclared_test_outputs //dir:test &> $TEST_log || fail "expected success"
bazel test -s //dir:test &> $TEST_log || fail "expected success"

# Newlines are useful around diffs. This helps us get them in bash strings.
N=$'\n'
Expand Down Expand Up @@ -898,13 +898,13 @@ function test_undeclared_outputs_zipped_then_unzipped() {
local -r output_text=$outputs_dir/text.txt
local -r output_html=$outputs_dir/fake.html

bazel test -s //dir:test &> $TEST_log || fail "expected success"
bazel test -s --zip_undeclared_test_outputs //dir:test &> $TEST_log || fail "expected success"

[ -s $output_text ] && fail "$output_text was present after test"
[ -s $output_html ] && fail "$output_html was present after test"
[ -s $outputs_zip ] || fail "$outputs_zip was not present after test"

bazel test -s --nozip_undeclared_test_outputs //dir:test &> $TEST_log || fail "expected success"
bazel test -s //dir:test &> $TEST_log || fail "expected success"

[ -s $outputs_zip ] && fail "$outputs_zip was present after test"
[ -s $output_text ] || fail "$output_text was not present after test"
Expand All @@ -919,13 +919,13 @@ function test_undeclared_outputs_unzipped_then_zipped() {
local -r output_text=$outputs_dir/text.txt
local -r output_html=$outputs_dir/fake.html

bazel test -s --nozip_undeclared_test_outputs //dir:test &> $TEST_log || fail "expected success"
bazel test -s //dir:test &> $TEST_log || fail "expected success"

[ -s $outputs_zip ] && fail "$outputs_zip was present after test"
[ -s $output_text ] || fail "$output_text was not present after test"
[ -s $output_html ] || fail "$output_html was not present after test"

bazel test -s //dir:test &> $TEST_log || fail "expected success"
bazel test -s --zip_undeclared_test_outputs //dir:test &> $TEST_log || fail "expected success"

[ -s $output_text ] && fail "$output_text was present after test"
[ -s $output_html ] && fail "$output_html was present after test"
Expand Down
35 changes: 31 additions & 4 deletions src/test/shell/bazel/remote/build_without_the_bytes_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ EOF
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_minimal \
--build_event_text_file=$TEST_log \
--zip_undeclared_test_outputs \
//a:foo || fail "Failed to test //a:foo"

expect_log "test.log"
Expand All @@ -849,7 +850,7 @@ EOF
expect_log "test.outputs_manifest__MANIFEST"
}

function test_nozip_undeclared_test_outputs() {
function test_undeclared_test_outputs_unzipped() {
mkdir -p a
cat > a/test.sh << 'EOF'
#!/bin/sh
Expand All @@ -867,11 +868,37 @@ EOF
bazel test \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
--nozip_undeclared_test_outputs \
//a:foo || fail "Failed to test //a:foo"

[[ -e "bazel-testlogs/a/foo/test.outputs/text.txt" ]] || fail "bazel-testlogs/a/foo/test.outputs/text.txt does not exist"
assert_contains "foo" "bazel-testlogs/a/foo/test.outputs/text.txt"
if ! [[ -e "bazel-testlogs/a/foo/test.outputs/text.txt" ]]; then
fail "bazel-testlogs/a/foo/test.outputs/text.txt does not exist"
fi
}

function test_undeclared_test_outputs_zipped() {
mkdir -p a
cat > a/test.sh << 'EOF'
#!/bin/sh
echo foo > "$TEST_UNDECLARED_OUTPUTS_DIR/text.txt"
EOF
chmod +x a/test.sh

cat > a/BUILD <<'EOF'
sh_test(
name = "foo",
srcs = ["test.sh"],
)
EOF

bazel test \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
--zip_undeclared_test_outputs \
//a:foo || fail "Failed to test //a:foo"

if ! [[ -e "bazel-testlogs/a/foo/test.outputs/outputs.zip" ]]; then
fail "bazel-testlogs/a/foo/test.outputs/outputs.zip does not exist"
fi
}

function test_multiple_test_attempts() {
Expand Down

0 comments on commit 489d08b

Please sign in to comment.