Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CTest / cmCTestGenericHandler.cxx
blob43631ab51a519b7e1c92bd0624b387a754cb531c
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestGenericHandler.cxx,v $
5 Language: C++
6 Date: $Date: 2009-01-15 18:24:54 $
7 Version: $Revision: 1.21 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "cmCTestGenericHandler.h"
19 #include "cmSystemTools.h"
21 #include "cmCTest.h"
23 //----------------------------------------------------------------------
24 cmCTestGenericHandler::cmCTestGenericHandler()
26 this->HandlerVerbose = false;
27 this->CTest = 0;
28 this->SubmitIndex = 0;
29 this->AppendXML = false;
32 //----------------------------------------------------------------------
33 cmCTestGenericHandler::~cmCTestGenericHandler()
37 //----------------------------------------------------------------------
38 void cmCTestGenericHandler::SetOption(const char* op, const char* value)
40 if ( !op )
42 return;
44 if ( !value )
46 cmCTestGenericHandler::t_StringToString::iterator remit
47 = this->Options.find(op);
48 if ( remit != this->Options.end() )
50 this->Options.erase(remit);
52 return;
55 this->Options[op] = value;
58 //----------------------------------------------------------------------
59 void cmCTestGenericHandler::SetPersistentOption(const char* op,
60 const char* value)
62 this->SetOption(op, value);
63 if ( !op )
65 return;
67 if ( !value )
69 cmCTestGenericHandler::t_StringToString::iterator remit
70 = this->PersistentOptions.find(op);
71 if ( remit != this->PersistentOptions.end() )
73 this->PersistentOptions.erase(remit);
75 return;
78 this->PersistentOptions[op] = value;
81 //----------------------------------------------------------------------
82 void cmCTestGenericHandler::Initialize()
84 this->AppendXML = false;
85 this->Options.clear();
86 t_StringToString::iterator it;
87 for ( it = this->PersistentOptions.begin();
88 it != this->PersistentOptions.end();
89 ++ it )
91 this->Options[it->first.c_str()] = it->second.c_str();
95 //----------------------------------------------------------------------
96 const char* cmCTestGenericHandler::GetOption(const char* op)
98 cmCTestGenericHandler::t_StringToString::iterator remit
99 = this->Options.find(op);
100 if ( remit == this->Options.end() )
102 return 0;
104 return remit->second.c_str();
107 //----------------------------------------------------------------------
108 bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
109 const char* name,
110 cmGeneratedFileStream& xofs)
112 if ( !name )
114 cmCTestLog(this->CTest, ERROR_MESSAGE,
115 "Cannot create resulting XML file without providing the name"
116 << std::endl;);
117 return false;
119 cmOStringStream ostr;
120 ostr << name;
121 if ( this->SubmitIndex > 0 )
123 ostr << "_" << this->SubmitIndex;
125 ostr << ".xml";
126 if(this->CTest->GetCurrentTag().empty())
128 cmCTestLog(this->CTest, ERROR_MESSAGE,
129 "Current Tag empty, this may mean NightlyStartTime / "
130 "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
131 "maybe you forgot to call ctest_start() before calling "
132 "ctest_configure()." << std::endl);
133 cmSystemTools::SetFatalErrorOccured();
134 return false;
136 if( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(),
137 ostr.str().c_str(), xofs, true) )
139 cmCTestLog(this->CTest, ERROR_MESSAGE,
140 "Cannot create resulting XML file: " << ostr.str().c_str()
141 << std::endl);
142 return false;
144 this->CTest->AddSubmitFile(part, ostr.str().c_str());
145 return true;
148 //----------------------------------------------------------------------
149 bool cmCTestGenericHandler::StartLogFile(const char* name,
150 cmGeneratedFileStream& xofs)
152 if ( !name )
154 cmCTestLog(this->CTest, ERROR_MESSAGE,
155 "Cannot create log file without providing the name" << std::endl;);
156 return false;
158 cmOStringStream ostr;
159 ostr << "Last" << name;
160 if ( this->SubmitIndex > 0 )
162 ostr << "_" << this->SubmitIndex;
164 if ( !this->CTest->GetCurrentTag().empty() )
166 ostr << "_" << this->CTest->GetCurrentTag();
168 ostr << ".log";
169 // if this is a parallel subprocess then add the id to the
170 // file so they don't clobber each other
171 if(this->CTest->GetParallelSubprocess())
173 ostr << "." << this->CTest->GetParallelSubprocessId();
175 if( !this->CTest->OpenOutputFile("Temporary", ostr.str().c_str(), xofs) )
177 cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create log file: "
178 << ostr.str().c_str() << std::endl);
179 return false;
181 return true;