1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestBuildHandler.cxx,v $
6 <<<<<<< cmCTestBuildHandler.cxx
7 Date: $Date: 2008/01/30 16:17:36 $
8 Version: $Revision: 1.61 $
10 Date: $Date: 2008-03-19 15:18:40 $
11 Version: $Revision: 1.62 $
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
23 #include "cmCTestBuildHandler.h"
27 #include "cmMakefile.h"
28 #include "cmLocalGenerator.h"
29 #include "cmGlobalGenerator.h"
30 #include "cmGeneratedFileStream.h"
32 //#include <cmsys/RegularExpression.hxx>
33 #include <cmsys/Process.h>
45 #if defined(__BORLANDC__)
46 # pragma warn -8060 /* possibly incorrect assignment */
49 static const char* cmCTestErrorMatches
[] = {
51 "^[Ss]egmentation [Vv]iolation",
52 "^[Ss]egmentation [Ff]ault",
53 "([^ :]+):([0-9]+): ([^ \\t])",
54 "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
60 "^\"[^\"]+\", line [0-9]+: [^Ww]",
61 "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
62 "^ld([^:])*:([ \\t])*ERROR([^:])*:",
63 "^ild:([ \\t])*\\(undefined symbol\\)",
64 "([^ :]+) : (error|fatal error|catastrophic error)",
65 "([^:]+): (Error:|error|undefined reference|multiply defined)",
66 "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
67 "^fatal error C[0-9]+:",
69 "^collect2: ld returned 1 exit status",
70 "ld terminated with signal",
71 "Unsatisfied symbols:",
74 "^Undefined[ \\t]+first referenced",
78 ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
79 ": \\*\\*\\* No targets specified and no makefile found",
80 ": Invalid loader fixup for symbol",
81 ": Invalid fixups exist",
82 ": Can't find library for",
83 ": internal link edit command failed",
84 ": Unrecognized option \\`.*\\'",
85 "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^WI]\\)",
86 "ld: 0706-006 Cannot find or open library file: -l ",
87 "ild: \\(argument error\\) can't find library argument ::",
88 "^could not be found and will not be loaded.",
89 "s:616 string too big",
90 "make: Fatal error: ",
91 "ld: 0711-993 Error occurred while writing to the output file:",
94 "make: \\*\\*\\*.*Error",
95 "make\\[.*\\]: \\*\\*\\*.*Error",
96 "\\*\\*\\* Error code",
98 "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
99 ": No such file or directory",
100 ": Invalid argument",
101 "^The project cannot be built\\.",
105 static const char* cmCTestErrorExceptions
[] = {
106 "instantiated from ",
114 "([^ :]+):([0-9]+): Warning",
115 "------ Build started: .* ------",
119 static const char* cmCTestWarningMatches
[] = {
120 "([^ :]+):([0-9]+): warning:",
121 "([^ :]+):([0-9]+): note:",
122 "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
123 "^ld([^:])*:([ \\t])*WARNING([^:])*:",
124 "([^:]+): warning ([0-9]+):",
125 "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
126 "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
127 "^(Warning|Warnung) ([0-9]+):",
128 "^(Warning|Warnung) ",
130 "([^ :]+) : warning",
132 "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([WI]\\)",
134 ".*file: .* has no symbols",
135 "([^ :]+):([0-9]+): (Warning|Warnung)",
136 "\\([0-9]*\\): remark #[0-9]*",
137 "\".*\", line [0-9]+: remark\\([0-9]*\\):",
138 "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
142 static const char* cmCTestWarningExceptions
[] = {
143 "/usr/.*/X11/Xlib\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
144 "/usr/.*/X11/Xutil\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
145 "/usr/.*/X11/XResource\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
150 "warning: Clock skew detected. Your build may be incomplete.",
151 "/usr/openwin/include/GL/[^:]+:",
155 "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
156 "ld32: WARNING 85: definition of dataKey in",
157 "cc: warning 422: Unknown option \"\\+b",
162 struct cmCTestBuildCompileErrorWarningRex
164 const char* RegularExpressionString
;
169 static cmCTestBuildCompileErrorWarningRex
170 cmCTestWarningErrorFileLine
[] = {
171 { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
172 { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
173 { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
174 { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
175 { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
176 { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
180 //----------------------------------------------------------------------
181 cmCTestBuildHandler::cmCTestBuildHandler()
183 this->MaxPreContext
= 6;
184 this->MaxPostContext
= 6;
186 this->MaxErrors
= 50;
187 this->MaxWarnings
= 50;
189 this->LastErrorOrWarning
= this->ErrorsAndWarnings
.end();
193 //----------------------------------------------------------------------
194 void cmCTestBuildHandler::Initialize()
196 this->Superclass::Initialize();
197 this->StartBuild
= "";
199 this->CustomErrorMatches
.clear();
200 this->CustomErrorExceptions
.clear();
201 this->CustomWarningMatches
.clear();
202 this->CustomWarningExceptions
.clear();
203 this->ErrorWarningFileLineRegex
.clear();
205 this->ErrorMatchRegex
.clear();
206 this->ErrorExceptionRegex
.clear();
207 this->WarningMatchRegex
.clear();
208 this->WarningExceptionRegex
.clear();
209 this->BuildProcessingQueue
.clear();
210 this->BuildProcessingErrorQueue
.clear();
211 this->BuildOutputLogSize
= 0;
212 this->CurrentProcessingLine
.clear();
214 this->SimplifySourceDir
= "";
215 this->SimplifyBuildDir
= "";
216 this->OutputLineCounter
= 0;
217 this->ErrorsAndWarnings
.clear();
218 this->LastErrorOrWarning
= this->ErrorsAndWarnings
.end();
219 this->PostContextCount
= 0;
220 this->MaxPreContext
= 6;
221 this->MaxPostContext
= 6;
222 this->PreContext
.clear();
224 this->TotalErrors
= 0;
225 this->TotalWarnings
= 0;
226 this->LastTickChar
= 0;
228 this->ErrorQuotaReached
= false;
229 this->WarningQuotaReached
= false;
231 this->MaxErrors
= 50;
232 this->MaxWarnings
= 50;
235 //----------------------------------------------------------------------
236 void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile
*mf
)
238 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_ERROR_MATCH",
239 this->CustomErrorMatches
);
240 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_ERROR_EXCEPTION",
241 this->CustomErrorExceptions
);
242 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_WARNING_MATCH",
243 this->CustomWarningMatches
);
244 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_WARNING_EXCEPTION",
245 this->CustomWarningExceptions
);
246 this->CTest
->PopulateCustomInteger(mf
,
247 "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
249 this->CTest
->PopulateCustomInteger(mf
,
250 "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
254 //----------------------------------------------------------------------
255 //clearly it would be nice if this were broken up into a few smaller
256 //functions and commented...
257 int cmCTestBuildHandler::ProcessHandler()
259 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, "Build project" << std::endl
);
261 // do we have time for this
262 if (this->CTest
->GetRemainingTimeAllowed() < 120)
269 cmCTestWarningErrorFileLine
[entry
].RegularExpressionString
;
272 cmCTestBuildHandler::cmCTestCompileErrorWarningRex r
;
273 if ( r
.RegularExpression
.compile(
274 cmCTestWarningErrorFileLine
[entry
].RegularExpressionString
) )
276 r
.FileIndex
= cmCTestWarningErrorFileLine
[entry
].FileIndex
;
277 r
.LineIndex
= cmCTestWarningErrorFileLine
[entry
].LineIndex
;
278 this->ErrorWarningFileLineRegex
.push_back(r
);
282 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
283 "Problem Compiling regular expression: "
284 << cmCTestWarningErrorFileLine
[entry
].RegularExpressionString
289 // Determine build command and build directory
290 const std::string
&makeCommand
291 = this->CTest
->GetCTestConfiguration("MakeCommand");
292 cmCTestLog(this->CTest
,
293 HANDLER_VERBOSE_OUTPUT
, "MakeCommand:" << makeCommand
<<
295 if ( makeCommand
.size() == 0 )
297 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
298 "Cannot find MakeCommand key in the DartConfiguration.tcl"
302 const std::string
&buildDirectory
303 = this->CTest
->GetCTestConfiguration("BuildDirectory");
304 if ( buildDirectory
.size() == 0 )
306 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
307 "Cannot find BuildDirectory key in the DartConfiguration.tcl"
312 // Create a last build log
313 cmGeneratedFileStream ofs
;
314 double elapsed_time_start
= cmSystemTools::GetTime();
315 if ( !this->StartLogFile("Build", ofs
) )
317 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "Cannot create build log file"
321 // Create lists of regular expression strings for errors, error exceptions,
322 // warnings and warning exceptions.
323 std::vector
<cmStdString
>::size_type cc
;
324 for ( cc
= 0; cmCTestErrorMatches
[cc
]; cc
++ )
326 this->CustomErrorMatches
.push_back(cmCTestErrorMatches
[cc
]);
328 for ( cc
= 0; cmCTestErrorExceptions
[cc
]; cc
++ )
330 this->CustomErrorExceptions
.push_back(cmCTestErrorExceptions
[cc
]);
332 for ( cc
= 0; cmCTestWarningMatches
[cc
]; cc
++ )
334 this->CustomWarningMatches
.push_back(cmCTestWarningMatches
[cc
]);
337 for ( cc
= 0; cmCTestWarningExceptions
[cc
]; cc
++ )
339 this->CustomWarningExceptions
.push_back(cmCTestWarningExceptions
[cc
]);
342 // Pre-compile regular expressions objects for all regular expressions
343 std::vector
<cmStdString
>::iterator it
;
345 #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
347 cmCTestLog(this->CTest, DEBUG, this << "Add " #regexes \
349 for ( it = strings.begin(); it != strings.end(); ++it ) \
351 cmCTestLog(this->CTest, DEBUG, "Add " #strings ": " \
352 << it->c_str() << std::endl); \
353 regexes.push_back(it->c_str()); \
355 cmCTestBuildHandlerPopulateRegexVector(
356 this->CustomErrorMatches
, this->ErrorMatchRegex
);
357 cmCTestBuildHandlerPopulateRegexVector(
358 this->CustomErrorExceptions
, this->ErrorExceptionRegex
);
359 cmCTestBuildHandlerPopulateRegexVector(
360 this->CustomWarningMatches
, this->WarningMatchRegex
);
361 cmCTestBuildHandlerPopulateRegexVector(
362 this->CustomWarningExceptions
, this->WarningExceptionRegex
);
365 // Determine source and binary tree substitutions to simplify the output.
366 this->SimplifySourceDir
= "";
367 this->SimplifyBuildDir
= "";
368 if ( this->CTest
->GetCTestConfiguration("SourceDirectory").size() > 20 )
371 = this->CTest
->GetCTestConfiguration("SourceDirectory") + "/";
372 std::string srcdirrep
;
373 for ( cc
= srcdir
.size()-2; cc
> 0; cc
-- )
375 if ( srcdir
[cc
] == '/' )
377 srcdirrep
= srcdir
.c_str() + cc
;
378 srcdirrep
= "/..." + srcdirrep
;
379 srcdir
= srcdir
.substr(0, cc
+1);
383 this->SimplifySourceDir
= srcdir
;
385 if ( this->CTest
->GetCTestConfiguration("BuildDirectory").size() > 20 )
388 = this->CTest
->GetCTestConfiguration("BuildDirectory") + "/";
389 std::string bindirrep
;
390 for ( cc
= bindir
.size()-2; cc
> 0; cc
-- )
392 if ( bindir
[cc
] == '/' )
394 bindirrep
= bindir
.c_str() + cc
;
395 bindirrep
= "/..." + bindirrep
;
396 bindir
= bindir
.substr(0, cc
+1);
400 this->SimplifyBuildDir
= bindir
;
404 // Ok, let's do the build
406 // Remember start build time
407 this->StartBuild
= this->CTest
->CurrentTime();
408 this->StartBuildTime
= cmSystemTools::GetTime();
410 int res
= cmsysProcess_State_Exited
;
411 if ( !this->CTest
->GetShowOnly() )
413 res
= this->RunMakeCommand(makeCommand
.c_str(), &retVal
,
414 buildDirectory
.c_str(), 0, ofs
);
418 cmCTestLog(this->CTest
, DEBUG
, "Build with command: " << makeCommand
422 // Remember end build time and calculate elapsed time
423 this->EndBuild
= this->CTest
->CurrentTime();
424 this->EndBuildTime
= cmSystemTools::GetTime();
425 double elapsed_build_time
= cmSystemTools::GetTime() - elapsed_time_start
;
426 if (res
!= cmsysProcess_State_Exited
|| retVal
)
428 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "Error(s) when building project"
432 // Cleanups strings in the errors and warnings list.
433 t_ErrorsAndWarningsVector::iterator evit
;
434 if ( !this->SimplifySourceDir
.empty() )
436 for ( evit
= this->ErrorsAndWarnings
.begin();
437 evit
!= this->ErrorsAndWarnings
.end();
440 cmSystemTools::ReplaceString(
441 evit
->Text
, this->SimplifySourceDir
.c_str(), "/.../");
442 cmSystemTools::ReplaceString(
443 evit
->PreContext
, this->SimplifySourceDir
.c_str(), "/.../");
444 cmSystemTools::ReplaceString(
445 evit
->PostContext
, this->SimplifySourceDir
.c_str(), "/.../");
449 if ( !this->SimplifyBuildDir
.empty() )
451 for ( evit
= this->ErrorsAndWarnings
.begin();
452 evit
!= this->ErrorsAndWarnings
.end();
455 cmSystemTools::ReplaceString(
456 evit
->Text
, this->SimplifyBuildDir
.c_str(), "/.../");
457 cmSystemTools::ReplaceString(
458 evit
->PreContext
, this->SimplifyBuildDir
.c_str(), "/.../");
459 cmSystemTools::ReplaceString(
460 evit
->PostContext
, this->SimplifyBuildDir
.c_str(), "/.../");
464 // Display message about number of errors and warnings
465 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, " " << this->TotalErrors
466 << (this->TotalErrors
>= this->MaxErrors
? " or more" : "")
467 << " Compiler errors" << std::endl
);
468 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, " " << this->TotalWarnings
469 << (this->TotalWarnings
>= this->MaxWarnings
? " or more" : "")
470 << " Compiler warnings" << std::endl
);
472 // Generate XML output
473 cmGeneratedFileStream xofs
;
474 if( !this->StartResultingXML("Build", xofs
))
476 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "Cannot create build XML file"
480 this->GenerateDartBuildOutput(
481 xofs
, this->ErrorsAndWarnings
, elapsed_build_time
);
485 //----------------------------------------------------------------------
486 void cmCTestBuildHandler::GenerateDartBuildOutput(
488 std::vector
<cmCTestBuildErrorWarning
> ew
,
489 double elapsed_build_time
)
491 this->CTest
->StartXML(os
);
493 << "\t<StartDateTime>" << this->StartBuild
<< "</StartDateTime>\n"
494 << "\t<StartBuildTime>" <<
495 static_cast<unsigned int>(this->StartBuildTime
)
496 << "</StartBuildTime>\n"
498 << this->CTest
->MakeXMLSafe(
499 this->CTest
->GetCTestConfiguration("MakeCommand"))
500 << "</BuildCommand>" << std::endl
;
502 std::vector
<cmCTestBuildErrorWarning
>::iterator it
;
504 // only report the first 50 warnings and first 50 errors
505 unsigned short numErrorsAllowed
= this->MaxErrors
;
506 unsigned short numWarningsAllowed
= this->MaxWarnings
;
507 std::string srcdir
= this->CTest
->GetCTestConfiguration("SourceDirectory");
508 // make sure the source dir is in the correct case on windows
509 // via a call to collapse full path.
510 srcdir
= cmSystemTools::CollapseFullPath(srcdir
.c_str());
512 for ( it
= ew
.begin();
513 it
!= ew
.end() && (numErrorsAllowed
|| numWarningsAllowed
); it
++ )
515 cmCTestBuildErrorWarning
*cm
= &(*it
);
516 if (cm
->Error
&& numErrorsAllowed
||
517 !cm
->Error
&& numWarningsAllowed
)
525 numWarningsAllowed
--;
527 os
<< "\t<" << (cm
->Error
? "Error" : "Warning") << ">\n"
528 << "\t\t<BuildLogLine>" << cm
->LogLine
<< "</BuildLogLine>\n"
529 << "\t\t<Text>" << this->CTest
->MakeXMLSafe(cm
->Text
)
530 << "\n</Text>" << std::endl
;
531 std::vector
<cmCTestCompileErrorWarningRex
>::iterator rit
;
532 for ( rit
= this->ErrorWarningFileLineRegex
.begin();
533 rit
!= this->ErrorWarningFileLineRegex
.end(); ++ rit
)
535 cmsys::RegularExpression
* re
= &rit
->RegularExpression
;
536 if ( re
->find(cm
->Text
.c_str() ) )
538 cm
->SourceFile
= re
->match(rit
->FileIndex
);
539 // At this point we need to make this->SourceFile relative to
540 // the source root of the project, so cvs links will work
541 cmSystemTools::ConvertToUnixSlashes(cm
->SourceFile
);
542 if(cm
->SourceFile
.find("/.../") != cm
->SourceFile
.npos
)
544 cmSystemTools::ReplaceString(cm
->SourceFile
, "/.../", "");
545 std::string::size_type p
= cm
->SourceFile
.find("/");
546 if(p
!= cm
->SourceFile
.npos
)
548 cm
->SourceFile
= cm
->SourceFile
.substr(
549 p
+1, cm
->SourceFile
.size()-p
);
554 // make sure it is a full path with the correct case
555 cm
->SourceFile
= cmSystemTools::CollapseFullPath(
556 cm
->SourceFile
.c_str());
557 cmSystemTools::ReplaceString(
558 cm
->SourceFile
, srcdir
.c_str(), "");
560 cm
->LineNumber
= atoi(re
->match(rit
->LineIndex
).c_str());
564 if ( !cm
->SourceFile
.empty() && cm
->LineNumber
>= 0 )
566 if ( cm
->SourceFile
.size() > 0 )
568 os
<< "\t\t<SourceFile>" << cm
->SourceFile
<< "</SourceFile>"
571 if ( cm
->SourceFileTail
.size() > 0 )
573 os
<< "\t\t<SourceFileTail>" << cm
->SourceFileTail
574 << "</SourceFileTail>" << std::endl
;
576 if ( cm
->LineNumber
>= 0 )
578 os
<< "\t\t<SourceLineNumber>" << cm
->LineNumber
579 << "</SourceLineNumber>" << std::endl
;
582 os
<< "\t\t<PreContext>" << this->CTest
->MakeXMLSafe(cm
->PreContext
)
584 << "\t\t<PostContext>" << this->CTest
->MakeXMLSafe(cm
->PostContext
);
585 // is this the last warning or error, if so notify
586 if (cm
->Error
&& !numErrorsAllowed
||
587 !cm
->Error
&& !numWarningsAllowed
)
589 os
<< "\nThe maximum number of reported warnings or errors has been "
592 os
<< "</PostContext>\n"
593 << "\t\t<RepeatCount>0</RepeatCount>\n"
594 << "</" << (cm
->Error
? "Error" : "Warning") << ">\n\n"
598 os
<< "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
599 << "\t<EndDateTime>" << this->EndBuild
<< "</EndDateTime>\n"
600 << "\t<EndBuildTime>" << static_cast<unsigned int>(this->EndBuildTime
)
601 << "</EndBuildTime>\n"
602 << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time
/6)/10.0
603 << "</ElapsedMinutes>"
604 << "</Build>" << std::endl
;
605 this->CTest
->EndXML(os
);
608 //######################################################################
609 //######################################################################
610 //######################################################################
611 //######################################################################
613 //----------------------------------------------------------------------
614 int cmCTestBuildHandler::RunMakeCommand(const char* command
,
615 int* retVal
, const char* dir
, int timeout
, std::ofstream
& ofs
)
617 // First generate the command and arguments
618 std::vector
<cmStdString
> args
= cmSystemTools::ParseArguments(command
);
625 std::vector
<const char*> argv
;
626 for(std::vector
<cmStdString
>::const_iterator a
= args
.begin();
627 a
!= args
.end(); ++a
)
629 argv
.push_back(a
->c_str());
633 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
, "Run command:");
634 std::vector
<const char*>::iterator ait
;
635 for ( ait
= argv
.begin(); ait
!= argv
.end() && *ait
; ++ ait
)
637 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
, " \"" << *ait
<< "\"");
639 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
, std::endl
);
641 // Now create process object
642 cmsysProcess
* cp
= cmsysProcess_New();
643 cmsysProcess_SetCommand(cp
, &*argv
.begin());
644 cmsysProcess_SetWorkingDirectory(cp
, dir
);
645 cmsysProcess_SetOption(cp
, cmsysProcess_Option_HideWindow
, 1);
646 cmsysProcess_SetTimeout(cp
, timeout
);
647 cmsysProcess_Execute(cp
);
650 std::string::size_type tick
= 0;
651 const std::string::size_type tick_len
= 1024;
655 cmCTestLog(this->CTest
, HANDLER_OUTPUT
,
656 " Each symbol represents " << tick_len
<< " bytes of output."
658 << " '!' represents an error and '*' a warning." << std::endl
659 << " " << std::flush
);
661 // Initialize building structures
662 this->BuildProcessingQueue
.clear();
663 this->OutputLineCounter
= 0;
664 this->ErrorsAndWarnings
.clear();
665 this->TotalErrors
= 0;
666 this->TotalWarnings
= 0;
667 this->BuildOutputLogSize
= 0;
668 this->LastTickChar
= '.';
669 this->WarningQuotaReached
= false;
670 this->ErrorQuotaReached
= false;
672 // For every chunk of data
674 while((res
= cmsysProcess_WaitForData(cp
, &data
, &length
, 0)))
676 // Replace '\0' with '\n', since '\0' does not really make sense. This is
677 // for Visual Studio output
678 for(int cc
=0; cc
< length
; ++cc
)
686 // Process the chunk of data
687 if ( res
== cmsysProcess_Pipe_STDERR
)
689 this->ProcessBuffer(data
, length
, tick
, tick_len
, ofs
,
690 &this->BuildProcessingErrorQueue
);
694 this->ProcessBuffer(data
, length
, tick
, tick_len
, ofs
,
695 &this->BuildProcessingQueue
);
699 this->ProcessBuffer(0, 0, tick
, tick_len
, ofs
, &this->BuildProcessingQueue
);
700 this->ProcessBuffer(0, 0, tick
, tick_len
, ofs
,
701 &this->BuildProcessingErrorQueue
);
702 cmCTestLog(this->CTest
, OUTPUT
, " Size of output: "
703 << int(this->BuildOutputLogSize
/ 1024.0) << "K" << std::endl
);
705 // Properly handle output of the build command
706 cmsysProcess_WaitForExit(cp
, 0);
707 int result
= cmsysProcess_GetState(cp
);
709 if(result
== cmsysProcess_State_Exited
)
713 *retVal
= cmsysProcess_GetExitValue(cp
);
714 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
,
715 "Command exited with the value: " << *retVal
<< std::endl
);
716 // if a non zero return value
719 // If there was an error running command, report that on the
721 cmCTestBuildErrorWarning errorwarning
;
722 errorwarning
.LogLine
= 1;
724 = "*** WARNING non-zero return value in ctest from: ";
725 errorwarning
.Text
+= argv
[0];
726 errorwarning
.PreContext
= "";
727 errorwarning
.PostContext
= "";
728 errorwarning
.Error
= false;
729 this->ErrorsAndWarnings
.push_back(errorwarning
);
730 this->TotalWarnings
++;
734 else if(result
== cmsysProcess_State_Exception
)
738 *retVal
= cmsysProcess_GetExitException(cp
);
739 cmCTestLog(this->CTest
, WARNING
, "There was an exception: " << *retVal
743 else if(result
== cmsysProcess_State_Expired
)
745 cmCTestLog(this->CTest
, WARNING
, "There was a timeout" << std::endl
);
747 else if(result
== cmsysProcess_State_Error
)
749 // If there was an error running command, report that on the dashboard.
750 cmCTestBuildErrorWarning errorwarning
;
751 errorwarning
.LogLine
= 1;
752 errorwarning
.Text
= "*** ERROR executing: ";
753 errorwarning
.Text
+= cmsysProcess_GetErrorString(cp
);
754 errorwarning
.PreContext
= "";
755 errorwarning
.PostContext
= "";
756 errorwarning
.Error
= true;
757 this->ErrorsAndWarnings
.push_back(errorwarning
);
758 this->TotalErrors
++;
759 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "There was an error: "
760 << cmsysProcess_GetErrorString(cp
) << std::endl
);
763 cmsysProcess_Delete(cp
);
768 //######################################################################
769 //######################################################################
770 //######################################################################
771 //######################################################################
773 //----------------------------------------------------------------------
774 void cmCTestBuildHandler::ProcessBuffer(const char* data
, int length
,
775 size_t& tick
, size_t tick_len
, std::ofstream
& ofs
,
776 t_BuildProcessingQueueType
* queue
)
778 const std::string::size_type tick_line_len
= 50;
780 for ( ptr
= data
; ptr
< data
+length
; ptr
++ )
782 queue
->push_back(*ptr
);
784 this->BuildOutputLogSize
+= length
;
786 // until there are any lines left in the buffer
789 // Find the end of line
790 t_BuildProcessingQueueType::iterator it
;
791 for ( it
= queue
->begin();
801 // Once certain number of errors or warnings reached, ignore future errors
803 if ( this->TotalWarnings
>= this->MaxWarnings
)
805 this->WarningQuotaReached
= true;
807 if ( this->TotalErrors
>= this->MaxErrors
)
809 this->ErrorQuotaReached
= true;
812 // If the end of line was found
813 if ( it
!= queue
->end() )
815 // Create a contiguous array for the line
816 this->CurrentProcessingLine
.clear();
817 t_BuildProcessingQueueType::iterator cit
;
818 for ( cit
= queue
->begin(); cit
!= it
; ++cit
)
820 this->CurrentProcessingLine
.push_back(*cit
);
822 this->CurrentProcessingLine
.push_back(0);
823 const char* line
= &*this->CurrentProcessingLine
.begin();
826 int lineType
= this->ProcessSingleLine(line
);
828 // Erase the line from the queue
829 queue
->erase(queue
->begin(), it
+1);
831 // Depending on the line type, produce error or warning, or nothing
832 cmCTestBuildErrorWarning errorwarning
;
837 this->LastTickChar
= '*';
838 errorwarning
.Error
= false;
840 this->TotalWarnings
++;
843 this->LastTickChar
= '!';
844 errorwarning
.Error
= true;
846 this->TotalErrors
++;
851 // This is an error or warning, so generate report
852 errorwarning
.LogLine
= static_cast<int>(this->OutputLineCounter
+1);
853 errorwarning
.Text
= line
;
854 errorwarning
.PreContext
= "";
855 errorwarning
.PostContext
= "";
857 // Copy pre-context to report
858 std::deque
<cmStdString
>::iterator pcit
;
859 for ( pcit
= this->PreContext
.begin();
860 pcit
!= this->PreContext
.end();
863 errorwarning
.PreContext
+= *pcit
+ "\n";
865 this->PreContext
.clear();
868 this->ErrorsAndWarnings
.push_back(errorwarning
);
869 this->LastErrorOrWarning
= this->ErrorsAndWarnings
.end()-1;
870 this->PostContextCount
= 0;
874 // This is not an error or warning.
875 // So, figure out if this is a post-context line
876 if ( this->ErrorsAndWarnings
.size() &&
877 this->LastErrorOrWarning
!= this->ErrorsAndWarnings
.end() &&
878 this->PostContextCount
< this->MaxPostContext
)
880 this->PostContextCount
++;
881 this->LastErrorOrWarning
->PostContext
+= line
;
882 if ( this->PostContextCount
< this->MaxPostContext
)
884 this->LastErrorOrWarning
->PostContext
+= "\n";
889 // Otherwise store pre-context for the next error
890 this->PreContext
.push_back(line
);
891 if ( this->PreContext
.size() > this->MaxPreContext
)
893 this->PreContext
.erase(this->PreContext
.begin(),
894 this->PreContext
.end()-this->MaxPreContext
);
898 this->OutputLineCounter
++;
906 // Now that the buffer is processed, display missing ticks
907 int tickDisplayed
= false;
908 while ( this->BuildOutputLogSize
> (tick
* tick_len
) )
911 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, this->LastTickChar
);
912 tickDisplayed
= true;
913 if ( tick
% tick_line_len
== 0 && tick
> 0 )
915 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, " Size: "
916 << int((this->BuildOutputLogSize
/ 1024.0) + 1) << "K" << std::endl
922 this->LastTickChar
= '.';
925 // And if this is verbose output, display the content of the chunk
926 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
,
927 cmCTestLogWrite(data
, length
));
929 // Always store the chunk to the file
930 ofs
<< cmCTestLogWrite(data
, length
);
933 //----------------------------------------------------------------------
934 int cmCTestBuildHandler::ProcessSingleLine(const char* data
)
936 cmCTestLog(this->CTest
, DEBUG
, "Line: [" << data
<< "]" << std::endl
);
938 std::vector
<cmsys::RegularExpression
>::iterator it
;
943 // Check for regular expressions
945 if ( !this->ErrorQuotaReached
)
949 for ( it
= this->ErrorMatchRegex
.begin();
950 it
!= this->ErrorMatchRegex
.end();
953 if ( it
->find(data
) )
956 cmCTestLog(this->CTest
, DEBUG
, " Error Line: " << data
957 << " (matches: " << this->CustomErrorMatches
[wrxCnt
] << ")"
965 for ( it
= this->ErrorExceptionRegex
.begin();
966 it
!= this->ErrorExceptionRegex
.end();
969 if ( it
->find(data
) )
972 cmCTestLog(this->CTest
, DEBUG
, " Not an error Line: " << data
973 << " (matches: " << this->CustomErrorExceptions
[wrxCnt
] << ")"
980 if ( !this->WarningQuotaReached
)
984 for ( it
= this->WarningMatchRegex
.begin();
985 it
!= this->WarningMatchRegex
.end();
988 if ( it
->find(data
) )
991 cmCTestLog(this->CTest
, DEBUG
,
992 " Warning Line: " << data
993 << " (matches: " << this->CustomWarningMatches
[wrxCnt
] << ")"
1001 // Warning exceptions
1002 for ( it
= this->WarningExceptionRegex
.begin();
1003 it
!= this->WarningExceptionRegex
.end();
1006 if ( it
->find(data
) )
1009 cmCTestLog(this->CTest
, DEBUG
, " Not a warning Line: " << data
1010 << " (matches: " << this->CustomWarningExceptions
[wrxCnt
] << ")"
1019 return b_ERROR_LINE
;
1023 return b_WARNING_LINE
;
1025 return b_REGULAR_LINE
;