@@ -189,6 +189,9 @@ struct Duration {
189
189
bool FromString (const wchar_t * str);
190
190
};
191
191
192
+ enum class MainType { kTestWrapperMain , kXmlWriterMain };
193
+ enum class DeleteAfterwards { kEnabled , kDisabled };
194
+
192
195
void WriteStdout (const std::string& s) {
193
196
DWORD written;
194
197
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), s.c_str (), s.size (), &written,
@@ -1603,9 +1606,16 @@ std::string CreateErrorTag(int exit_code) {
1603
1606
}
1604
1607
}
1605
1608
1606
- bool ShouldCreateXml (const Path& xml_log, bool * result) {
1609
+ bool ShouldCreateXml (const Path& xml_log, const MainType main_type,
1610
+ bool * result) {
1607
1611
*result = true ;
1608
1612
1613
+ // If running from the xml generator binary, we should always create the xml
1614
+ // file.
1615
+ if (main_type == MainType::kXmlWriterMain ) {
1616
+ return true ;
1617
+ }
1618
+
1609
1619
DWORD attr = GetFileAttributesW (AddUncPrefixMaybe (xml_log).c_str ());
1610
1620
if (attr != INVALID_FILE_ATTRIBUTES) {
1611
1621
// The XML file already exists, maybe the test framework wrote it.
@@ -1630,9 +1640,10 @@ bool ShouldCreateXml(const Path& xml_log, bool* result) {
1630
1640
1631
1641
bool CreateXmlLog (const Path& output, const Path& test_outerr,
1632
1642
const Duration duration, const int exit_code,
1633
- const bool delete_afterwards) {
1643
+ const DeleteAfterwards delete_afterwards,
1644
+ const MainType main_type) {
1634
1645
bool should_create_xml;
1635
- if (!ShouldCreateXml (output, &should_create_xml)) {
1646
+ if (!ShouldCreateXml (output, main_type, &should_create_xml)) {
1636
1647
LogErrorWithArg (__LINE__, " Failed to decide if XML log is needed" ,
1637
1648
output.Get ());
1638
1649
return false ;
@@ -1645,7 +1656,7 @@ bool CreateXmlLog(const Path& output, const Path& test_outerr,
1645
1656
// Delete the test's outerr file after we have the XML file.
1646
1657
// We don't care if this succeeds or not, because the outerr file is not a
1647
1658
// declared output.
1648
- if (delete_afterwards) {
1659
+ if (delete_afterwards == DeleteAfterwards:: kEnabled ) {
1649
1660
DeleteFileW (test_outerr.Get ().c_str ());
1650
1661
}
1651
1662
});
@@ -1904,7 +1915,8 @@ int TestWrapperMain(int argc, wchar_t** argv) {
1904
1915
1905
1916
Duration test_duration;
1906
1917
int result = RunSubprocess (test_path, args, test_outerr, &test_duration);
1907
- if (!CreateXmlLog (xml_log, test_outerr, test_duration, result, true ) ||
1918
+ if (!CreateXmlLog (xml_log, test_outerr, test_duration, result,
1919
+ DeleteAfterwards::kEnabled , MainType::kTestWrapperMain ) ||
1908
1920
!ArchiveUndeclaredOutputs (undecl) ||
1909
1921
!CreateUndeclaredOutputsAnnotations (undecl.annotations_dir ,
1910
1922
undecl.annotations )) {
@@ -1921,7 +1933,8 @@ int XmlWriterMain(int argc, wchar_t** argv) {
1921
1933
if (!GetCwd (&cwd) ||
1922
1934
!ParseXmlWriterArgs (argc, argv, cwd, &test_outerr, &test_xml_log,
1923
1935
&duration, &exit_code) ||
1924
- !CreateXmlLog (test_xml_log, test_outerr, duration, exit_code, false )) {
1936
+ !CreateXmlLog (test_xml_log, test_outerr, duration, exit_code,
1937
+ DeleteAfterwards::kDisabled , MainType::kXmlWriterMain )) {
1925
1938
return 1 ;
1926
1939
}
1927
1940
0 commit comments