diff --git a/Source/ctest.cxx b/Source/ctest.cxx index a21aef932..9442c7546 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -464,37 +464,23 @@ int ctest::BuildDirectory() // Add parsing of output for errors and warnings. cmCTestBuildErrorWarning cerw; - char* coutput = new char[ output.size() + 1]; - memcpy(coutput, output.c_str(), output.size()); int cc; + + std::ofstream ofs; + if ( this->OpenFile("Temporary", "LastBuild.log", ofs) ) + { + ofs << output; + ofs.close(); + } - std::vector lines; + std::vector lines; + cmSystemTools::Split(output.c_str(), lines); // Lines are marked: // 0 - nothing // 1 - error // > 1 - warning - std::vector markedLines; - cmIStringStream istr(coutput); - while(istr) - { - char buffer[1024]; - std::string line; - while ( istr ) - { - buffer[0] = 0; - istr.getline(buffer, 1023); - buffer[1023] = 0; - line += buffer; - if ( strlen(buffer) < 1023 ) - { - break; - } - } - lines.push_back(line); - markedLines.push_back(0); - //std::cout << "Line [" << line << "]" << std::endl; - } + std::vector markedLines(lines.size(), 0); // Errors for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ ) @@ -595,7 +581,23 @@ int ctest::BuildDirectory() errorsWarnings.push_back(errorwarning); } } + + if( !this->OpenFile("", "Build.xml", ofs) ) + { + return 1; + } + this->GenerateDartBuildOutput(ofs, errorsWarnings); + return 0; +} + +bool ctest::OpenFile(const std::string& path, + const std::string& name, std::ofstream& stream) +{ std::string testingDir = m_ToplevelPath + "/Testing/CDart"; + if ( path.size() > 0 ) + { + testingDir += "/" + path; + } if ( cmSystemTools::FileExists(testingDir.c_str()) ) { if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) ) @@ -603,7 +605,7 @@ int ctest::BuildDirectory() std::cerr << "File " << testingDir << " is in the place of the testing directory" << std::endl; - return 1; + return false; } } else @@ -612,21 +614,19 @@ int ctest::BuildDirectory() { std::cerr << "Cannot create directory " << testingDir << std::endl; - return 1; + return false; } } - std::string buildxml = testingDir + "/Build.xml"; - std::ofstream ofs(buildxml.c_str()); - if( !ofs ) + std::string filename = testingDir + "/" + name; + stream.open(filename.c_str()); + if( !stream ) { std::cerr << "Cannot create build XML file" << std::endl; - return 1; + return false; } - this->GenerateDartBuildOutput(ofs, errorsWarnings); - return 0; + return true; } - void ctest::GenerateDartBuildOutput(std::ostream& os, std::vector ew) { @@ -635,39 +635,40 @@ void ctest::GenerateDartBuildOutput(std::ostream& os, << "\" BuildStamp=\"" << m_CurrentTag << "-Experimental\" Name=\"" << m_DartConfiguration["Site"] << "\">\n" << "\n" - << " " << m_StartBuild << "\n" - << " " << m_DartConfiguration["MakeCommand"] + << "\t" << m_StartBuild << "\n" + << "" << m_DartConfiguration["MakeCommand"] << "" << std::endl; std::vector::iterator it; for ( it = ew.begin(); it != ew.end(); it++ ) { cmCTestBuildErrorWarning *cm = &(*it); - os << " <" << (cm->m_Error ? "Error" : "Warning") << ">\n" - << " " << cm->m_LogLine << "\n" - << " " << cm->m_Text << "" << std::endl; + os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n" + << "\t\t" << cm->m_LogLine << "\n" + << "\t\t" << cm->m_Text << "\n" << std::endl; if ( cm->m_SourceFile.size() > 0 ) { - os << " " << cm->m_SourceFile << "" + os << "\t\t" << cm->m_SourceFile << "" << std::endl; } if ( cm->m_SourceFileTail.size() > 0 ) { - os << " " << cm->m_SourceFileTail + os << "\t\t" << cm->m_SourceFileTail << "" << std::endl; } if ( cm->m_LineNumber >= 0 ) { - os << " " << cm->m_LineNumber + os << "\t\t" << cm->m_LineNumber << "" << std::endl; } - os << " " << cm->m_PreContext << "\n" - << " " << cm->m_PostContext << "\n" - << " m_Error ? "Error" : "Warning") << ">" + os << "\t\t" << cm->m_PreContext << "\n\n" + << "\t\t" << cm->m_PostContext << "\n\n" + << "\t\t0\n" + << "m_Error ? "Error" : "Warning") << ">\n\n" << std::endl; } - os << " \n \n" - << " " << m_EndBuild << "\n" + os << "\t\n\t\n" + << "\t" << m_EndBuild << "\n" << "\n" << "" << std::endl; } @@ -966,7 +967,7 @@ void ctest::GenerateDartOutput(std::ostream& os) << "name=\"Completion Status\">" << result->m_CompletionStatus << "\n" << " \n" - << " " << result->m_Output << "\n" + << " " << result->m_Output << "\n" << " \n" << " \n" << " " << std::endl; diff --git a/Source/ctest.h b/Source/ctest.h index 60aab8e64..426f3b96e 100644 --- a/Source/ctest.h +++ b/Source/ctest.h @@ -148,6 +148,8 @@ private: void GenerateDartOutput(std::ostream& os); void GenerateDartBuildOutput(std::ostream& os, std::vector); - + + bool OpenFile(const std::string& path, + const std::string& name, std::ofstream& stream); };