Skip to content

Commit

Permalink
Remove undeclared test outputs after zipping on Windows
Browse files Browse the repository at this point in the history
Closes #17003.

PiperOrigin-RevId: 495040806
Change-Id: I8cc836d0bc8ad291b39cf4293c4b1f15254e5d79
  • Loading branch information
fmeum authored and hvadehra committed Feb 14, 2023
1 parent 61f2d20 commit 6e31e82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
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

0 comments on commit 6e31e82

Please sign in to comment.