diff options
author | Googler <noreply@google.com> | 2017-09-22 10:38:45 -0400 |
---|---|---|
committer | John Cater <jcater@google.com> | 2017-09-25 09:36:14 -0400 |
commit | da8386aaf23ba4b76de542d7c4d37f057b4b8683 (patch) | |
tree | 70ce4d9e2e9f82a1bdd35acc587c1529036f2cd7 /tools/test | |
parent | 3c23d3eae64b51d8367d5d586f0a41128eb96174 (diff) |
Don't emit an undeclared outputs MANIFEST if there are no files.
Tested manually (with a test that doesn't emit undeclared outputs), and added a test that failed before and passes after the test-setup.sh change.
RELNOTES: N/A
PiperOrigin-RevId: 169687782
Diffstat (limited to 'tools/test')
-rwxr-xr-x | tools/test/test-setup.sh | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index 77b02083ba..5eb43a0bdd 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -225,21 +225,25 @@ write_xml_output_file # Add all of the files from the undeclared outputs directory to the manifest. if [[ -n "$TEST_UNDECLARED_OUTPUTS_DIR" && -n "$TEST_UNDECLARED_OUTPUTS_MANIFEST" ]]; then - # For each file, write a tab-separated line with name (relative to - # TEST_UNDECLARED_OUTPUTS_DIR), size, and mime type to the manifest. e.g. - # foo.txt 9 text/plain - while read -r undeclared_output; do - rel_path="${undeclared_output#$TEST_UNDECLARED_OUTPUTS_DIR/}" - # stat has different flags for different systems. -c is supported by GNU, - # and -f by BSD (and thus OSX). Try both. - file_size="$(stat -f%z "$undeclared_output" 2>/dev/null || stat -c%s "$undeclared_output" 2>/dev/null || echo "Could not stat $undeclared_output")" - file_type="$(file -L -b --mime-type "$undeclared_output")" - - printf "$rel_path\t$file_size\t$file_type\n" - done <<< "$(find -L "$TEST_UNDECLARED_OUTPUTS_DIR" -type f | sort)" \ - > "$TEST_UNDECLARED_OUTPUTS_MANIFEST" - if [[ ! -s "$TEST_UNDECLARED_OUTPUTS_MANIFEST" ]]; then - rm "$TEST_UNDECLARED_OUTPUTS_MANIFEST" + undeclared_outputs="$(find -L "$TEST_UNDECLARED_OUTPUTS_DIR" -type f | sort)" + # Only write the manifest if there are any undeclared outputs. + if [[ ! -z "$undeclared_outputs" ]]; then + # For each file, write a tab-separated line with name (relative to + # TEST_UNDECLARED_OUTPUTS_DIR), size, and mime type to the manifest. e.g. + # foo.txt 9 text/plain + while read -r undeclared_output; do + rel_path="${undeclared_output#$TEST_UNDECLARED_OUTPUTS_DIR/}" + # stat has different flags for different systems. -c is supported by GNU, + # and -f by BSD (and thus OSX). Try both. + file_size="$(stat -f%z "$undeclared_output" 2>/dev/null || stat -c%s "$undeclared_output" 2>/dev/null || echo "Could not stat $undeclared_output")" + file_type="$(file -L -b --mime-type "$undeclared_output")" + + printf "$rel_path\t$file_size\t$file_type\n" + done <<< "$undeclared_outputs" \ + > "$TEST_UNDECLARED_OUTPUTS_MANIFEST" + if [[ ! -s "$TEST_UNDECLARED_OUTPUTS_MANIFEST" ]]; then + rm "$TEST_UNDECLARED_OUTPUTS_MANIFEST" + fi fi fi |