1
/*=========================================================================
3
Program: CMake - Cross-Platform Makefile Generator
4
Module: $RCSfile: cmCTestBuildHandler.cxx,v $
6
Date: $Date: 2009-01-13 18:03:54 $
7
Version: $Revision: 1.61.2.2 $
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
=========================================================================*/
1
/*============================================================================
2
CMake - Cross Platform Makefile Generator
3
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5
Distributed under the OSI-approved BSD License (the "License");
6
see accompanying file Copyright.txt for details.
8
This software is distributed WITHOUT ANY WARRANTY; without even the
9
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
See the License for more information.
11
============================================================================*/
18
13
#include "cmCTestBuildHandler.h"
245
248
this->CTest->PopulateCustomInteger(mf,
246
249
"CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
247
250
this->MaxWarnings);
252
// Record the user-specified custom warning rules.
253
if(const char* customWarningMatchers =
254
mf->GetDefinition("CTEST_CUSTOM_WARNING_MATCH"))
256
cmSystemTools::ExpandListArgument(customWarningMatchers,
257
this->ReallyCustomWarningMatches);
259
if(const char* customWarningExceptions =
260
mf->GetDefinition("CTEST_CUSTOM_WARNING_EXCEPTION"))
262
cmSystemTools::ExpandListArgument(customWarningExceptions,
263
this->ReallyCustomWarningExceptions);
250
267
//----------------------------------------------------------------------
476
// Generate XML output
477
cmGeneratedFileStream xofs;
478
if(!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs))
480
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
484
this->GenerateXMLHeader(xofs);
485
if(this->UseCTestLaunch)
487
this->GenerateXMLLaunched(xofs);
491
this->GenerateXMLLogScraped(xofs);
493
this->GenerateXMLFooter(xofs, elapsed_build_time);
495
if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0)
497
cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project"
460
501
// Display message about number of errors and warnings
461
502
cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalErrors
462
503
<< (this->TotalErrors >= this->MaxErrors ? " or more" : "")
465
506
<< (this->TotalWarnings >= this->MaxWarnings ? " or more" : "")
466
507
<< " Compiler warnings" << std::endl);
468
// Generate XML output
469
cmGeneratedFileStream xofs;
470
if( !this->StartResultingXML("Build", xofs))
472
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
476
this->GenerateDartBuildOutput(
477
xofs, this->ErrorsAndWarnings, elapsed_build_time);
481
//----------------------------------------------------------------------
482
void cmCTestBuildHandler::GenerateDartBuildOutput(
484
std::vector<cmCTestBuildErrorWarning> ew,
485
double elapsed_build_time)
512
//----------------------------------------------------------------------------
513
void cmCTestBuildHandler::GenerateXMLHeader(std::ostream& os)
487
this->CTest->StartXML(os);
515
this->CTest->StartXML(os, this->AppendXML);
488
516
os << "<Build>\n"
489
517
<< "\t<StartDateTime>" << this->StartBuild << "</StartDateTime>\n"
490
518
<< "\t<StartBuildTime>" <<
491
519
static_cast<unsigned int>(this->StartBuildTime)
492
520
<< "</StartBuildTime>\n"
493
521
<< "<BuildCommand>"
494
<< this->CTest->MakeXMLSafe(
495
523
this->CTest->GetCTestConfiguration("MakeCommand"))
496
524
<< "</BuildCommand>" << std::endl;
527
//----------------------------------------------------------------------------
528
class cmCTestBuildHandler::FragmentCompare
531
FragmentCompare(cmFileTimeComparison* ftc): FTC(ftc) {}
532
bool operator()(std::string const& l, std::string const& r)
534
// Order files by modification time. Use lexicographic order
535
// among files with the same time.
537
if(this->FTC->FileTimeCompare(l.c_str(), r.c_str(), &result) &&
548
cmFileTimeComparison* FTC;
551
//----------------------------------------------------------------------------
552
void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os)
554
if(this->CTestLaunchDir.empty())
559
// Sort XML fragments in chronological order.
560
cmFileTimeComparison ftc;
561
FragmentCompare fragmentCompare(&ftc);
562
typedef std::set<cmStdString, FragmentCompare> Fragments;
563
Fragments fragments(fragmentCompare);
565
// Identify fragments on disk.
566
cmsys::Directory launchDir;
567
launchDir.Load(this->CTestLaunchDir.c_str());
568
unsigned long n = launchDir.GetNumberOfFiles();
569
for(unsigned long i=0; i < n; ++i)
571
const char* fname = launchDir.GetFile(i);
572
if(this->IsLaunchedErrorFile(fname))
574
fragments.insert(this->CTestLaunchDir + "/" + fname);
577
else if(this->IsLaunchedWarningFile(fname))
579
fragments.insert(this->CTestLaunchDir + "/" + fname);
580
++this->TotalWarnings;
584
// Copy the fragments into the final XML file.
585
for(Fragments::const_iterator fi = fragments.begin();
586
fi != fragments.end(); ++fi)
588
this->GenerateXMLLaunchedFragment(os, fi->c_str());
592
//----------------------------------------------------------------------------
593
void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
595
std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
498
596
std::vector<cmCTestBuildErrorWarning>::iterator it;
500
598
// only report the first 50 warnings and first 50 errors
501
unsigned short numErrorsAllowed = this->MaxErrors;
502
unsigned short numWarningsAllowed = this->MaxWarnings;
599
int numErrorsAllowed = this->MaxErrors;
600
int numWarningsAllowed = this->MaxWarnings;
503
601
std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
504
602
// make sure the source dir is in the correct case on windows
505
603
// via a call to collapse full path.
601
705
this->CTest->EndXML(os);
604
//######################################################################
605
//######################################################################
606
//######################################################################
607
//######################################################################
708
//----------------------------------------------------------------------------
709
void cmCTestBuildHandler::GenerateXMLLaunchedFragment(std::ostream& os,
712
std::ifstream fin(fname, std::ios::in | std::ios::binary);
714
while(cmSystemTools::GetLineFromStream(fin, line))
720
//----------------------------------------------------------------------------
721
bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname)
724
return (strncmp(fname, "error-", 6) == 0 &&
725
strcmp(fname+strlen(fname)-4, ".xml") == 0);
728
//----------------------------------------------------------------------------
729
bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname)
731
// warning-{hash}.xml
732
return (strncmp(fname, "warning-", 8) == 0 &&
733
strcmp(fname+strlen(fname)-4, ".xml") == 0);
736
//######################################################################
737
//######################################################################
738
//######################################################################
739
//######################################################################
741
//----------------------------------------------------------------------------
742
class cmCTestBuildHandler::LaunchHelper
745
LaunchHelper(cmCTestBuildHandler* handler);
748
cmCTestBuildHandler* Handler;
751
void WriteLauncherConfig();
752
void WriteScrapeMatchers(const char* purpose,
753
std::vector<std::string> const& matchers);
756
//----------------------------------------------------------------------------
757
cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler):
758
Handler(handler), CTest(handler->CTest)
760
std::string tag = this->CTest->GetCurrentTag();
763
// This is not for a dashboard submission, so there is no XML.
764
// Skip enabling the launchers.
765
this->Handler->UseCTestLaunch = false;
769
// Compute a directory in which to store launcher fragments.
770
std::string& launchDir = this->Handler->CTestLaunchDir;
771
launchDir = this->CTest->GetBinaryDir();
772
launchDir += "/Testing/";
774
launchDir += "/Build";
776
// Clean out any existing launcher fragments.
777
cmSystemTools::RemoveADirectory(launchDir.c_str());
779
if(this->Handler->UseCTestLaunch)
781
// Enable launcher fragments.
782
cmSystemTools::MakeDirectory(launchDir.c_str());
783
this->WriteLauncherConfig();
784
std::string launchEnv = "CTEST_LAUNCH_LOGS=";
785
launchEnv += launchDir;
786
cmSystemTools::PutEnv(launchEnv.c_str());
790
// If not using launchers, make sure they passthru.
791
if(!this->Handler->UseCTestLaunch)
793
cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
797
//----------------------------------------------------------------------------
798
cmCTestBuildHandler::LaunchHelper::~LaunchHelper()
800
if(this->Handler->UseCTestLaunch)
802
cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
806
//----------------------------------------------------------------------------
807
void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
809
this->WriteScrapeMatchers("Warning",
810
this->Handler->ReallyCustomWarningMatches);
811
this->WriteScrapeMatchers("WarningSuppress",
812
this->Handler->ReallyCustomWarningExceptions);
814
// Give some testing configuration information to the launcher.
815
std::string fname = this->Handler->CTestLaunchDir;
816
fname += "/CTestLaunchConfig.cmake";
817
cmGeneratedFileStream fout(fname.c_str());
818
std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
819
fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
822
//----------------------------------------------------------------------------
824
cmCTestBuildHandler::LaunchHelper
825
::WriteScrapeMatchers(const char* purpose,
826
std::vector<std::string> const& matchers)
832
std::string fname = this->Handler->CTestLaunchDir;
836
cmGeneratedFileStream fout(fname.c_str());
837
for(std::vector<std::string>::const_iterator mi = matchers.begin();
838
mi != matchers.end(); ++mi)
609
844
//----------------------------------------------------------------------
610
845
int cmCTestBuildHandler::RunMakeCommand(const char* command,