cmCTest.cxx 148 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "cmCTest.h"
Ken Martin's avatar
Ken Martin committed
18
19
20
21
22
#include "cmake.h"
#include "cmMakefile.h"
#include "cmLocalGenerator.h"
#include "cmGlobalGenerator.h"
#include <cmsys/Directory.hxx>
23
#include "cmGlob.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
24
#include "cmDynamicLoader.h"
25

26
27
#include "cmCTestSubmit.h"
#include "curl/curl.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
28

29
30
#include <cmsys/RegularExpression.hxx>
#include <cmsys/Process.h>
31
#include <cmsys/Base64.h>
32

33
#include <stdlib.h> 
34
#include <time.h>
35
#include <math.h>
Andy Cedilnik's avatar
Andy Cedilnik committed
36
#include <float.h>
Andy Cedilnik's avatar
Andy Cedilnik committed
37

Ken Martin's avatar
Ken Martin committed
38
39
40
41
42
// needed for sleep
#if !defined(_WIN32)
# include <unistd.h>
#endif

Andy Cedilnik's avatar
Andy Cedilnik committed
43
#include <memory> // auto_ptr
44

45
#define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
46
47
#define DEBUGOUT std::cout << __LINE__ << " "; std::cout
#define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
48

49
50
51
52
53
54
55
// provide some more detailed info on the return code for ctest
#define CTEST_UPDATE_ERRORS 0x01
#define CTEST_CONFIGURE_ERRORS 0x02
#define CTEST_BUILD_ERRORS 0x04
#define CTEST_TEST_ERRORS 0x08
#define CTEST_MEMORY_ERRORS 0x10

56
static struct tm* GetNightlyTime(std::string str, bool tomorrowtag)
Andy Cedilnik's avatar
Andy Cedilnik committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
  struct tm* lctime;
  time_t tctime = time(0);
  //Convert the nightly start time to seconds. Since we are
  //providing only a time and a timezone, the current date of
  //the local machine is assumed. Consequently, nightlySeconds
  //is the time at which the nightly dashboard was opened or
  //will be opened on the date of the current client machine.
  //As such, this time may be in the past or in the future.
  time_t ntime = curl_getdate(str.c_str(), &tctime);
  tctime = time(0);
  //std::cout << "Seconds: " << tctime << std::endl;
  if ( ntime > tctime )
    {
    // If nightlySeconds is in the past, this is the current
    // open dashboard, then return nightlySeconds.  If
    // nightlySeconds is in the future, this is the next
    // dashboard to be opened, so subtract 24 hours to get the
    // time of the current open dashboard
76
    ntime -= ( 24 * 60 * 60 );
Andy Cedilnik's avatar
Andy Cedilnik committed
77
78
79
    //std::cout << "Pick yesterday" << std::endl;
    }
  //std::cout << "nightlySeconds: " << ntime << std::endl;
80
81
82
83
84
  if ( tomorrowtag )
    {
    std::cout << "Add a day" << std::endl;
    ntime += ( 24 * 60 * 60 );
    }
Andy Cedilnik's avatar
Andy Cedilnik committed
85
86
87
88
  lctime = gmtime(&ntime);
  return lctime;
}

89
static std::string CleanString(const std::string& str)
90
{
91
92
  std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  if ( spos == str.npos )
    {
    return std::string();
    }
  if ( epos != str.npos )
    {
    epos = epos - spos + 1;
    }
  return str.substr(spos, epos);
}

static std::string CurrentTime()
{
  time_t currenttime = time(0);
107
108
109
  struct tm* t = localtime(&currenttime);
  //return ::CleanString(ctime(&currenttime));
  char current_time[1024];
Andy Cedilnik's avatar
Andy Cedilnik committed
110
  strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
111
112
  //std::cout << "Current_Time: " << current_time << std::endl;
  return ::CleanString(current_time);
113
114
115
116
117
118
119
120
121
}

static const char* cmCTestErrorMatches[] = {
  "^[Bb]us [Ee]rror",
  "^[Ss]egmentation [Vv]iolation",
  "^[Ss]egmentation [Ff]ault",
  "([^ :]+):([0-9]+): ([^ \\t])",
  "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  "^Error ([0-9]+):",
Andy Cedilnik's avatar
Andy Cedilnik committed
122
123
  "^Fatal",
  "^Error: ",
124
  "^Error ",
Andy Cedilnik's avatar
Andy Cedilnik committed
125
  "[0-9] ERROR: ",
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  "^\"[^\"]+\", line [0-9]+: [^Ww]",
  "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  "^ild:([ \\t])*\\(undefined symbol\\)",
  "([^ :]+) : (error|fatal error|catastrophic error)",
  "([^:]+): (Error:|error|undefined reference|multiply defined)",
  "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  "^fatal error C[0-9]+:",
  ": syntax error ",
  "^collect2: ld returned 1 exit status",
  "Unsatisfied symbols:",
  "Undefined symbols:",
  "^Undefined[ \\t]+first referenced",
  "^CMake Error:",
  ":[ \\t]cannot find",
Andy Cedilnik's avatar
Andy Cedilnik committed
141
142
143
144
145
  ":[ \\t]can't find",
  ": \\*\\*\\* No rule to make target \\`.*\\'.  Stop",
  ": Invalid loader fixup for symbol",
  ": internal link edit command failed",
  ": Unrecognized option \\`.*\\'",
146
  "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
147
  "ld: 0706-006 Cannot find or open library file: -l ",
148
149
  "ild: \\(argument error\\) can't find library argument ::",
  "^could not be found and will not be loaded.",
150
151
152
153
  0
};

static const char* cmCTestErrorExceptions[] = {
Andy Cedilnik's avatar
Andy Cedilnik committed
154
155
156
157
158
159
  "instantiated from ",
  "candidates are:",
  ": warning",
  "makefile:",
  "Makefile:",
  ":[ \\t]+Where:",
160
161
162
163
164
165
166
167
168
169
170
171
  0
};

static const char* cmCTestWarningMatches[] = {
  "([^ :]+):([0-9]+): warning:",
  "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  "([^:]+): warning ([0-9]+):",
  "^\"[^\"]+\", line [0-9]+: [Ww]arning",
  "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  "^Warning ([0-9]+):",
  "^Warning ",
Andy Cedilnik's avatar
Andy Cedilnik committed
172
  "WARNING: ",
173
174
  "([^ :]+) : warning",
  "([^:]+): warning",
Andy Cedilnik's avatar
Andy Cedilnik committed
175
  "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  0
};

static const char* cmCTestWarningExceptions[] = {
  "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  "WARNING 84 :",
  "WARNING 47 :",
  "makefile:",
  "Makefile:",
  "warning:  Clock skew detected.  Your build may be incomplete.",
  "/usr/openwin/include/GL/[^:]+:",
  "bind_at_load",
  "XrmQGetResource",
  "IceFlush",
Andy Cedilnik's avatar
Andy Cedilnik committed
192
  "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
193
  "ld32: WARNING 85: definition of dataKey in",
194
  "cc: warning 422: Unknown option \"\\+b",
195
  "_with_warning_C",
196
197
198
  0
};

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
static const char* cmCTestMemCheckResultStrings[] = {
  "ABR",
  "ABW",
  "ABWL",
  "COR",
  "EXU",
  "FFM",
  "FIM",
  "FMM",
  "FMR",
  "FMW",
  "FUM",
  "IPR",
  "IPW",
  "MAF",
  "MLK",
  "MPK",
  "NPR",
  "ODS",
  "PAR",
  "PLK",
  "UMC",
  "UMR",
  0
};

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
static const char* cmCTestMemCheckResultLongStrings[] = {
  "ABR",
  "ABW",
  "ABWL",
  "COR",
  "EXU",
  "FFM",
  "FIM",
  "Mismatched deallocation",
  "FMR",
  "FMW",
  "FUM",
  "IPR",
  "IPW",
  "MAF",
  "Memory Leak",
  "Potential Memory Leak",
  "NPR",
  "ODS",
  "Invalid syscall param",
  "PLK",
  "Uninitialized Memory Conditional",
  "Uninitialized Memory Read",
  0
};

251
252
253
std::string cmCTest::MakeXMLSafe(const std::string& str)
{
  cmOStringStream ost;
254
255
  // By uncommenting the lcnt code, it will put newline every 120 characters
  //int lcnt = 0;
Bill Hoffman's avatar
Bill Hoffman committed
256
  for (std::string::size_type  pos = 0; pos < str.size(); pos ++ )
257
    {
258
    unsigned char ch = str[pos];
259
    if ( (ch > 126 || ch < 32) && ch != 9  && ch != 10 && ch != 13 )
260
      {
261
      char buffer[33];
262
      sprintf(buffer, "&lt;%d&gt;", (int)ch);
263
      //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
264
      ost << buffer;
265
      //lcnt += 4;
266
267
268
269
270
271
272
273
      }
    else
      {
      switch ( ch )
        {
        case '&': ost << "&amp;"; break;
        case '<': ost << "&lt;"; break;
        case '>': ost << "&gt;"; break;
274
275
276
        case '\n': ost << "\n"; 
          //lcnt = 0; 
          break;
277
278
        default: ost << ch;
        }
279
      //lcnt ++;
280
      }
281
282
283
284
285
    //if ( lcnt > 120 )
    //  {
    //  ost << "\n";
    //  lcnt = 0;
    //  }
286
287
288
289
    }
  return ost.str();
}

Andy Cedilnik's avatar
Andy Cedilnik committed
290
291
292
293
std::string cmCTest::MakeURLSafe(const std::string& str)
{
  cmOStringStream ost;
  char buffer[10];
294
  for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
Andy Cedilnik's avatar
Andy Cedilnik committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    {
    unsigned char ch = str[pos];
    if ( ( ch > 126 || ch < 32 ||
           ch == '&' ||
           ch == '%' ||
           ch == '+' ||
           ch == '=' || 
           ch == '@'
          ) && ch != 9 )
      {
      sprintf(buffer, "%02x;", (unsigned int)ch);
      ost << buffer;
      }
    else
      {
      ost << ch;
      }
    }
  return ost.str();
}

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
bool TryExecutable(const char *dir, const char *file,
                   std::string *fullPath, const char *subdir)
{
  // try current directory
  std::string tryPath;
  if (dir && strcmp(dir,""))
    {
    tryPath = dir;
    tryPath += "/";
    }
  
  if (subdir && strcmp(subdir,""))
    {
    tryPath += subdir;
    tryPath += "/";
    }
  
  tryPath += file;
  if(cmSystemTools::FileExists(tryPath.c_str()))
    {
    *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
    return true;
    }
  tryPath += cmSystemTools::GetExecutableExtension();
  if(cmSystemTools::FileExists(tryPath.c_str()))
    {
    *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
    return true;
    }
  return false;
}

cmCTest::cmCTest() 
{ 
350
  m_TomorrowTag            = false;
Bill Hoffman's avatar
Bill Hoffman committed
351
  m_BuildNoCMake           = false;
Bill Hoffman's avatar
Bill Hoffman committed
352
  m_BuildNoClean           = false;
353
  m_BuildTwoConfig         = false;
Ken Martin's avatar
Ken Martin committed
354
355
356
357
358
359
360
361
362
  m_UseIncludeRegExp       = false;
  m_UseExcludeRegExp       = false;
  m_UseExcludeRegExpFirst  = false;
  m_Verbose                = false;
  m_DartMode               = false;
  m_ShowOnly               = false;
  m_RunConfigurationScript = false;
  m_TestModel              = cmCTest::EXPERIMENTAL;
  m_TimeOut                = 0;
363
  m_CompatibilityMode      = 0;
364
365
366
367
368
369
370
  int cc; 
  for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
    {
    m_Tests[cc] = 0;
    }
}

371
int cmCTest::Initialize()
372
373
{
  m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
374
  cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
375
376
377
378
  if ( !this->ReadCustomConfigurationFileTree(m_ToplevelPath.c_str()) )
    {
    return 0;
    }
379
  this->UpdateCTestConfiguration();
380
381
  if ( m_DartMode )
    {
382
    std::string testingDir = m_ToplevelPath + "/Testing";
383
384
385
386
387
388
    if ( cmSystemTools::FileExists(testingDir.c_str()) )
      {
      if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
        {
        std::cerr << "File " << testingDir << " is in the place of the testing directory"
                  << std::endl;
389
        return 0;
390
391
392
393
394
395
396
397
        }
      }
    else
      {
      if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
        {
        std::cerr << "Cannot create directory " << testingDir
                  << std::endl;
398
        return 0;
399
400
401
402
403
404
        }
      }
    std::string tagfile = testingDir + "/TAG";
    std::ifstream tfin(tagfile.c_str());
    std::string tag;
    time_t tctime = time(0);
405
406
407
408
    if ( m_TomorrowTag )
      {
      tctime += ( 24 * 60 * 60 );
      }
409
    struct tm *lctime = gmtime(&tctime);
410
    if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
411
412
413
414
415
416
417
418
419
      {
      int year = 0;
      int mon = 0;
      int day = 0;
      int hour = 0;
      int min = 0;
      sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
             &year, &mon, &day, &hour, &min);
      if ( year != lctime->tm_year + 1900 ||
Andy Cedilnik's avatar
Andy Cedilnik committed
420
           mon != lctime->tm_mon+1 ||
421
422
423
424
           day != lctime->tm_mday )
        {
        tag = "";
        }
425
426
427
428
429
430
431
432
433
      std::string tagmode;
      if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
        {
        if ( tagmode.size() > 4 && !( m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST] ))
          {
          m_TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
          }
        }
      tfin.close();
434
      }
Andy Cedilnik's avatar
Andy Cedilnik committed
435
    if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
436
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
437
438
      //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
      //std::cout << "TestModel: " << m_TestModel << std::endl;
439
440
      if ( m_TestModel == cmCTest::NIGHTLY )
        {
441
442
        lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"],
          m_TomorrowTag);
443
        }
444
445
446
      char datestring[100];
      sprintf(datestring, "%04d%02d%02d-%02d%02d",
              lctime->tm_year + 1900,
Andy Cedilnik's avatar
Andy Cedilnik committed
447
              lctime->tm_mon+1,
448
449
450
451
452
453
454
455
              lctime->tm_mday,
              lctime->tm_hour,
              lctime->tm_min);
      tag = datestring;
      std::ofstream ofs(tagfile.c_str());
      if ( ofs )
        {
        ofs << tag << std::endl;
456
        ofs << this->GetTestModelString() << std::endl;
457
458
        }
      ofs.close();
459
460
      std::cout << "Create new tag: " << tag << " - " 
        << this->GetTestModelString() << std::endl;
461
462
463
      }
    m_CurrentTag = tag;
    }
464
  return 1;
465
466
}

467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
void cmCTest::UpdateCTestConfiguration()
{
  // parse the dart test file
  std::ifstream fin("DartConfiguration.tcl");
  if(!fin)
    {
    return;
    }

  char buffer[1024];
  while ( fin )
    {
    buffer[0] = 0;
    fin.getline(buffer, 1023);
    buffer[1023] = 0;
    std::string line = ::CleanString(buffer);
    if(line.size() == 0)
      {
      continue;
      }
    while ( fin && (line[line.size()-1] == '\\') )
      {
      line = line.substr(0, line.size()-1);
      buffer[0] = 0;
      fin.getline(buffer, 1023);
      buffer[1023] = 0;
      line += ::CleanString(buffer);
      }
    if ( line[0] == '#' )
      {
      continue;
      }
    std::string::size_type cpos = line.find_first_of(":");
    if ( cpos == line.npos )
      {
      continue;
      }
    std::string key = line.substr(0, cpos);
    std::string value = ::CleanString(line.substr(cpos+1, line.npos));
    m_DartConfiguration[key] = value;
    }
  fin.close();
  if ( m_DartMode )
    {
    m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
    }
}

515
516
517
518
519
520
bool cmCTest::SetTest(const char* ttype)
{
  if ( cmSystemTools::LowerCase(ttype) == "all" )
    {
    m_Tests[cmCTest::ALL_TEST] = 1;
    }
Andy Cedilnik's avatar
Andy Cedilnik committed
521
522
523
524
  else if ( cmSystemTools::LowerCase(ttype) == "start" )
    {
    m_Tests[cmCTest::START_TEST] = 1;
    }
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  else if ( cmSystemTools::LowerCase(ttype) == "update" )
    {
    m_Tests[cmCTest::UPDATE_TEST] = 1;
    }
  else if ( cmSystemTools::LowerCase(ttype) == "configure" )
    {
    m_Tests[cmCTest::CONFIGURE_TEST] = 1;
    }
  else if ( cmSystemTools::LowerCase(ttype) == "build" )
    {
    m_Tests[cmCTest::BUILD_TEST] = 1;
    }
  else if ( cmSystemTools::LowerCase(ttype) == "test" )
    {
    m_Tests[cmCTest::TEST_TEST] = 1;
    }
  else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
    {
    m_Tests[cmCTest::COVERAGE_TEST] = 1;
    }
545
  else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
546
    {
547
    m_Tests[cmCTest::MEMCHECK_TEST] = 1;
548
    }
549
550
551
552
  else if ( cmSystemTools::LowerCase(ttype) == "notes" )
    {
    m_Tests[cmCTest::NOTES_TEST] = 1;
    }
Andy Cedilnik's avatar
Andy Cedilnik committed
553
554
555
556
  else if ( cmSystemTools::LowerCase(ttype) == "submit" )
    {
    m_Tests[cmCTest::SUBMIT_TEST] = 1;
    }
557
558
559
560
561
562
563
564
565
566
567
568
  else
    {
    std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
    return false;
    }
  return true;
}

void cmCTest::Finalize()
{
}

Andy Cedilnik's avatar
Andy Cedilnik committed
569
std::string cmCTest::FindTheExecutable(const char *exe)
570
571
572
573
574
575
{
  std::string fullPath = "";
  std::string dir;
  std::string file;

  cmSystemTools::SplitProgramPath(exe, dir, file);
576
577
578
  if(m_ConfigType != "" && 
    ::TryExecutable(dir.c_str(), file.c_str(), &fullPath, 
      m_ConfigType.c_str()))
579
580
581
582
    {
    return fullPath;
    }

583
  if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
584
585
586
587
    {
    return fullPath;
    }

588
  if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
589
590
591
592
    {
    return fullPath;
    }

593
  if ( m_ConfigType == "" )
594
    {
595
596
597
598
599
    // No config type, so try to guess it
    if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
      {
      return fullPath;
      }
600

601
602
603
604
    if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
      {
      return fullPath;
      }
605

606
607
608
609
610
611
612
613
614
    if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
      {
      return fullPath;
      }

    if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
      {
      return fullPath;
      }
615
616
617
618
619
620
621
622
623
624
625
    }

  // if everything else failed, check the users path
  if (dir != "")
    {
    std::string path = cmSystemTools::FindProgram(file.c_str());
    if (path != "")
      {
      return path;
      }
    }
626
627
628
629
630
631
632
633
634
635
636

  if ( m_ConfigType != "" )
    {
    dir += "/";
    dir += m_ConfigType;
    dir += "/";
    dir += file;
    cmSystemTools::Error("config type specified on the command line, but test executable not found.",
      dir.c_str());
    return "";
    }
637
638
639
640
641
  return fullPath;
}

int cmCTest::UpdateDirectory()
{
Andy Cedilnik's avatar
Andy Cedilnik committed
642
  int count = 0;
Andy Cedilnik's avatar
Andy Cedilnik committed
643
  std::string::size_type cc, kk;
644
645
646
647
  std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  if ( cvsCommand.size() == 0 )
    {
    std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
648
    return -1;
649
650
651
652
653
    }
  std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  if ( cvsOptions.size() == 0 )
    {
    std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
654
    return -1;
655
656
657
658
659
660
    }

  std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  if ( sourceDirectory.size() == 0 )
    {
    std::cerr << "Cannot find SourceDirectory  key in the DartConfiguration.tcl" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
661
    return -1;
662
663
    }

664
665
666
  std::string extra_update_opts;
  if ( m_TestModel == cmCTest::NIGHTLY )
    {
667
668
    struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"],
      m_TomorrowTag);
669
    char current_time[1024];
670
671
672
673
674
675
676
    sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
      t->tm_year + 1900,
      t->tm_mon + 1,
      t->tm_mday,
      t->tm_hour,
      t->tm_min,
      t->tm_sec);
Andy Cedilnik's avatar
Andy Cedilnik committed
677
    std::string today_update_date = current_time;
678
679
   
    extra_update_opts += "-D \"" + today_update_date +"\"";
Andy Cedilnik's avatar
Andy Cedilnik committed
680
    //std::cout << "Update: " << extra_update_opts << std::endl;
681
    }
Andy Cedilnik's avatar
Andy Cedilnik committed
682

683
684
  std::string command = cvsCommand + " -z3 update " + cvsOptions +
    " " + extra_update_opts;
Andy Cedilnik's avatar
Andy Cedilnik committed
685
  std::ofstream os; 
686
  if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
Andy Cedilnik's avatar
Andy Cedilnik committed
687
    {
688
    std::cerr << "Cannot open log file" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
689
690
691
    }
  std::string start_time = ::CurrentTime();
 
692

693
  std::string goutput;
694
695
  int retVal = 0;
  bool res = true;
Andy Cedilnik's avatar
Andy Cedilnik committed
696
  std::ofstream ofs;
697
698
  if ( !m_ShowOnly )
    {
Andy Cedilnik's avatar
Andy Cedilnik committed
699
700
    res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput, 
      &retVal, sourceDirectory.c_str(),
701
      m_Verbose, 0 /*m_TimeOut*/);
Andy Cedilnik's avatar
Andy Cedilnik committed
702
703
    if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
704
      ofs << goutput << std::endl;; 
Andy Cedilnik's avatar
Andy Cedilnik committed
705
      }
706
707
708
709
710
    }
  else
    {
    std::cout << "Update with command: " << command << std::endl;
    }
Andy Cedilnik's avatar
Andy Cedilnik committed
711
712

  os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
713
     << "<Update mode=\"Client\" Generator=\"ctest\">\n"
Andy Cedilnik's avatar
Andy Cedilnik committed
714
715
716
     << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
     << "\t<BuildName>" << m_DartConfiguration["BuildName"]
     << "</BuildName>\n"
717
     << "\t<BuildStamp>" << m_CurrentTag << "-"
718
719
     << this->GetTestModelString() << "</BuildStamp>" << std::endl;
  os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
Andy Cedilnik's avatar
Andy Cedilnik committed
720
     << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
Andy Cedilnik's avatar
Andy Cedilnik committed
721
     << "\t<UpdateReturnStatus>";
722
723
  int failed = 0;
  if ( !res || retVal )
Andy Cedilnik's avatar
Andy Cedilnik committed
724
    {
725
    os << "Update error: ";
Andy Cedilnik's avatar
Andy Cedilnik committed
726
    os << goutput;
727
728
    std::cerr << "Update with command: " << command << " failed" << std::endl;
    failed = 1;
Andy Cedilnik's avatar
Andy Cedilnik committed
729
730
    }
  os << "</UpdateReturnStatus>" << std::endl;
731
732
  if ( !failed )
    {
Andy Cedilnik's avatar
Andy Cedilnik committed
733

734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
    std::vector<cmStdString> lines;
    cmSystemTools::Split(goutput.c_str(), lines);
    std::cout << "Updated; gathering version information" << std::endl;
    cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
    cmsys::RegularExpression revision("^revision +([^ ]*) *$");
    cmsys::RegularExpression end_of_file("^=============================================================================$");
    cmsys::RegularExpression end_of_comment("^----------------------------$");
    std::string current_path = "";
    bool first_file = true;

    cmCTest::AuthorsToUpdatesMap authors_files_map;
    int num_updated = 0;
    int num_modified = 0;
    int num_conflicting = 0;
    for ( cc= 0 ; cc < lines.size(); cc ++ )
      {
      const char* line = lines[cc].c_str();
      char mod = line[0];
      if ( line[1] == ' ' && mod != '?' )
        {
        count ++;
        const char* file = line + 2;
        //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
        std::string logcommand = cvsCommand + " -z3 log -N " + file;
        //std::cout << "Do log: " << logcommand << std::endl;
        std::string output;
        res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output, 
          &retVal, sourceDirectory.c_str(),
          m_Verbose, 0 /*m_TimeOut*/);
        if ( ofs )
Andy Cedilnik's avatar
Andy Cedilnik committed
764
          {
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
          ofs << output << std::endl;
          }
        if ( res && retVal == 0)
          {
          //std::cout << output << std::endl;
          std::vector<cmStdString> ulines;
          cmSystemTools::Split(output.c_str(), ulines);
          std::string::size_type sline = 0;
          std::string srevision1 = "Unknown";
          std::string sdate1     = "Unknown";
          std::string sauthor1   = "Unknown";
          std::string semail1    = "Unknown";
          std::string comment1   = "";
          std::string srevision2 = "Unknown";
          std::string sdate2     = "Unknown";
          std::string sauthor2   = "Unknown";
          std::string comment2   = "";
          std::string semail2    = "Unknown";
          bool have_first = false;
          bool have_second = false;
          for ( kk = 0; kk < ulines.size(); kk ++ )
Andy Cedilnik's avatar
Andy Cedilnik committed
786
            {
787
788
            const char* clp = ulines[kk].c_str();
            if ( !have_second && !sline && revision.find(clp) )
Andy Cedilnik's avatar
Andy Cedilnik committed
789
              {
790
791
792
793
794
795
796
797
              if ( !have_first )
                {
                srevision1 = revision.match(1);
                }
              else
                {
                srevision2 = revision.match(1);
                }
Andy Cedilnik's avatar
Andy Cedilnik committed
798
              }
799
            else if ( !have_second && !sline && date_author.find(clp) )
Andy Cedilnik's avatar
Andy Cedilnik committed
800
              {
801
802
803
804
805
806
807
808
809
810
811
              sline = kk + 1;
              if ( !have_first )
                {
                sdate1 = date_author.match(1);
                sauthor1 = date_author.match(2);
                }
              else
                {
                sdate2 = date_author.match(1);
                sauthor2 = date_author.match(2);
                }
Andy Cedilnik's avatar
Andy Cedilnik committed
812
              }
813
            else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
Andy Cedilnik's avatar
Andy Cedilnik committed
814
              {
815
816
817
818
819
820
821
822
823
              if ( !have_first )
                {
                have_first = true;
                }
              else if ( !have_second )
                {
                have_second = true;
                }
              sline = 0;
Andy Cedilnik's avatar
Andy Cedilnik committed
824
              }
825
            else if ( sline )
Andy Cedilnik's avatar
Andy Cedilnik committed
826
              {
827
828
829
830
831
832
833
834
835
836
              if ( !have_first )
                {
                comment1 += clp;
                comment1 += "\n";
                }
              else
                {
                comment2 += clp;
                comment2 += "\n";
                }
Andy Cedilnik's avatar
Andy Cedilnik committed
837
838
              }
            }
839
          if ( mod == 'M' )
Andy Cedilnik's avatar
Andy Cedilnik committed
840
            {
841
            comment1 = "Locally modified file\n";
Andy Cedilnik's avatar
Andy Cedilnik committed
842
            }
843
          if ( mod == 'C' )
Andy Cedilnik's avatar
Andy Cedilnik committed
844
            {
845
846
847
848
849
850
851
            comment1 = "Conflict while updating\n";
            }
          std::string path = cmSystemTools::GetFilenamePath(file);
          std::string fname = cmSystemTools::GetFilenameName(file);
          if ( path != current_path )
            {
            if ( !first_file )
Andy Cedilnik's avatar
Andy Cedilnik committed
852
              {
853
              os << "\t</Directory>" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
854
855
856
              }
            else
              {
857
              first_file = false;
Andy Cedilnik's avatar
Andy Cedilnik committed
858
              }
859
860
            os << "\t<Directory>\n"
              << "\t\t<Name>" << path << "</Name>" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
861
            }
862
863
864
865
866
867
          if ( mod == 'C' )
            {
            num_conflicting ++;
            os << "\t<Conflicting>" << std::endl;
            }
          else if ( mod == 'M' )
Andy Cedilnik's avatar
Andy Cedilnik committed
868
            {
869
870
            num_modified ++;
            os << "\t<Modified>" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
871
872
873
            }
          else
            {
874
875
            num_updated ++;
            os << "\t<Updated>" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
876
            }
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
          if ( srevision2 == "Unknown" )
            {
            srevision2 = srevision1;
            }
          os << "\t\t<File Directory=\"" << path << "\">" << fname 
            << "</File>\n"
            << "\t\t<Directory>" << path << "</Directory>\n"
            << "\t\t<FullName>" << file << "</FullName>\n"
            << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
            << "\t\t<Author>" << sauthor1 << "</Author>\n"
            << "\t\t<Email>" << semail1 << "</Email>\n"
            << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
            << "\t\t<Revision>" << srevision1 << "</Revision>\n"
            << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
            << std::endl;
          if ( srevision2 != srevision1 )
            {
            os
              << "\t\t<Revisions>\n"
              << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
              << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
              << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
              << "\t\t\t<Date>" << sdate1 << "</Date>\n"
              << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
              << "\t\t\t<Email>" << semail1 << "</Email>\n"
              << "\t\t</Revisions>\n"
              << "\t\t<Revisions>\n"
              << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
              << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
              << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
              << "\t\t\t<Date>" << sdate2 << "</Date>\n"
              << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
              << "\t\t\t<Email>" << semail2 << "</Email>\n"
              << "\t\t</Revisions>" << std::endl;
            }
          if ( mod == 'C' )
            {
            os << "\t</Conflicting>" << std::endl;
            }
          else if ( mod == 'M' )
            {
            os << "\t</Modified>" << std::endl;
            }
          else
            {
            os << "\t</Updated>" << std::endl;
            }
          cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
          cmCTest::StringPair p;
          p.first = path;
          p.second = fname;
          u->push_back(p);
Andy Cedilnik's avatar
Andy Cedilnik committed
929

930
931
          current_path = path;
          }
Andy Cedilnik's avatar
Andy Cedilnik committed
932
933
        }
      }
934
    if ( num_updated )
Andy Cedilnik's avatar
Andy Cedilnik committed
935
      {
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
      std::cout << "Found " << num_updated << " updated files" << std::endl;
      }
    if ( num_modified )
      {
      std::cout << "Found " << num_modified << " locally modified files" 
        << std::endl;
      }
    if ( num_conflicting )
      {
      std::cout << "Found " << num_conflicting << " conflicting files" 
        << std::endl;
      }
    if ( !first_file )
      {
      os << "\t</Directory>" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
951
952
      }

953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
    cmCTest::AuthorsToUpdatesMap::iterator it;
    for ( it = authors_files_map.begin();
      it != authors_files_map.end();
      it ++ )
      {
      os << "\t<Author>\n"
        << "\t\t<Name>" << it->first << "</Name>" << std::endl;
      cmCTest::UpdateFiles *u = &(it->second);
      for ( cc = 0; cc < u->size(); cc ++ )
        {
        os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
          << (*u)[cc].second << "</File>" << std::endl;
        }
      os << "\t</Author>" << std::endl;
      }

    //std::cout << "End" << std::endl;
    std::string end_time = ::CurrentTime();
    os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
      << "</Update>" << std::endl;

    if ( ofs )
      {
      ofs.close();
      }
Andy Cedilnik's avatar
Andy Cedilnik committed
978
979
    }

980
981
982
  if (! res || retVal )
    {
    std::cerr << "Error(s) when updating the project" << std::endl;
983
    std::cerr << "Output: " << goutput << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
984
    return -1;
985
    }
Andy Cedilnik's avatar
Andy Cedilnik committed
986
  return count;
987
988
989
990
}

int cmCTest::ConfigureDirectory()
{
991
  std::cout << "Configure project" << std::endl;
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
  std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  if ( cCommand.size() == 0 )
    {
    std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl" 
              << std::endl;
    return 1;
    }

  std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  if ( buildDirectory.size() == 0 )
    {
    std::cerr << "Cannot find BuildDirectory  key in the DartConfiguration.tcl" << std::endl;
    return 1;
    }

  std::string output;
  int retVal = 0;
1009
  int res = 0;
1010
1011
  if ( !m_ShowOnly )
    {
Andy Cedilnik's avatar
Andy Cedilnik committed
1012
    std::ofstream os; 
1013
    if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
Andy Cedilnik's avatar
Andy Cedilnik committed
1014
      {
1015
1016
      std::cerr << "Cannot open configure file" << std::endl;
      return 1;
Andy Cedilnik's avatar
Andy Cedilnik committed
1017
1018
1019
      }
    std::string start_time = ::CurrentTime();

1020
    std::ofstream ofs;
1021
1022
1023
    this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
    res = this->RunMakeCommand(cCommand.c_str(), &output, 
      &retVal, buildDirectory.c_str(),
1024
      m_Verbose, 0, ofs);
1025
1026

    if ( ofs )
1027
1028
1029
      {
      ofs.close();
      }
Andy Cedilnik's avatar
Andy Cedilnik committed
1030
1031
1032
    
    if ( os )
      {
1033
1034
      this->StartXML(os);
      os << "<Configure>\n"
Andy Cedilnik's avatar
Andy Cedilnik committed
1035
         << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
1036
      if ( res == cmsysProcess_State_Exited && retVal )
Andy Cedilnik's avatar
Andy Cedilnik committed
1037
1038
1039
1040
1041
        {
        os << retVal;
        }
      os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
      //std::cout << "End" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
1042
      os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
1043
      std::string end_time = ::CurrentTime();
Andy Cedilnik's avatar
Andy Cedilnik committed
1044
1045
      os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
         << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
1046
1047
         << "</Configure>" << std::endl;
      this->EndXML(os);
Andy Cedilnik's avatar
Andy Cedilnik committed
1048
      }    
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
    }
  else
    {
    std::cout << "Configure with command: " << cCommand << std::endl;
    }
  if (! res || retVal )
    {
    std::cerr << "Error(s) when updating the project" << std::endl;
    return 1;
    }
  return 0;
}

int cmCTest::BuildDirectory()
{
1064
  std::cout << "Build project" << std::endl;
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
  std::string makeCommand = m_DartConfiguration["MakeCommand"];
  if ( makeCommand.size() == 0 )
    {
    std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
    return 1;
    }
  std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  if ( buildDirectory.size() == 0 )
    {
    std::cerr << "Cannot find BuildDirectory  key in the DartConfiguration.tcl" << std::endl;
    return 1;
    }

1078
1079
1080
1081
1082
  std::ofstream ofs;
  if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
    {
    std::cerr << "Cannot create LastBuild.log file" << std::endl;    
    }
1083
1084
1085
  m_StartBuild = ::CurrentTime();
  std::string output;
  int retVal = 0;
1086
  int res = cmsysProcess_State_Exited;
1087
1088
  if ( !m_ShowOnly )
    {
1089
    res = this->RunMakeCommand(makeCommand.c_str(), &output, 
Andy Cedilnik's avatar
Andy Cedilnik committed
1090
      &retVal, buildDirectory.c_str(), 
1091
      m_Verbose, 0, ofs);
1092
1093
1094
1095
1096
1097
    }
  else
    {
    std::cout << "Build with command: " << makeCommand << std::endl;
    }
  m_EndBuild = ::CurrentTime();
1098
  if (res != cmsysProcess_State_Exited || retVal )
1099
1100
1101
    {
    std::cerr << "Error(s) when building project" << std::endl;
    }
1102
1103
1104
1105
  if ( ofs )
    {
    ofs.close();
    }
1106

1107
  tm_VectorOfStrings::size_type cc;
1108
1109
  if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
    m_DartConfiguration["BuildDirectory"].size() > 20 )
1110
    {
1111
1112
1113
1114
1115
    std::string srcdir = m_DartConfiguration["SourceDirectory"] + "/";
    std::string bindir = m_DartConfiguration["BuildDirectory"] + "/";
    std::string srcdirrep;
    std::string bindirrep;
    for ( cc = srcdir.size()-2; cc > 0; cc -- )
1116
      {
1117
1118
1119
1120
1121
1122
1123
      if ( srcdir[cc] == '/' )
        {
        srcdirrep = srcdir.c_str() + cc;
        srcdirrep = "/..." + srcdirrep;
        srcdir = srcdir.substr(0, cc+1);
        break;
        }
1124
      }
1125
    for ( cc = bindir.size()-2; cc > 0; cc -- )
1126
      {
1127
1128
1129
1130
1131
1132
1133
      if ( bindir[cc] == '/' )
        {
        bindirrep = bindir.c_str() + cc;
        bindirrep = "/..." + bindirrep;
        bindir = bindir.substr(0, cc+1);
        break;
        }
1134
1135
      }

1136
1137
1138
    cmSystemTools::ReplaceString(output, srcdir.c_str(), "/.../"); //srcdirrep.c_str());
    cmSystemTools::ReplaceString(output, bindir.c_str(), "/.../"); //bindirrep.c_str());
    }
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
  // Parsing of output for errors and warnings.

  std::vector<cmStdString> lines;
  cmSystemTools::Split(output.c_str(), lines);

  
  // Lines are marked: 
  // 0 - nothing
  // 1 - error
  // > 1 - warning
  std::vector<int> markedLines(lines.size(), 0);
  
  // Errors
  for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
    {
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
    m_CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
    }
  for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
    {
    m_CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
    }
  for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
    {
    m_CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
    }
  for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
    {
    m_CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
    }

  for ( cc = 0; cc < m_CustomErrorMatches.size(); cc ++ )
    {
    cmsys::RegularExpression re(m_CustomErrorMatches[cc].c_str());
1173
    cmCTest::tm_VectorOfStrings::size_type kk;
1174
1175
1176
1177
1178
1179
1180
1181
1182
    for ( kk = 0; kk < lines.size(); kk ++ )
      {
      if ( re.find(lines[kk]) )
        {
        markedLines[kk] = 1;
        }
      }    
    }
  // Warnings
1183
  for ( cc = 0; cc < m_CustomWarningMatches.size(); cc ++ )
1184
    {
1185
    cmsys::RegularExpression re(m_CustomWarningMatches[cc].c_str());
1186
    cmCTest::tm_VectorOfStrings::size_type kk;
1187
1188
1189
1190
1191
1192
1193
1194
1195
    for ( kk = 0; kk < lines.size(); kk ++ )
      {
      if ( re.find(lines[kk]) )
        {
        markedLines[kk] += 2;
        }
      }    
    }
  // Errors exceptions
1196
  for ( cc = 0; cc < m_CustomErrorExceptions.size(); cc ++ )
1197
    {
1198
    cmsys::RegularExpression re(m_CustomErrorExceptions[cc].c_str());
1199
1200
1201
    std::vector<int>::size_type kk;
    for ( kk =0; kk < markedLines.size(); kk ++ )
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
1202
      if ( markedLines[kk] == 1 )
1203
1204
1205
        {
        if ( re.find(lines[kk]) )
          {
Andy Cedilnik's avatar
Andy Cedilnik committed
1206
          markedLines[kk] = 0;
1207
1208
1209
1210
1211
          }
        }
      }
    }
  // Warning exceptions
1212
  for ( cc = 0; cc < m_CustomWarningExceptions.size(); cc ++ )
1213
    {
1214
    cmsys::RegularExpression re(m_CustomWarningExceptions[cc].c_str());
1215
1216
1217
    std::vector<int>::size_type kk;
    for ( kk =0; kk < markedLines.size(); kk ++ )
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
1218
      if ( markedLines[kk] > 1 )
1219
1220
1221
        {
        if ( re.find(lines[kk]) )
          {
Andy Cedilnik's avatar
Andy Cedilnik committed
1222
          markedLines[kk] = 0;
1223
1224
1225
1226
1227
1228
          }
        }
      }
    }
  std::vector<cmCTestBuildErrorWarning> errorsWarnings;

1229
1230
1231
  int errors = 0;
  int warnings = 0;

1232
1233
1234
1235
1236
1237
1238
1239
  std::vector<int>::size_type kk;
  cmCTestBuildErrorWarning errorwarning;
  for ( kk =0; kk < markedLines.size(); kk ++ )
    {
    errorwarning.m_LineNumber = -1;
    bool found = false;
    if ( markedLines[kk] == 1 )
      {
1240
      //std::cout << "Error: " << lines[kk] << std::endl;
1241
1242
1243
1244
1245
      errorwarning.m_Error = true;
      found = true;
      }
    else if ( markedLines[kk] > 1 )
      {
1246
      //std::cout << "Warning: " << lines[kk] << std::endl;
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
      errorwarning.m_Error = false;
      found = true;
      }
    if ( found )
      {
      errorwarning.m_LogLine     = static_cast<int>(kk+1);
      errorwarning.m_Text        = lines[kk];
      errorwarning.m_PreContext  = "";
      errorwarning.m_PostContext = "";
      std::vector<int>::size_type jj;
      std::vector<int>::size_type ll = 0;
      if ( kk > 6 )
        {
        ll = kk - 6;
        }
1262
1263
      for ( jj = kk-1; 
            jj > 0 && jj > ll && markedLines[jj] != markedLines[kk]; 
1264
            jj -- );
1265
1266
1267
1268
      while ( markedLines[jj] == markedLines[kk] && jj < kk )
        {
        jj ++;
        }
1269
1270
1271
1272
1273
      for (; jj < kk; jj ++ )
        {
        errorwarning.m_PreContext += lines[jj] + "\n";
        }
      for ( jj = kk+1; 
1274
            jj < lines.size() && jj < kk + 7 && markedLines[jj] != markedLines[kk]; 
1275
1276
1277
1278
1279
            jj ++ )
        {
        errorwarning.m_PostContext += lines[jj] + "\n";
        }
      errorsWarnings.push_back(errorwarning);
1280
1281
1282
1283
1284
1285
1286
1287
      if ( errorwarning.m_Error )
        {
        errors ++;
        }
      else
        {
        warnings ++;
        }
1288
1289
1290
      }
    }

1291
1292
1293
  std::cout << "   " << errors << " Compiler errors" << std::endl;
  std::cout << "   " << warnings << " Compiler warnings" << std::endl;

1294
  if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
    {
    std::cerr << "Cannot create build XML file" << std::endl;
    return 1;
    }
  this->GenerateDartBuildOutput(ofs, errorsWarnings);
  return 0;
}
 
int cmCTest::CoverageDirectory()
{
1305
  std::cout << "Performing coverage" << std::endl;
1306
1307
1308
  cmCTest::tm_VectorOfStrings files;
  cmCTest::tm_VectorOfStrings cfiles;
  cmCTest::tm_VectorOfStrings cdirs;
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
  bool done = false;
  std::string::size_type cc;
  std::string glob;
  std::map<std::string, std::string> allsourcefiles;
  std::map<std::string, std::string> allbinaryfiles;

  std::string start_time = ::CurrentTime();

  // Find all source files.
  std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  if ( sourceDirectory.size() == 0 )
    {
1321
1322
1323
1324
1325
1326
1327
1328
    std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
    return 1;
    }

  std::string coverageCommand = m_DartConfiguration["CoverageCommand"];
  if ( coverageCommand.size() == 0 )
    {
    std::cerr << "Coverage command not defined in DartConfiguration.tcl" << std::endl;
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
    return 1;
    }
  cdirs.push_back(sourceDirectory);
  while ( !done ) 
    {
    if ( cdirs.size() <= 0 )
      {
      break;
      }
    glob = cdirs[cdirs.size()-1] +