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

Remove undeclared test outputs after zipping on Windows #17003

Closed
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
4 changes: 1 addition & 3 deletions src/test/py/bazel/bazel_windows_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,7 @@ def testZipUndeclaredTestOutputs(self):
],
)
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.
self.assertTrue(os.path.exists(output_file))
self.assertFalse(os.path.exists(output_file))
self.assertTrue(os.path.exists(output_zip))

# Run the test without undeclared outputs zipping.
Expand Down
26 changes: 22 additions & 4 deletions tools/test/windows/tw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,19 @@ bool StartSubprocess(const Path& path, const std::wstring& args,
return true;
}

bool RemoveRelativeRecursively(const Path& root,
const std::vector<FileInfo>& files) {
Path path;
for (const auto& file : files) {
if (!(path.Set(file.RelativePath()) && path.Absolutize(root)
&& blaze_util::RemoveRecursively(
blaze_util::WstringToCstring(path.Get())))) {
return false;
}
}
return true;
}

bool ArchiveUndeclaredOutputs(const UndeclaredOutputs& undecl) {
if (undecl.root.Get().empty() || undecl.zip.Get().empty()) {
// TEST_UNDECLARED_OUTPUTS_DIR was undefined, so there's nothing to archive,
Expand All @@ -1306,10 +1319,15 @@ bool ArchiveUndeclaredOutputs(const UndeclaredOutputs& undecl) {
}

std::vector<FileInfo> files;
return GetFileListRelativeTo(undecl.root, &files) &&
(files.empty() ||
(CreateZip(undecl.root, files, undecl.zip) &&
CreateUndeclaredOutputsManifest(files, undecl.manifest)));
if (!GetFileListRelativeTo(undecl.root, &files)) {
return false;
}
if (files.empty()) {
return true;
}
return CreateZip(undecl.root, files, undecl.zip)
&& CreateUndeclaredOutputsManifest(files, undecl.manifest)
&& RemoveRelativeRecursively(undecl.root, files);
}

// Creates the Undeclared Outputs Annotations file.
Expand Down