1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestBuildHandler.cxx,v $
6 Date: $Date: 2007-06-14 17:05:09 $
7 Version: $Revision: 1.60 $
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 "cmCTestBuildHandler.h"
22 #include "cmMakefile.h"
23 #include "cmLocalGenerator.h"
24 #include "cmGlobalGenerator.h"
25 #include "cmGeneratedFileStream.h"
27 //#include <cmsys/RegularExpression.hxx>
28 #include <cmsys/Process.h>
40 #if defined(__BORLANDC__)
41 # pragma warn -8060 /* possibly incorrect assignment */
44 static const char* cmCTestErrorMatches
[] = {
46 "^[Ss]egmentation [Vv]iolation",
47 "^[Ss]egmentation [Ff]ault",
48 "([^ :]+):([0-9]+): ([^ \\t])",
49 "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
55 "^\"[^\"]+\", line [0-9]+: [^Ww]",
56 "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
57 "^ld([^:])*:([ \\t])*ERROR([^:])*:",
58 "^ild:([ \\t])*\\(undefined symbol\\)",
59 "([^ :]+) : (error|fatal error|catastrophic error)",
60 "([^:]+): (Error:|error|undefined reference|multiply defined)",
61 "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
62 "^fatal error C[0-9]+:",
64 "^collect2: ld returned 1 exit status",
65 "Unsatisfied symbols:",
68 "^Undefined[ \\t]+first referenced",
72 ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
73 ": \\*\\*\\* No targets specified and no makefile found",
74 ": Invalid loader fixup for symbol",
75 ": Invalid fixups exist",
76 ": Can't find library for",
77 ": internal link edit command failed",
78 ": Unrecognized option \\`.*\\'",
79 "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^WI]\\)",
80 "ld: 0706-006 Cannot find or open library file: -l ",
81 "ild: \\(argument error\\) can't find library argument ::",
82 "^could not be found and will not be loaded.",
83 "s:616 string too big",
84 "make: Fatal error: ",
85 "ld: 0711-993 Error occurred while writing to the output file:",
88 "make: \\*\\*\\*.*Error",
89 "make\\[.*\\]: \\*\\*\\*.*Error",
90 "\\*\\*\\* Error code",
92 "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
93 ": No such file or directory",
95 "^The project cannot be built\\.",
99 static const char* cmCTestErrorExceptions
[] = {
100 "instantiated from ",
108 "([^ :]+):([0-9]+): Warning",
109 "------ Build started: .* ------",
113 static const char* cmCTestWarningMatches
[] = {
114 "([^ :]+):([0-9]+): warning:",
115 "([^ :]+):([0-9]+): note:",
116 "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
117 "^ld([^:])*:([ \\t])*WARNING([^:])*:",
118 "([^:]+): warning ([0-9]+):",
119 "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
120 "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
121 "^(Warning|Warnung) ([0-9]+):",
122 "^(Warning|Warnung) ",
124 "([^ :]+) : warning",
126 "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([WI]\\)",
128 ".*file: .* has no symbols",
129 "([^ :]+):([0-9]+): (Warning|Warnung)",
130 "\\([0-9]*\\): remark #[0-9]*",
131 "\".*\", line [0-9]+: remark\\([0-9]*\\):",
132 "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
136 static const char* cmCTestWarningExceptions
[] = {
137 "/usr/.*/X11/Xlib\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
138 "/usr/.*/X11/Xutil\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
139 "/usr/.*/X11/XResource\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
144 "warning: Clock skew detected. Your build may be incomplete.",
145 "/usr/openwin/include/GL/[^:]+:",
149 "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
150 "ld32: WARNING 85: definition of dataKey in",
151 "cc: warning 422: Unknown option \"\\+b",
156 struct cmCTestBuildCompileErrorWarningRex
158 const char* RegularExpressionString
;
163 static cmCTestBuildCompileErrorWarningRex
164 cmCTestWarningErrorFileLine
[] = {
165 { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
166 { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
167 { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
168 { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
169 { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
170 { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
174 //----------------------------------------------------------------------
175 cmCTestBuildHandler::cmCTestBuildHandler()
177 this->MaxPreContext
= 6;
178 this->MaxPostContext
= 6;
180 this->MaxErrors
= 50;
181 this->MaxWarnings
= 50;
183 this->LastErrorOrWarning
= this->ErrorsAndWarnings
.end();
187 //----------------------------------------------------------------------
188 void cmCTestBuildHandler::Initialize()
190 this->Superclass::Initialize();
191 this->StartBuild
= "";
193 this->CustomErrorMatches
.clear();
194 this->CustomErrorExceptions
.clear();
195 this->CustomWarningMatches
.clear();
196 this->CustomWarningExceptions
.clear();
197 this->ErrorWarningFileLineRegex
.clear();
199 this->ErrorMatchRegex
.clear();
200 this->ErrorExceptionRegex
.clear();
201 this->WarningMatchRegex
.clear();
202 this->WarningExceptionRegex
.clear();
203 this->BuildProcessingQueue
.clear();
204 this->BuildProcessingErrorQueue
.clear();
205 this->BuildOutputLogSize
= 0;
206 this->CurrentProcessingLine
.clear();
208 this->SimplifySourceDir
= "";
209 this->SimplifyBuildDir
= "";
210 this->OutputLineCounter
= 0;
211 this->ErrorsAndWarnings
.clear();
212 this->LastErrorOrWarning
= this->ErrorsAndWarnings
.end();
213 this->PostContextCount
= 0;
214 this->MaxPreContext
= 6;
215 this->MaxPostContext
= 6;
216 this->PreContext
.clear();
218 this->TotalErrors
= 0;
219 this->TotalWarnings
= 0;
220 this->LastTickChar
= 0;
222 this->ErrorQuotaReached
= false;
223 this->WarningQuotaReached
= false;
225 this->MaxErrors
= 50;
226 this->MaxWarnings
= 50;
229 //----------------------------------------------------------------------
230 void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile
*mf
)
232 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_ERROR_MATCH",
233 this->CustomErrorMatches
);
234 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_ERROR_EXCEPTION",
235 this->CustomErrorExceptions
);
236 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_WARNING_MATCH",
237 this->CustomWarningMatches
);
238 this->CTest
->PopulateCustomVector(mf
, "CTEST_CUSTOM_WARNING_EXCEPTION",
239 this->CustomWarningExceptions
);
240 this->CTest
->PopulateCustomInteger(mf
,
241 "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
243 this->CTest
->PopulateCustomInteger(mf
,
244 "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
248 //----------------------------------------------------------------------
249 //clearly it would be nice if this were broken up into a few smaller
250 //functions and commented...
251 int cmCTestBuildHandler::ProcessHandler()
253 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, "Build project" << std::endl
);
255 // do we have time for this
256 if (this->CTest
->GetRemainingTimeAllowed() < 120)
263 cmCTestWarningErrorFileLine
[entry
].RegularExpressionString
;
266 cmCTestBuildHandler::cmCTestCompileErrorWarningRex r
;
267 if ( r
.RegularExpression
.compile(
268 cmCTestWarningErrorFileLine
[entry
].RegularExpressionString
) )
270 r
.FileIndex
= cmCTestWarningErrorFileLine
[entry
].FileIndex
;
271 r
.LineIndex
= cmCTestWarningErrorFileLine
[entry
].LineIndex
;
272 this->ErrorWarningFileLineRegex
.push_back(r
);
276 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
277 "Problem Compiling regular expression: "
278 << cmCTestWarningErrorFileLine
[entry
].RegularExpressionString
283 // Determine build command and build directory
284 const std::string
&makeCommand
285 = this->CTest
->GetCTestConfiguration("MakeCommand");
286 cmCTestLog(this->CTest
,
287 HANDLER_VERBOSE_OUTPUT
, "MakeCommand:" << makeCommand
<<
289 if ( makeCommand
.size() == 0 )
291 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
292 "Cannot find MakeCommand key in the DartConfiguration.tcl"
296 const std::string
&buildDirectory
297 = this->CTest
->GetCTestConfiguration("BuildDirectory");
298 if ( buildDirectory
.size() == 0 )
300 cmCTestLog(this->CTest
, ERROR_MESSAGE
,
301 "Cannot find BuildDirectory key in the DartConfiguration.tcl"
306 // Create a last build log
307 cmGeneratedFileStream ofs
;
308 double elapsed_time_start
= cmSystemTools::GetTime();
309 if ( !this->StartLogFile("Build", ofs
) )
311 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "Cannot create build log file"
315 // Create lists of regular expression strings for errors, error exceptions,
316 // warnings and warning exceptions.
317 std::vector
<cmStdString
>::size_type cc
;
318 for ( cc
= 0; cmCTestErrorMatches
[cc
]; cc
++ )
320 this->CustomErrorMatches
.push_back(cmCTestErrorMatches
[cc
]);
322 for ( cc
= 0; cmCTestErrorExceptions
[cc
]; cc
++ )
324 this->CustomErrorExceptions
.push_back(cmCTestErrorExceptions
[cc
]);
326 for ( cc
= 0; cmCTestWarningMatches
[cc
]; cc
++ )
328 this->CustomWarningMatches
.push_back(cmCTestWarningMatches
[cc
]);
331 for ( cc
= 0; cmCTestWarningExceptions
[cc
]; cc
++ )
333 this->CustomWarningExceptions
.push_back(cmCTestWarningExceptions
[cc
]);
336 // Pre-compile regular expressions objects for all regular expressions
337 std::vector
<cmStdString
>::iterator it
;
339 #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
341 cmCTestLog(this->CTest, DEBUG, this << "Add " #regexes \
343 for ( it = strings.begin(); it != strings.end(); ++it ) \
345 cmCTestLog(this->CTest, DEBUG, "Add " #strings ": " \
346 << it->c_str() << std::endl); \
347 regexes.push_back(it->c_str()); \
349 cmCTestBuildHandlerPopulateRegexVector(
350 this->CustomErrorMatches
, this->ErrorMatchRegex
);
351 cmCTestBuildHandlerPopulateRegexVector(
352 this->CustomErrorExceptions
, this->ErrorExceptionRegex
);
353 cmCTestBuildHandlerPopulateRegexVector(
354 this->CustomWarningMatches
, this->WarningMatchRegex
);
355 cmCTestBuildHandlerPopulateRegexVector(
356 this->CustomWarningExceptions
, this->WarningExceptionRegex
);
359 // Determine source and binary tree substitutions to simplify the output.
360 this->SimplifySourceDir
= "";
361 this->SimplifyBuildDir
= "";
362 if ( this->CTest
->GetCTestConfiguration("SourceDirectory").size() > 20 )
365 = this->CTest
->GetCTestConfiguration("SourceDirectory") + "/";
366 std::string srcdirrep
;
367 for ( cc
= srcdir
.size()-2; cc
> 0; cc
-- )
369 if ( srcdir
[cc
] == '/' )
371 srcdirrep
= srcdir
.c_str() + cc
;
372 srcdirrep
= "/..." + srcdirrep
;
373 srcdir
= srcdir
.substr(0, cc
+1);
377 this->SimplifySourceDir
= srcdir
;
379 if ( this->CTest
->GetCTestConfiguration("BuildDirectory").size() > 20 )
382 = this->CTest
->GetCTestConfiguration("BuildDirectory") + "/";
383 std::string bindirrep
;
384 for ( cc
= bindir
.size()-2; cc
> 0; cc
-- )
386 if ( bindir
[cc
] == '/' )
388 bindirrep
= bindir
.c_str() + cc
;
389 bindirrep
= "/..." + bindirrep
;
390 bindir
= bindir
.substr(0, cc
+1);
394 this->SimplifyBuildDir
= bindir
;
398 // Ok, let's do the build
400 // Remember start build time
401 this->StartBuild
= this->CTest
->CurrentTime();
403 int res
= cmsysProcess_State_Exited
;
404 if ( !this->CTest
->GetShowOnly() )
406 res
= this->RunMakeCommand(makeCommand
.c_str(), &retVal
,
407 buildDirectory
.c_str(), 0, ofs
);
411 cmCTestLog(this->CTest
, DEBUG
, "Build with command: " << makeCommand
415 // Remember end build time and calculate elapsed time
416 this->EndBuild
= this->CTest
->CurrentTime();
417 double elapsed_build_time
= cmSystemTools::GetTime() - elapsed_time_start
;
418 if (res
!= cmsysProcess_State_Exited
|| retVal
)
420 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "Error(s) when building project"
424 // Cleanups strings in the errors and warnings list.
425 t_ErrorsAndWarningsVector::iterator evit
;
426 if ( !this->SimplifySourceDir
.empty() )
428 for ( evit
= this->ErrorsAndWarnings
.begin();
429 evit
!= this->ErrorsAndWarnings
.end();
432 cmSystemTools::ReplaceString(
433 evit
->Text
, this->SimplifySourceDir
.c_str(), "/.../");
434 cmSystemTools::ReplaceString(
435 evit
->PreContext
, this->SimplifySourceDir
.c_str(), "/.../");
436 cmSystemTools::ReplaceString(
437 evit
->PostContext
, this->SimplifySourceDir
.c_str(), "/.../");
441 if ( !this->SimplifyBuildDir
.empty() )
443 for ( evit
= this->ErrorsAndWarnings
.begin();
444 evit
!= this->ErrorsAndWarnings
.end();
447 cmSystemTools::ReplaceString(
448 evit
->Text
, this->SimplifyBuildDir
.c_str(), "/.../");
449 cmSystemTools::ReplaceString(
450 evit
->PreContext
, this->SimplifyBuildDir
.c_str(), "/.../");
451 cmSystemTools::ReplaceString(
452 evit
->PostContext
, this->SimplifyBuildDir
.c_str(), "/.../");
456 // Display message about number of errors and warnings
457 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, " " << this->TotalErrors
458 << (this->TotalErrors
>= this->MaxErrors
? " or more" : "")
459 << " Compiler errors" << std::endl
);
460 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, " " << this->TotalWarnings
461 << (this->TotalWarnings
>= this->MaxWarnings
? " or more" : "")
462 << " Compiler warnings" << std::endl
);
464 // Generate XML output
465 cmGeneratedFileStream xofs
;
466 if( !this->StartResultingXML("Build", xofs
))
468 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "Cannot create build XML file"
472 this->GenerateDartBuildOutput(
473 xofs
, this->ErrorsAndWarnings
, elapsed_build_time
);
477 //----------------------------------------------------------------------
478 void cmCTestBuildHandler::GenerateDartBuildOutput(
480 std::vector
<cmCTestBuildErrorWarning
> ew
,
481 double elapsed_build_time
)
483 this->CTest
->StartXML(os
);
485 << "\t<StartDateTime>" << this->StartBuild
<< "</StartDateTime>\n"
487 << this->CTest
->MakeXMLSafe(
488 this->CTest
->GetCTestConfiguration("MakeCommand"))
489 << "</BuildCommand>" << std::endl
;
491 std::vector
<cmCTestBuildErrorWarning
>::iterator it
;
493 // only report the first 50 warnings and first 50 errors
494 unsigned short numErrorsAllowed
= this->MaxErrors
;
495 unsigned short numWarningsAllowed
= this->MaxWarnings
;
496 std::string srcdir
= this->CTest
->GetCTestConfiguration("SourceDirectory");
497 // make sure the source dir is in the correct case on windows
498 // via a call to collapse full path.
499 srcdir
= cmSystemTools::CollapseFullPath(srcdir
.c_str());
501 for ( it
= ew
.begin();
502 it
!= ew
.end() && (numErrorsAllowed
|| numWarningsAllowed
); it
++ )
504 cmCTestBuildErrorWarning
*cm
= &(*it
);
505 if (cm
->Error
&& numErrorsAllowed
||
506 !cm
->Error
&& numWarningsAllowed
)
514 numWarningsAllowed
--;
516 os
<< "\t<" << (cm
->Error
? "Error" : "Warning") << ">\n"
517 << "\t\t<BuildLogLine>" << cm
->LogLine
<< "</BuildLogLine>\n"
518 << "\t\t<Text>" << this->CTest
->MakeXMLSafe(cm
->Text
)
519 << "\n</Text>" << std::endl
;
520 std::vector
<cmCTestCompileErrorWarningRex
>::iterator rit
;
521 for ( rit
= this->ErrorWarningFileLineRegex
.begin();
522 rit
!= this->ErrorWarningFileLineRegex
.end(); ++ rit
)
524 cmsys::RegularExpression
* re
= &rit
->RegularExpression
;
525 if ( re
->find(cm
->Text
.c_str() ) )
527 cm
->SourceFile
= re
->match(rit
->FileIndex
);
528 // At this point we need to make this->SourceFile relative to
529 // the source root of the project, so cvs links will work
530 cmSystemTools::ConvertToUnixSlashes(cm
->SourceFile
);
531 if(cm
->SourceFile
.find("/.../") != cm
->SourceFile
.npos
)
533 cmSystemTools::ReplaceString(cm
->SourceFile
, "/.../", "");
534 std::string::size_type p
= cm
->SourceFile
.find("/");
535 if(p
!= cm
->SourceFile
.npos
)
537 cm
->SourceFile
= cm
->SourceFile
.substr(
538 p
+1, cm
->SourceFile
.size()-p
);
543 // make sure it is a full path with the correct case
544 cm
->SourceFile
= cmSystemTools::CollapseFullPath(
545 cm
->SourceFile
.c_str());
546 cmSystemTools::ReplaceString(
547 cm
->SourceFile
, srcdir
.c_str(), "");
549 cm
->LineNumber
= atoi(re
->match(rit
->LineIndex
).c_str());
553 if ( !cm
->SourceFile
.empty() && cm
->LineNumber
>= 0 )
555 if ( cm
->SourceFile
.size() > 0 )
557 os
<< "\t\t<SourceFile>" << cm
->SourceFile
<< "</SourceFile>"
560 if ( cm
->SourceFileTail
.size() > 0 )
562 os
<< "\t\t<SourceFileTail>" << cm
->SourceFileTail
563 << "</SourceFileTail>" << std::endl
;
565 if ( cm
->LineNumber
>= 0 )
567 os
<< "\t\t<SourceLineNumber>" << cm
->LineNumber
568 << "</SourceLineNumber>" << std::endl
;
571 os
<< "\t\t<PreContext>" << this->CTest
->MakeXMLSafe(cm
->PreContext
)
573 << "\t\t<PostContext>" << this->CTest
->MakeXMLSafe(cm
->PostContext
);
574 // is this the last warning or error, if so notify
575 if (cm
->Error
&& !numErrorsAllowed
||
576 !cm
->Error
&& !numWarningsAllowed
)
578 os
<< "\nThe maximum number of reported warnings or errors has been "
581 os
<< "</PostContext>\n"
582 << "\t\t<RepeatCount>0</RepeatCount>\n"
583 << "</" << (cm
->Error
? "Error" : "Warning") << ">\n\n"
587 os
<< "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
588 << "\t<EndDateTime>" << this->EndBuild
<< "</EndDateTime>\n"
589 << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time
/6)/10.0
590 << "</ElapsedMinutes>"
591 << "</Build>" << std::endl
;
592 this->CTest
->EndXML(os
);
595 //######################################################################
596 //######################################################################
597 //######################################################################
598 //######################################################################
600 //----------------------------------------------------------------------
601 int cmCTestBuildHandler::RunMakeCommand(const char* command
,
602 int* retVal
, const char* dir
, int timeout
, std::ofstream
& ofs
)
604 // First generate the command and arguments
605 std::vector
<cmStdString
> args
= cmSystemTools::ParseArguments(command
);
612 std::vector
<const char*> argv
;
613 for(std::vector
<cmStdString
>::const_iterator a
= args
.begin();
614 a
!= args
.end(); ++a
)
616 argv
.push_back(a
->c_str());
620 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
, "Run command:");
621 std::vector
<const char*>::iterator ait
;
622 for ( ait
= argv
.begin(); ait
!= argv
.end() && *ait
; ++ ait
)
624 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
, " \"" << *ait
<< "\"");
626 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
, std::endl
);
628 // Now create process object
629 cmsysProcess
* cp
= cmsysProcess_New();
630 cmsysProcess_SetCommand(cp
, &*argv
.begin());
631 cmsysProcess_SetWorkingDirectory(cp
, dir
);
632 cmsysProcess_SetOption(cp
, cmsysProcess_Option_HideWindow
, 1);
633 cmsysProcess_SetTimeout(cp
, timeout
);
634 cmsysProcess_Execute(cp
);
637 std::string::size_type tick
= 0;
638 const std::string::size_type tick_len
= 1024;
642 cmCTestLog(this->CTest
, HANDLER_OUTPUT
,
643 " Each symbol represents " << tick_len
<< " bytes of output."
645 << " '!' represents an error and '*' a warning." << std::endl
646 << " " << std::flush
);
648 // Initialize building structures
649 this->BuildProcessingQueue
.clear();
650 this->OutputLineCounter
= 0;
651 this->ErrorsAndWarnings
.clear();
652 this->TotalErrors
= 0;
653 this->TotalWarnings
= 0;
654 this->BuildOutputLogSize
= 0;
655 this->LastTickChar
= '.';
656 this->WarningQuotaReached
= false;
657 this->ErrorQuotaReached
= false;
659 // For every chunk of data
661 while((res
= cmsysProcess_WaitForData(cp
, &data
, &length
, 0)))
663 // Replace '\0' with '\n', since '\0' does not really make sense. This is
664 // for Visual Studio output
665 for(int cc
=0; cc
< length
; ++cc
)
673 // Process the chunk of data
674 if ( res
== cmsysProcess_Pipe_STDERR
)
676 this->ProcessBuffer(data
, length
, tick
, tick_len
, ofs
,
677 &this->BuildProcessingErrorQueue
);
681 this->ProcessBuffer(data
, length
, tick
, tick_len
, ofs
,
682 &this->BuildProcessingQueue
);
686 this->ProcessBuffer(0, 0, tick
, tick_len
, ofs
, &this->BuildProcessingQueue
);
687 this->ProcessBuffer(0, 0, tick
, tick_len
, ofs
,
688 &this->BuildProcessingErrorQueue
);
689 cmCTestLog(this->CTest
, OUTPUT
, " Size of output: "
690 << int(this->BuildOutputLogSize
/ 1024.0) << "K" << std::endl
);
692 // Properly handle output of the build command
693 cmsysProcess_WaitForExit(cp
, 0);
694 int result
= cmsysProcess_GetState(cp
);
696 if(result
== cmsysProcess_State_Exited
)
700 *retVal
= cmsysProcess_GetExitValue(cp
);
701 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
,
702 "Command exited with the value: " << *retVal
<< std::endl
);
703 // if a non zero return value
706 // If there was an error running command, report that on the
708 cmCTestBuildErrorWarning errorwarning
;
709 errorwarning
.LogLine
= 1;
711 = "*** WARNING non-zero return value in ctest from: ";
712 errorwarning
.Text
+= argv
[0];
713 errorwarning
.PreContext
= "";
714 errorwarning
.PostContext
= "";
715 errorwarning
.Error
= false;
716 this->ErrorsAndWarnings
.push_back(errorwarning
);
717 this->TotalWarnings
++;
721 else if(result
== cmsysProcess_State_Exception
)
725 *retVal
= cmsysProcess_GetExitException(cp
);
726 cmCTestLog(this->CTest
, WARNING
, "There was an exception: " << *retVal
730 else if(result
== cmsysProcess_State_Expired
)
732 cmCTestLog(this->CTest
, WARNING
, "There was a timeout" << std::endl
);
734 else if(result
== cmsysProcess_State_Error
)
736 // If there was an error running command, report that on the dashboard.
737 cmCTestBuildErrorWarning errorwarning
;
738 errorwarning
.LogLine
= 1;
739 errorwarning
.Text
= "*** ERROR executing: ";
740 errorwarning
.Text
+= cmsysProcess_GetErrorString(cp
);
741 errorwarning
.PreContext
= "";
742 errorwarning
.PostContext
= "";
743 errorwarning
.Error
= true;
744 this->ErrorsAndWarnings
.push_back(errorwarning
);
745 this->TotalErrors
++;
746 cmCTestLog(this->CTest
, ERROR_MESSAGE
, "There was an error: "
747 << cmsysProcess_GetErrorString(cp
) << std::endl
);
750 cmsysProcess_Delete(cp
);
755 //######################################################################
756 //######################################################################
757 //######################################################################
758 //######################################################################
760 //----------------------------------------------------------------------
761 void cmCTestBuildHandler::ProcessBuffer(const char* data
, int length
,
762 size_t& tick
, size_t tick_len
, std::ofstream
& ofs
,
763 t_BuildProcessingQueueType
* queue
)
765 const std::string::size_type tick_line_len
= 50;
767 for ( ptr
= data
; ptr
< data
+length
; ptr
++ )
769 queue
->push_back(*ptr
);
771 this->BuildOutputLogSize
+= length
;
773 // until there are any lines left in the buffer
776 // Find the end of line
777 t_BuildProcessingQueueType::iterator it
;
778 for ( it
= queue
->begin();
788 // Once certain number of errors or warnings reached, ignore future errors
790 if ( this->TotalWarnings
>= this->MaxWarnings
)
792 this->WarningQuotaReached
= true;
794 if ( this->TotalErrors
>= this->MaxErrors
)
796 this->ErrorQuotaReached
= true;
799 // If the end of line was found
800 if ( it
!= queue
->end() )
802 // Create a contiguous array for the line
803 this->CurrentProcessingLine
.clear();
804 t_BuildProcessingQueueType::iterator cit
;
805 for ( cit
= queue
->begin(); cit
!= it
; ++cit
)
807 this->CurrentProcessingLine
.push_back(*cit
);
809 this->CurrentProcessingLine
.push_back(0);
810 const char* line
= &*this->CurrentProcessingLine
.begin();
813 int lineType
= this->ProcessSingleLine(line
);
815 // Erase the line from the queue
816 queue
->erase(queue
->begin(), it
+1);
818 // Depending on the line type, produce error or warning, or nothing
819 cmCTestBuildErrorWarning errorwarning
;
824 this->LastTickChar
= '*';
825 errorwarning
.Error
= false;
827 this->TotalWarnings
++;
830 this->LastTickChar
= '!';
831 errorwarning
.Error
= true;
833 this->TotalErrors
++;
838 // This is an error or warning, so generate report
839 errorwarning
.LogLine
= static_cast<int>(this->OutputLineCounter
+1);
840 errorwarning
.Text
= line
;
841 errorwarning
.PreContext
= "";
842 errorwarning
.PostContext
= "";
844 // Copy pre-context to report
845 std::deque
<cmStdString
>::iterator pcit
;
846 for ( pcit
= this->PreContext
.begin();
847 pcit
!= this->PreContext
.end();
850 errorwarning
.PreContext
+= *pcit
+ "\n";
852 this->PreContext
.clear();
855 this->ErrorsAndWarnings
.push_back(errorwarning
);
856 this->LastErrorOrWarning
= this->ErrorsAndWarnings
.end()-1;
857 this->PostContextCount
= 0;
861 // This is not an error or warning.
862 // So, figure out if this is a post-context line
863 if ( this->ErrorsAndWarnings
.size() &&
864 this->LastErrorOrWarning
!= this->ErrorsAndWarnings
.end() &&
865 this->PostContextCount
< this->MaxPostContext
)
867 this->PostContextCount
++;
868 this->LastErrorOrWarning
->PostContext
+= line
;
869 if ( this->PostContextCount
< this->MaxPostContext
)
871 this->LastErrorOrWarning
->PostContext
+= "\n";
876 // Otherwise store pre-context for the next error
877 this->PreContext
.push_back(line
);
878 if ( this->PreContext
.size() > this->MaxPreContext
)
880 this->PreContext
.erase(this->PreContext
.begin(),
881 this->PreContext
.end()-this->MaxPreContext
);
885 this->OutputLineCounter
++;
893 // Now that the buffer is processed, display missing ticks
894 int tickDisplayed
= false;
895 while ( this->BuildOutputLogSize
> (tick
* tick_len
) )
898 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, this->LastTickChar
);
899 tickDisplayed
= true;
900 if ( tick
% tick_line_len
== 0 && tick
> 0 )
902 cmCTestLog(this->CTest
, HANDLER_OUTPUT
, " Size: "
903 << int((this->BuildOutputLogSize
/ 1024.0) + 1) << "K" << std::endl
909 this->LastTickChar
= '.';
912 // And if this is verbose output, display the content of the chunk
913 cmCTestLog(this->CTest
, HANDLER_VERBOSE_OUTPUT
,
914 cmCTestLogWrite(data
, length
));
916 // Always store the chunk to the file
917 ofs
<< cmCTestLogWrite(data
, length
);
920 //----------------------------------------------------------------------
921 int cmCTestBuildHandler::ProcessSingleLine(const char* data
)
923 cmCTestLog(this->CTest
, DEBUG
, "Line: [" << data
<< "]" << std::endl
);
925 std::vector
<cmsys::RegularExpression
>::iterator it
;
930 // Check for regular expressions
932 if ( !this->ErrorQuotaReached
)
936 for ( it
= this->ErrorMatchRegex
.begin();
937 it
!= this->ErrorMatchRegex
.end();
940 if ( it
->find(data
) )
943 cmCTestLog(this->CTest
, DEBUG
, " Error Line: " << data
944 << " (matches: " << this->CustomErrorMatches
[wrxCnt
] << ")"
952 for ( it
= this->ErrorExceptionRegex
.begin();
953 it
!= this->ErrorExceptionRegex
.end();
956 if ( it
->find(data
) )
959 cmCTestLog(this->CTest
, DEBUG
, " Not an error Line: " << data
960 << " (matches: " << this->CustomErrorExceptions
[wrxCnt
] << ")"
967 if ( !this->WarningQuotaReached
)
971 for ( it
= this->WarningMatchRegex
.begin();
972 it
!= this->WarningMatchRegex
.end();
975 if ( it
->find(data
) )
978 cmCTestLog(this->CTest
, DEBUG
,
979 " Warning Line: " << data
980 << " (matches: " << this->CustomWarningMatches
[wrxCnt
] << ")"
988 // Warning exceptions
989 for ( it
= this->WarningExceptionRegex
.begin();
990 it
!= this->WarningExceptionRegex
.end();
993 if ( it
->find(data
) )
996 cmCTestLog(this->CTest
, DEBUG
, " Not a warning Line: " << data
997 << " (matches: " << this->CustomWarningExceptions
[wrxCnt
] << ")"
1006 return b_ERROR_LINE
;
1010 return b_WARNING_LINE
;
1012 return b_REGULAR_LINE
;