Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --nozip_undeclared_test_outputs on Windows #16973

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/test/py/bazel/bazel_windows_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,48 @@ def testRunWithScriptPath(self):
self.AssertExitCode(exit_code, 0, stderr)
self.assertIn('Hello from test!', '\n'.join(stdout))

def testZipUndeclaredTestOutputs(self):
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
self.ScratchFile('BUILD', [
'sh_test(',
' name = "foo_test",',
' srcs = ["foo.sh"],',
')',
'',
])
self.ScratchFile('foo.sh', [
'touch "$TEST_UNDECLARED_OUTPUTS_DIR/foo.txt"',
])

exit_code, stdout, stderr = self.RunBazel(['info', 'bazel-testlogs'])
self.AssertExitCode(exit_code, 0, stderr)
bazel_testlogs = stdout[0]

output_file = os.path.join(bazel_testlogs, 'foo_test/test.outputs/foo.txt')
output_zip = os.path.join(bazel_testlogs,
'foo_test/test.outputs/outputs.zip')

# Run the test with undeclared outputs zipping.
exit_code, _, stderr = self.RunBazel([
'test',
'--zip_undeclared_test_outputs',
'//:foo_test',
], )
self.AssertExitCode(exit_code, 0, stderr)
# FIXME: The Windows test runner does not delete the undeclared outputs
# after zipping, which differs from the behavior on other platforms.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this would require implementing recursive directory removal in the Windows runner. The code already exists in src/main/cpp/util/file_windows.cc, let me know if you want me to copy it over.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with fixing this separately.

self.assertTrue(os.path.exists(output_file))
self.assertTrue(os.path.exists(output_zip))

# Run the test without undeclared outputs zipping.
exit_code, _, stderr = self.RunBazel([
'test',
'--nozip_undeclared_test_outputs',
'//:foo_test',
], )
self.AssertExitCode(exit_code, 0, stderr)
self.assertTrue(os.path.exists(output_file))
self.assertFalse(os.path.exists(output_zip))

if __name__ == '__main__':
unittest.main()
6 changes: 4 additions & 2 deletions tools/test/windows/tw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,10 @@ bool StartSubprocess(const Path& path, const std::wstring& args,
}

bool ArchiveUndeclaredOutputs(const UndeclaredOutputs& undecl) {
if (undecl.root.Get().empty()) {
// TEST_UNDECLARED_OUTPUTS_DIR was undefined, there's nothing to archive.
if (undecl.root.Get().empty() || undecl.zip.Get().empty()) {
// TEST_UNDECLARED_OUTPUTS_DIR was undefined, so there's nothing to archive,
// or TEST_UNDECLARED_OUTPUTS_ZIP was undefined as
// --nozip_undeclared_test_outputs was specified.
return true;
}

Expand Down