2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2009-02-11 19:31:25 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-02-11 19:31:25 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2009-02-11 19:31:25 +03:00
|
|
|
#include "cmCTestLaunch.h"
|
|
|
|
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmSystemTools.h"
|
2015-05-24 21:32:33 +03:00
|
|
|
#include "cmXMLWriter.h"
|
2009-02-11 19:31:25 +03:00
|
|
|
#include "cmake.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/FStream.hxx>
|
2009-02-11 19:31:25 +03:00
|
|
|
#include <cmsys/MD5.h>
|
|
|
|
#include <cmsys/Process.h>
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2014-12-05 20:47:18 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <fcntl.h> // for _O_BINARY
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <io.h> // for _setmode
|
2014-12-05 20:47:18 +03:00
|
|
|
#include <stdio.h> // for std{out,err} and fileno
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 19:31:25 +03:00
|
|
|
cmCTestLaunch::cmCTestLaunch(int argc, const char* const* argv)
|
|
|
|
{
|
|
|
|
this->Passthru = true;
|
2016-06-27 23:44:16 +03:00
|
|
|
this->Process = CM_NULLPTR;
|
2009-02-11 19:31:25 +03:00
|
|
|
this->ExitCode = 1;
|
|
|
|
this->CWD = cmSystemTools::GetCurrentWorkingDirectory();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ParseArguments(argc, argv)) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
this->ComputeFileNames();
|
|
|
|
|
|
|
|
this->ScrapeRulesLoaded = false;
|
|
|
|
this->HaveOut = false;
|
|
|
|
this->HaveErr = false;
|
|
|
|
this->Process = cmsysProcess_New();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCTestLaunch::~cmCTestLaunch()
|
|
|
|
{
|
|
|
|
cmsysProcess_Delete(this->Process);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Passthru) {
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(this->LogOut);
|
|
|
|
cmSystemTools::RemoveFile(this->LogErr);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestLaunch::ParseArguments(int argc, const char* const* argv)
|
|
|
|
{
|
|
|
|
// Launcher options occur first and are separated from the real
|
|
|
|
// command line by a '--' option.
|
2016-05-16 17:34:04 +03:00
|
|
|
enum Doing
|
|
|
|
{
|
|
|
|
DoingNone,
|
|
|
|
DoingOutput,
|
|
|
|
DoingSource,
|
|
|
|
DoingLanguage,
|
|
|
|
DoingTargetName,
|
|
|
|
DoingTargetType,
|
|
|
|
DoingBuildDir,
|
|
|
|
DoingCount,
|
|
|
|
DoingFilterPrefix
|
|
|
|
};
|
2009-02-11 19:31:25 +03:00
|
|
|
Doing doing = DoingNone;
|
|
|
|
int arg0 = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (int i = 1; !arg0 && i < argc; ++i) {
|
2009-02-11 19:31:25 +03:00
|
|
|
const char* arg = argv[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strcmp(arg, "--") == 0) {
|
|
|
|
arg0 = i + 1;
|
|
|
|
} else if (strcmp(arg, "--output") == 0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
doing = DoingOutput;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(arg, "--source") == 0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
doing = DoingSource;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(arg, "--language") == 0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
doing = DoingLanguage;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(arg, "--target-name") == 0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
doing = DoingTargetName;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(arg, "--target-type") == 0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
doing = DoingTargetType;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(arg, "--build-dir") == 0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
doing = DoingBuildDir;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(arg, "--filter-prefix") == 0) {
|
2013-12-02 02:16:06 +04:00
|
|
|
doing = DoingFilterPrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingOutput) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionOutput = arg;
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingSource) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionSource = arg;
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingLanguage) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionLanguage = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OptionLanguage == "CXX") {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionLanguage = "C++";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
doing = DoingNone;
|
|
|
|
} else if (doing == DoingTargetName) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionTargetName = arg;
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingTargetType) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionTargetType = arg;
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingBuildDir) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->OptionBuildDir = arg;
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingFilterPrefix) {
|
2013-12-02 02:16:06 +04:00
|
|
|
this->OptionFilterPrefix = arg;
|
|
|
|
doing = DoingNone;
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// Extract the real command line.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg0) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->RealArgC = argc - arg0;
|
|
|
|
this->RealArgV = argv + arg0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (int i = 0; i < this->RealArgC; ++i) {
|
2009-02-11 19:31:25 +03:00
|
|
|
this->HandleRealArg(this->RealArgV[i]);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-18 21:04:21 +03:00
|
|
|
this->RealArgC = 0;
|
|
|
|
this->RealArgV = CM_NULLPTR;
|
|
|
|
std::cerr << "No launch/command separator ('--') found!\n";
|
|
|
|
return false;
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestLaunch::HandleRealArg(const char* arg)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Expand response file arguments.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg[0] == '@' && cmSystemTools::FileExists(arg + 1)) {
|
|
|
|
cmsys::ifstream fin(arg + 1);
|
2009-02-11 19:31:25 +03:00
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
2009-02-11 19:31:25 +03:00
|
|
|
cmSystemTools::ParseWindowsCommandLine(line.c_str(), this->RealArgs);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
#endif
|
|
|
|
this->RealArgs.push_back(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestLaunch::ComputeFileNames()
|
|
|
|
{
|
|
|
|
// We just passthru the behavior of the real command unless the
|
|
|
|
// CTEST_LAUNCH_LOGS environment variable is set.
|
|
|
|
const char* d = getenv("CTEST_LAUNCH_LOGS");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!(d && *d)) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
this->Passthru = false;
|
|
|
|
|
|
|
|
// The environment variable specifies the directory into which we
|
|
|
|
// generate build logs.
|
|
|
|
this->LogDir = d;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(this->LogDir);
|
|
|
|
this->LogDir += "/";
|
|
|
|
|
|
|
|
// We hash the input command working dir and command line to obtain
|
|
|
|
// a repeatable and (probably) unique name for log files.
|
2009-02-11 19:57:24 +03:00
|
|
|
char hash[32];
|
2009-02-11 19:31:25 +03:00
|
|
|
cmsysMD5* md5 = cmsysMD5_New();
|
|
|
|
cmsysMD5_Initialize(md5);
|
|
|
|
cmsysMD5_Append(md5, (unsigned char const*)(this->CWD.c_str()), -1);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
|
|
|
|
ai != this->RealArgs.end(); ++ai) {
|
2009-02-11 19:31:25 +03:00
|
|
|
cmsysMD5_Append(md5, (unsigned char const*)ai->c_str(), -1);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
cmsysMD5_FinalizeHex(md5, hash);
|
|
|
|
cmsysMD5_Delete(md5);
|
2009-02-11 19:57:24 +03:00
|
|
|
this->LogHash.assign(hash, 32);
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// We store stdout and stderr in temporary log files.
|
|
|
|
this->LogOut = this->LogDir;
|
|
|
|
this->LogOut += "launch-";
|
|
|
|
this->LogOut += this->LogHash;
|
|
|
|
this->LogOut += "-out.txt";
|
|
|
|
this->LogErr = this->LogDir;
|
|
|
|
this->LogErr += "launch-";
|
|
|
|
this->LogErr += this->LogHash;
|
|
|
|
this->LogErr += "-err.txt";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestLaunch::RunChild()
|
|
|
|
{
|
2011-01-06 21:00:18 +03:00
|
|
|
// Ignore noopt make rules
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->RealArgs.empty() || this->RealArgs[0] == ":") {
|
2011-01-06 21:00:18 +03:00
|
|
|
this->ExitCode = 0;
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-01-06 21:00:18 +03:00
|
|
|
|
2009-02-11 19:31:25 +03:00
|
|
|
// Prepare to run the real command.
|
|
|
|
cmsysProcess* cp = this->Process;
|
|
|
|
cmsysProcess_SetCommand(cp, this->RealArgV);
|
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream fout;
|
|
|
|
cmsys::ofstream ferr;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Passthru) {
|
2009-02-11 19:31:25 +03:00
|
|
|
// In passthru mode we just share the output pipes.
|
|
|
|
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
|
|
|
|
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2009-02-11 19:31:25 +03:00
|
|
|
// In full mode we record the child output pipes to log files.
|
2016-05-16 17:34:04 +03:00
|
|
|
fout.open(this->LogOut.c_str(), std::ios::out | std::ios::binary);
|
|
|
|
ferr.open(this->LogErr.c_str(), std::ios::out | std::ios::binary);
|
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
2014-12-05 20:47:18 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Do this so that newline transformation is not done when writing to cout
|
|
|
|
// and cerr below.
|
|
|
|
_setmode(fileno(stdout), _O_BINARY);
|
|
|
|
_setmode(fileno(stderr), _O_BINARY);
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 19:31:25 +03:00
|
|
|
// Run the real command.
|
|
|
|
cmsysProcess_Execute(cp);
|
|
|
|
|
|
|
|
// Record child stdout and stderr if necessary.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Passthru) {
|
2016-06-27 23:44:16 +03:00
|
|
|
char* data = CM_NULLPTR;
|
2009-02-11 19:31:25 +03:00
|
|
|
int length = 0;
|
2016-06-27 23:44:16 +03:00
|
|
|
while (int p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (p == cmsysProcess_Pipe_STDOUT) {
|
2009-02-11 19:31:25 +03:00
|
|
|
fout.write(data, length);
|
|
|
|
std::cout.write(data, length);
|
|
|
|
this->HaveOut = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (p == cmsysProcess_Pipe_STDERR) {
|
2009-02-11 19:31:25 +03:00
|
|
|
ferr.write(data, length);
|
|
|
|
std::cerr.write(data, length);
|
|
|
|
this->HaveErr = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// Wait for the real command to finish.
|
2016-06-27 23:44:16 +03:00
|
|
|
cmsysProcess_WaitForExit(cp, CM_NULLPTR);
|
2009-02-11 19:31:25 +03:00
|
|
|
this->ExitCode = cmsysProcess_GetExitValue(cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCTestLaunch::Run()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Process) {
|
2009-02-11 19:31:25 +03:00
|
|
|
std::cerr << "Could not allocate cmsysProcess instance!\n";
|
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
this->RunChild();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CheckResults()) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return this->ExitCode;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
2009-02-12 21:00:22 +03:00
|
|
|
this->LoadConfig();
|
2009-02-11 19:31:25 +03:00
|
|
|
this->WriteXML();
|
|
|
|
|
|
|
|
return this->ExitCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestLaunch::LoadLabels()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OptionBuildDir.empty() || this->OptionTargetName.empty()) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// Labels are listed in per-target files.
|
|
|
|
std::string fname = this->OptionBuildDir;
|
|
|
|
fname += cmake::GetCMakeFilesDirectory();
|
|
|
|
fname += "/";
|
|
|
|
fname += this->OptionTargetName;
|
|
|
|
fname += ".dir/Labels.txt";
|
|
|
|
|
|
|
|
// We are interested in per-target labels for this source file.
|
|
|
|
std::string source = this->OptionSource;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(source);
|
|
|
|
|
|
|
|
// Load the labels file.
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fin) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
bool inTarget = true;
|
|
|
|
bool inSource = false;
|
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (line.empty() || line[0] == '#') {
|
2009-02-11 19:31:25 +03:00
|
|
|
// Ignore blank and comment lines.
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (line[0] == ' ') {
|
2009-02-11 19:31:25 +03:00
|
|
|
// Label lines appear indented by one space.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (inTarget || inSource) {
|
|
|
|
this->Labels.insert(line.c_str() + 1);
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->OptionSource.empty() && !inSource) {
|
2009-02-11 19:31:25 +03:00
|
|
|
// Non-indented lines specify a source file name. The first one
|
|
|
|
// is the end of the target-wide labels. Use labels following a
|
|
|
|
// matching source.
|
|
|
|
inTarget = false;
|
|
|
|
inSource = this->SourceMatches(line, source);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2009-02-11 19:31:25 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestLaunch::SourceMatches(std::string const& lhs,
|
|
|
|
std::string const& rhs)
|
|
|
|
{
|
|
|
|
// TODO: Case sensitivity, UseRelativePaths, etc. Note that both
|
|
|
|
// paths in the comparison get generated by CMake. This is done for
|
|
|
|
// every source in the target, so it should be efficient (cannot use
|
|
|
|
// cmSystemTools::IsSameFile).
|
|
|
|
return lhs == rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestLaunch::IsError() const
|
|
|
|
{
|
|
|
|
return this->ExitCode != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestLaunch::WriteXML()
|
|
|
|
{
|
|
|
|
// Name the xml file.
|
|
|
|
std::string logXML = this->LogDir;
|
2016-05-16 17:34:04 +03:00
|
|
|
logXML += this->IsError() ? "error-" : "warning-";
|
2009-02-11 19:31:25 +03:00
|
|
|
logXML += this->LogHash;
|
|
|
|
logXML += ".xml";
|
|
|
|
|
|
|
|
// Use cmGeneratedFileStream to atomically create the report file.
|
|
|
|
cmGeneratedFileStream fxml(logXML.c_str());
|
2015-05-24 21:32:33 +03:00
|
|
|
cmXMLWriter xml(fxml, 2);
|
|
|
|
xml.StartElement("Failure");
|
|
|
|
xml.Attribute("type", this->IsError() ? "Error" : "Warning");
|
|
|
|
this->WriteXMLAction(xml);
|
|
|
|
this->WriteXMLCommand(xml);
|
|
|
|
this->WriteXMLResult(xml);
|
|
|
|
this->WriteXMLLabels(xml);
|
|
|
|
xml.EndElement(); // Failure
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
|
2009-02-11 19:31:25 +03:00
|
|
|
{
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Comment("Meta-information about the build action");
|
|
|
|
xml.StartElement("Action");
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// TargetName
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OptionTargetName.empty()) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("TargetName", this->OptionTargetName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// Language
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OptionLanguage.empty()) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("Language", this->OptionLanguage);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// SourceFile
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OptionSource.empty()) {
|
2009-02-12 21:00:22 +03:00
|
|
|
std::string source = this->OptionSource;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(source);
|
|
|
|
|
|
|
|
// If file is in source tree use its relative location.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsFullPath(this->SourceDir.c_str()) &&
|
|
|
|
cmSystemTools::FileIsFullPath(source.c_str()) &&
|
|
|
|
cmSystemTools::IsSubDirectory(source, this->SourceDir)) {
|
|
|
|
source =
|
|
|
|
cmSystemTools::RelativePath(this->SourceDir.c_str(), source.c_str());
|
|
|
|
}
|
2009-02-12 21:00:22 +03:00
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("SourceFile", source);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// OutputFile
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OptionOutput.empty()) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("OutputFile", this->OptionOutput);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// OutputType
|
2016-06-27 23:44:16 +03:00
|
|
|
const char* outputType = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OptionTargetType.empty()) {
|
|
|
|
if (this->OptionTargetType == "EXECUTABLE") {
|
2009-02-11 19:31:25 +03:00
|
|
|
outputType = "executable";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->OptionTargetType == "SHARED_LIBRARY") {
|
2009-02-11 19:31:25 +03:00
|
|
|
outputType = "shared library";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->OptionTargetType == "MODULE_LIBRARY") {
|
2009-02-11 19:31:25 +03:00
|
|
|
outputType = "module library";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->OptionTargetType == "STATIC_LIBRARY") {
|
2009-02-11 19:31:25 +03:00
|
|
|
outputType = "static library";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->OptionSource.empty()) {
|
2009-02-11 19:31:25 +03:00
|
|
|
outputType = "object file";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (outputType) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("OutputType", outputType);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.EndElement(); // Action
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml)
|
2009-02-11 19:31:25 +03:00
|
|
|
{
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Comment("Details of command");
|
|
|
|
xml.StartElement("Command");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->CWD.empty()) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("WorkingDirectory", this->CWD);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
|
|
|
|
ai != this->RealArgs.end(); ++ai) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("Argument", *ai);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.EndElement(); // Command
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml)
|
2009-02-11 19:31:25 +03:00
|
|
|
{
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Comment("Result of command");
|
|
|
|
xml.StartElement("Result");
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// StdOut
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.StartElement("StdOut");
|
|
|
|
this->DumpFileToXML(xml, this->LogOut);
|
|
|
|
xml.EndElement(); // StdOut
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// StdErr
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.StartElement("StdErr");
|
|
|
|
this->DumpFileToXML(xml, this->LogErr);
|
|
|
|
xml.EndElement(); // StdErr
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// ExitCondition
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.StartElement("ExitCondition");
|
2009-02-11 19:31:25 +03:00
|
|
|
cmsysProcess* cp = this->Process;
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (cmsysProcess_GetState(cp)) {
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Starting:
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content("No process has been executed");
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Executing:
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content("The process is still executing");
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Disowned:
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content("Disowned");
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Killed:
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content("Killed by parent");
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
case cmsysProcess_State_Expired:
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content("Killed when timeout expired");
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Exited:
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content(this->ExitCode);
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Exception:
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Content("Terminated abnormally: ");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content(cmsysProcess_GetExceptionString(cp));
|
|
|
|
break;
|
2009-02-11 19:31:25 +03:00
|
|
|
case cmsysProcess_State_Error:
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Content("Error administrating child process: ");
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.Content(cmsysProcess_GetErrorString(cp));
|
|
|
|
break;
|
|
|
|
};
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.EndElement(); // ExitCondition
|
2009-02-11 19:31:25 +03:00
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.EndElement(); // Result
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml)
|
2009-02-11 19:31:25 +03:00
|
|
|
{
|
|
|
|
this->LoadLabels();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Labels.empty()) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Comment("Interested parties");
|
|
|
|
xml.StartElement("Labels");
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator li = this->Labels.begin();
|
|
|
|
li != this->Labels.end(); ++li) {
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Element("Label", *li);
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
xml.EndElement(); // Labels
|
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname)
|
2009-02-11 19:31:25 +03:00
|
|
|
{
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
std::string line;
|
|
|
|
const char* sep = "";
|
2013-12-02 02:16:06 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (MatchesFilterPrefix(line)) {
|
2013-12-02 02:16:06 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-12-02 02:16:06 +04:00
|
|
|
|
2015-05-24 21:32:33 +03:00
|
|
|
xml.Content(sep);
|
|
|
|
xml.Content(line);
|
2009-02-11 19:31:25 +03:00
|
|
|
sep = "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestLaunch::CheckResults()
|
|
|
|
{
|
|
|
|
// Skip XML in passthru mode.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Passthru) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// We always report failure for error conditions.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsError()) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
|
|
|
|
// Scrape the output logs to look for warnings.
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((this->HaveErr && this->ScrapeLog(this->LogErr)) ||
|
|
|
|
(this->HaveOut && this->ScrapeLog(this->LogOut))) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestLaunch::LoadScrapeRules()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ScrapeRulesLoaded) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
this->ScrapeRulesLoaded = true;
|
|
|
|
|
|
|
|
// Common compiler warning formats. These are much simpler than the
|
|
|
|
// full log-scraping expressions because we do not need to extract
|
|
|
|
// file and line information.
|
|
|
|
this->RegexWarning.push_back("(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]");
|
|
|
|
this->RegexWarning.push_back("(^|[ :])[Rr][Ee][Mm][Aa][Rr][Kk]");
|
|
|
|
this->RegexWarning.push_back("(^|[ :])[Nn][Oo][Tt][Ee]");
|
|
|
|
|
|
|
|
// Load custom match rules given to us by CTest.
|
|
|
|
this->LoadScrapeRules("Warning", this->RegexWarning);
|
|
|
|
this->LoadScrapeRules("WarningSuppress", this->RegexWarningSuppress);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestLaunch::LoadScrapeRules(
|
|
|
|
const char* purpose, std::vector<cmsys::RegularExpression>& regexps)
|
2009-02-11 19:31:25 +03:00
|
|
|
{
|
|
|
|
std::string fname = this->LogDir;
|
|
|
|
fname += "Custom";
|
|
|
|
fname += purpose;
|
|
|
|
fname += ".txt";
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
|
2009-02-11 19:31:25 +03:00
|
|
|
std::string line;
|
|
|
|
cmsys::RegularExpression rex;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (rex.compile(line.c_str())) {
|
2009-02-11 19:31:25 +03:00
|
|
|
regexps.push_back(rex);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestLaunch::ScrapeLog(std::string const& fname)
|
|
|
|
{
|
|
|
|
this->LoadScrapeRules();
|
|
|
|
|
|
|
|
// Look for log file lines matching warning expressions but not
|
|
|
|
// suppression expressions.
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
|
2009-02-11 19:31:25 +03:00
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (MatchesFilterPrefix(line)) {
|
2014-02-25 14:25:41 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-25 14:25:41 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Match(line, this->RegexWarning) &&
|
|
|
|
!this->Match(line, this->RegexWarningSuppress)) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestLaunch::Match(std::string const& line,
|
|
|
|
std::vector<cmsys::RegularExpression>& regexps)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmsys::RegularExpression>::iterator ri = regexps.begin();
|
|
|
|
ri != regexps.end(); ++ri) {
|
|
|
|
if (ri->find(line.c_str())) {
|
2009-02-11 19:31:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 14:25:41 +04:00
|
|
|
bool cmCTestLaunch::MatchesFilterPrefix(std::string const& line) const
|
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
return !this->OptionFilterPrefix.empty() &&
|
|
|
|
cmSystemTools::StringStartsWith(line, this->OptionFilterPrefix.c_str());
|
2014-02-25 14:25:41 +04:00
|
|
|
}
|
|
|
|
|
2009-02-11 19:31:25 +03:00
|
|
|
int cmCTestLaunch::Main(int argc, const char* const argv[])
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argc == 2) {
|
2009-02-11 19:31:25 +03:00
|
|
|
std::cerr << "ctest --launch: this mode is for internal CTest use only"
|
|
|
|
<< std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-11 19:31:25 +03:00
|
|
|
cmCTestLaunch self(argc, argv);
|
|
|
|
return self.Run();
|
|
|
|
}
|
2009-02-12 21:00:22 +03:00
|
|
|
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmake.h"
|
2016-06-28 17:17:52 +03:00
|
|
|
#include <cm_auto_ptr.hxx>
|
2009-02-12 21:00:22 +03:00
|
|
|
void cmCTestLaunch::LoadConfig()
|
|
|
|
{
|
|
|
|
cmake cm;
|
2015-05-05 00:01:29 +03:00
|
|
|
cm.SetHomeDirectory("");
|
|
|
|
cm.SetHomeOutputDirectory("");
|
2015-10-13 22:48:46 +03:00
|
|
|
cm.GetCurrentSnapshot().SetDefaultDefinitions();
|
2015-05-24 12:31:14 +03:00
|
|
|
cmGlobalGenerator gg(&cm);
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
|
2009-02-12 21:00:22 +03:00
|
|
|
std::string fname = this->LogDir;
|
|
|
|
fname += "CTestLaunchConfig.cmake";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(fname.c_str()) &&
|
|
|
|
mf->ReadListFile(fname.c_str())) {
|
2009-02-12 21:00:22 +03:00
|
|
|
this->SourceDir = mf->GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(this->SourceDir);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-12 21:00:22 +03:00
|
|
|
}
|