diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/CTest/cmCTestLaunch.cxx | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Source/CTest/cmCTestLaunch.cxx')
-rw-r--r-- | Source/CTest/cmCTestLaunch.cxx | 431 |
1 files changed, 170 insertions, 261 deletions
diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 7da81ec..4a408a2 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -34,10 +34,9 @@ cmCTestLaunch::cmCTestLaunch(int argc, const char* const* argv) this->ExitCode = 1; this->CWD = cmSystemTools::GetCurrentWorkingDirectory(); - if(!this->ParseArguments(argc, argv)) - { + if (!this->ParseArguments(argc, argv)) { return; - } + } this->ComputeFileNames(); @@ -50,138 +49,103 @@ cmCTestLaunch::cmCTestLaunch(int argc, const char* const* argv) cmCTestLaunch::~cmCTestLaunch() { cmsysProcess_Delete(this->Process); - if(!this->Passthru) - { + if (!this->Passthru) { cmSystemTools::RemoveFile(this->LogOut); cmSystemTools::RemoveFile(this->LogErr); - } + } } bool cmCTestLaunch::ParseArguments(int argc, const char* const* argv) { // Launcher options occur first and are separated from the real // command line by a '--' option. - enum Doing { DoingNone, - DoingOutput, - DoingSource, - DoingLanguage, - DoingTargetName, - DoingTargetType, - DoingBuildDir, - DoingCount, - DoingFilterPrefix }; + enum Doing + { + DoingNone, + DoingOutput, + DoingSource, + DoingLanguage, + DoingTargetName, + DoingTargetType, + DoingBuildDir, + DoingCount, + DoingFilterPrefix + }; Doing doing = DoingNone; int arg0 = 0; - for(int i=1; !arg0 && i < argc; ++i) - { + for (int i = 1; !arg0 && i < argc; ++i) { const char* arg = argv[i]; - if(strcmp(arg, "--") == 0) - { - arg0 = i+1; - } - else if(strcmp(arg, "--output") == 0) - { + if (strcmp(arg, "--") == 0) { + arg0 = i + 1; + } else if (strcmp(arg, "--output") == 0) { doing = DoingOutput; - } - else if(strcmp(arg, "--source") == 0) - { + } else if (strcmp(arg, "--source") == 0) { doing = DoingSource; - } - else if(strcmp(arg, "--language") == 0) - { + } else if (strcmp(arg, "--language") == 0) { doing = DoingLanguage; - } - else if(strcmp(arg, "--target-name") == 0) - { + } else if (strcmp(arg, "--target-name") == 0) { doing = DoingTargetName; - } - else if(strcmp(arg, "--target-type") == 0) - { + } else if (strcmp(arg, "--target-type") == 0) { doing = DoingTargetType; - } - else if(strcmp(arg, "--build-dir") == 0) - { + } else if (strcmp(arg, "--build-dir") == 0) { doing = DoingBuildDir; - } - else if(strcmp(arg, "--filter-prefix") == 0) - { + } else if (strcmp(arg, "--filter-prefix") == 0) { doing = DoingFilterPrefix; - } - else if(doing == DoingOutput) - { + } else if (doing == DoingOutput) { this->OptionOutput = arg; doing = DoingNone; - } - else if(doing == DoingSource) - { + } else if (doing == DoingSource) { this->OptionSource = arg; doing = DoingNone; - } - else if(doing == DoingLanguage) - { + } else if (doing == DoingLanguage) { this->OptionLanguage = arg; - if(this->OptionLanguage == "CXX") - { + if (this->OptionLanguage == "CXX") { this->OptionLanguage = "C++"; - } - doing = DoingNone; } - else if(doing == DoingTargetName) - { + doing = DoingNone; + } else if (doing == DoingTargetName) { this->OptionTargetName = arg; doing = DoingNone; - } - else if(doing == DoingTargetType) - { + } else if (doing == DoingTargetType) { this->OptionTargetType = arg; doing = DoingNone; - } - else if(doing == DoingBuildDir) - { + } else if (doing == DoingBuildDir) { this->OptionBuildDir = arg; doing = DoingNone; - } - else if(doing == DoingFilterPrefix) - { + } else if (doing == DoingFilterPrefix) { this->OptionFilterPrefix = arg; doing = DoingNone; - } } + } // Extract the real command line. - if(arg0) - { + if (arg0) { this->RealArgC = argc - arg0; this->RealArgV = argv + arg0; - for(int i=0; i < this->RealArgC; ++i) - { + for (int i = 0; i < this->RealArgC; ++i) { this->HandleRealArg(this->RealArgV[i]); - } - return true; } - else - { + return true; + } else { this->RealArgC = 0; this->RealArgV = 0; std::cerr << "No launch/command separator ('--') found!\n"; return false; - } + } } void cmCTestLaunch::HandleRealArg(const char* arg) { #ifdef _WIN32 // Expand response file arguments. - if(arg[0] == '@' && cmSystemTools::FileExists(arg+1)) - { - cmsys::ifstream fin(arg+1); + if (arg[0] == '@' && cmSystemTools::FileExists(arg + 1)) { + cmsys::ifstream fin(arg + 1); std::string line; - while(cmSystemTools::GetLineFromStream(fin, line)) - { + while (cmSystemTools::GetLineFromStream(fin, line)) { cmSystemTools::ParseWindowsCommandLine(line.c_str(), this->RealArgs); - } - return; } + return; + } #endif this->RealArgs.push_back(arg); } @@ -191,10 +155,9 @@ 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"); - if(!(d && *d)) - { + if (!(d && *d)) { return; - } + } this->Passthru = false; // The environment variable specifies the directory into which we @@ -209,11 +172,10 @@ void cmCTestLaunch::ComputeFileNames() cmsysMD5* md5 = cmsysMD5_New(); cmsysMD5_Initialize(md5); cmsysMD5_Append(md5, (unsigned char const*)(this->CWD.c_str()), -1); - for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin(); - ai != this->RealArgs.end(); ++ai) - { + for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin(); + ai != this->RealArgs.end(); ++ai) { cmsysMD5_Append(md5, (unsigned char const*)ai->c_str(), -1); - } + } cmsysMD5_FinalizeHex(md5, hash); cmsysMD5_Delete(md5); this->LogHash.assign(hash, 32); @@ -232,11 +194,10 @@ void cmCTestLaunch::ComputeFileNames() void cmCTestLaunch::RunChild() { // Ignore noopt make rules - if(this->RealArgs.empty() || this->RealArgs[0] == ":") - { + if (this->RealArgs.empty() || this->RealArgs[0] == ":") { this->ExitCode = 0; return; - } + } // Prepare to run the real command. cmsysProcess* cp = this->Process; @@ -244,20 +205,15 @@ void cmCTestLaunch::RunChild() cmsys::ofstream fout; cmsys::ofstream ferr; - if(this->Passthru) - { + if (this->Passthru) { // In passthru mode we just share the output pipes. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1); cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1); - } - else - { + } else { // In full mode we record the child output pipes to log files. - fout.open(this->LogOut.c_str(), - std::ios::out | std::ios::binary); - ferr.open(this->LogErr.c_str(), - std::ios::out | std::ios::binary); - } + fout.open(this->LogOut.c_str(), std::ios::out | std::ios::binary); + ferr.open(this->LogErr.c_str(), std::ios::out | std::ios::binary); + } #ifdef _WIN32 // Do this so that newline transformation is not done when writing to cout @@ -270,26 +226,21 @@ void cmCTestLaunch::RunChild() cmsysProcess_Execute(cp); // Record child stdout and stderr if necessary. - if(!this->Passthru) - { + if (!this->Passthru) { char* data = 0; int length = 0; - while(int p = cmsysProcess_WaitForData(cp, &data, &length, 0)) - { - if(p == cmsysProcess_Pipe_STDOUT) - { + while (int p = cmsysProcess_WaitForData(cp, &data, &length, 0)) { + if (p == cmsysProcess_Pipe_STDOUT) { fout.write(data, length); std::cout.write(data, length); this->HaveOut = true; - } - else if(p == cmsysProcess_Pipe_STDERR) - { + } else if (p == cmsysProcess_Pipe_STDERR) { ferr.write(data, length); std::cerr.write(data, length); this->HaveErr = true; - } } } + } // Wait for the real command to finish. cmsysProcess_WaitForExit(cp, 0); @@ -298,18 +249,16 @@ void cmCTestLaunch::RunChild() int cmCTestLaunch::Run() { - if(!this->Process) - { + if (!this->Process) { std::cerr << "Could not allocate cmsysProcess instance!\n"; return -1; - } + } this->RunChild(); - if(this->CheckResults()) - { + if (this->CheckResults()) { return this->ExitCode; - } + } this->LoadConfig(); this->WriteXML(); @@ -319,10 +268,9 @@ int cmCTestLaunch::Run() void cmCTestLaunch::LoadLabels() { - if(this->OptionBuildDir.empty() || this->OptionTargetName.empty()) - { + if (this->OptionBuildDir.empty() || this->OptionTargetName.empty()) { return; - } + } // Labels are listed in per-target files. std::string fname = this->OptionBuildDir; @@ -337,38 +285,31 @@ void cmCTestLaunch::LoadLabels() // Load the labels file. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary); - if(!fin) { return; } + if (!fin) { + return; + } bool inTarget = true; bool inSource = false; std::string line; - while(cmSystemTools::GetLineFromStream(fin, line)) - { - if(line.empty() || line[0] == '#') - { + while (cmSystemTools::GetLineFromStream(fin, line)) { + if (line.empty() || line[0] == '#') { // Ignore blank and comment lines. continue; - } - else if(line[0] == ' ') - { + } else if (line[0] == ' ') { // Label lines appear indented by one space. - if(inTarget || inSource) - { - this->Labels.insert(line.c_str()+1); - } + if (inTarget || inSource) { + this->Labels.insert(line.c_str() + 1); } - else if(!this->OptionSource.empty() && !inSource) - { + } else if (!this->OptionSource.empty() && !inSource) { // 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); - } - else - { + } else { return; - } } + } } bool cmCTestLaunch::SourceMatches(std::string const& lhs, @@ -390,7 +331,7 @@ void cmCTestLaunch::WriteXML() { // Name the xml file. std::string logXML = this->LogDir; - logXML += this->IsError()? "error-" : "warning-"; + logXML += this->IsError() ? "error-" : "warning-"; logXML += this->LogHash; logXML += ".xml"; @@ -412,71 +353,54 @@ void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml) xml.StartElement("Action"); // TargetName - if(!this->OptionTargetName.empty()) - { + if (!this->OptionTargetName.empty()) { xml.Element("TargetName", this->OptionTargetName); - } + } // Language - if(!this->OptionLanguage.empty()) - { + if (!this->OptionLanguage.empty()) { xml.Element("Language", this->OptionLanguage); - } + } // SourceFile - if(!this->OptionSource.empty()) - { + if (!this->OptionSource.empty()) { std::string source = this->OptionSource; cmSystemTools::ConvertToUnixSlashes(source); // If file is in source tree use its relative location. - 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()); - } + 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()); + } xml.Element("SourceFile", source); - } + } // OutputFile - if(!this->OptionOutput.empty()) - { + if (!this->OptionOutput.empty()) { xml.Element("OutputFile", this->OptionOutput); - } + } // OutputType const char* outputType = 0; - if(!this->OptionTargetType.empty()) - { - if(this->OptionTargetType == "EXECUTABLE") - { + if (!this->OptionTargetType.empty()) { + if (this->OptionTargetType == "EXECUTABLE") { outputType = "executable"; - } - else if(this->OptionTargetType == "SHARED_LIBRARY") - { + } else if (this->OptionTargetType == "SHARED_LIBRARY") { outputType = "shared library"; - } - else if(this->OptionTargetType == "MODULE_LIBRARY") - { + } else if (this->OptionTargetType == "MODULE_LIBRARY") { outputType = "module library"; - } - else if(this->OptionTargetType == "STATIC_LIBRARY") - { + } else if (this->OptionTargetType == "STATIC_LIBRARY") { outputType = "static library"; - } } - else if(!this->OptionSource.empty()) - { + } else if (!this->OptionSource.empty()) { outputType = "object file"; - } - if(outputType) - { + } + if (outputType) { xml.Element("OutputType", outputType); - } + } xml.EndElement(); // Action } @@ -485,15 +409,13 @@ void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml) { xml.Comment("Details of command"); xml.StartElement("Command"); - if(!this->CWD.empty()) - { + if (!this->CWD.empty()) { xml.Element("WorkingDirectory", this->CWD); - } - for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin(); - ai != this->RealArgs.end(); ++ai) - { + } + for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin(); + ai != this->RealArgs.end(); ++ai) { xml.Element("Argument", *ai); - } + } xml.EndElement(); // Command } @@ -515,28 +437,35 @@ void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml) // ExitCondition xml.StartElement("ExitCondition"); cmsysProcess* cp = this->Process; - switch (cmsysProcess_GetState(cp)) - { + switch (cmsysProcess_GetState(cp)) { case cmsysProcess_State_Starting: - xml.Content("No process has been executed"); break; + xml.Content("No process has been executed"); + break; case cmsysProcess_State_Executing: - xml.Content("The process is still executing"); break; + xml.Content("The process is still executing"); + break; case cmsysProcess_State_Disowned: - xml.Content("Disowned"); break; + xml.Content("Disowned"); + break; case cmsysProcess_State_Killed: - xml.Content("Killed by parent"); break; + xml.Content("Killed by parent"); + break; case cmsysProcess_State_Expired: - xml.Content("Killed when timeout expired"); break; + xml.Content("Killed when timeout expired"); + break; case cmsysProcess_State_Exited: - xml.Content(this->ExitCode); break; + xml.Content(this->ExitCode); + break; case cmsysProcess_State_Exception: xml.Content("Terminated abnormally: "); - xml.Content(cmsysProcess_GetExceptionString(cp)); break; + xml.Content(cmsysProcess_GetExceptionString(cp)); + break; case cmsysProcess_State_Error: xml.Content("Error administrating child process: "); - xml.Content(cmsysProcess_GetErrorString(cp)); break; - }; + xml.Content(cmsysProcess_GetErrorString(cp)); + break; + }; xml.EndElement(); // ExitCondition xml.EndElement(); // Result @@ -545,69 +474,60 @@ void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml) void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml) { this->LoadLabels(); - if(!this->Labels.empty()) - { + if (!this->Labels.empty()) { xml.Comment("Interested parties"); xml.StartElement("Labels"); - for(std::set<std::string>::const_iterator li = this->Labels.begin(); - li != this->Labels.end(); ++li) - { + for (std::set<std::string>::const_iterator li = this->Labels.begin(); + li != this->Labels.end(); ++li) { xml.Element("Label", *li); - } - xml.EndElement(); // Labels } + xml.EndElement(); // Labels + } } -void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, - std::string const& fname) +void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname) { cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary); std::string line; const char* sep = ""; - while(cmSystemTools::GetLineFromStream(fin, line)) - { - if(MatchesFilterPrefix(line)) - { + while (cmSystemTools::GetLineFromStream(fin, line)) { + if (MatchesFilterPrefix(line)) { continue; - } + } xml.Content(sep); xml.Content(line); sep = "\n"; - } + } } bool cmCTestLaunch::CheckResults() { // Skip XML in passthru mode. - if(this->Passthru) - { + if (this->Passthru) { return true; - } + } // We always report failure for error conditions. - if(this->IsError()) - { + if (this->IsError()) { return false; - } + } // Scrape the output logs to look for warnings. - if((this->HaveErr && this->ScrapeLog(this->LogErr)) || - (this->HaveOut && this->ScrapeLog(this->LogOut))) - { + if ((this->HaveErr && this->ScrapeLog(this->LogErr)) || + (this->HaveOut && this->ScrapeLog(this->LogOut))) { return false; - } + } return true; } void cmCTestLaunch::LoadScrapeRules() { - if(this->ScrapeRulesLoaded) - { + if (this->ScrapeRulesLoaded) { return; - } + } this->ScrapeRulesLoaded = true; // Common compiler warning formats. These are much simpler than the @@ -622,10 +542,8 @@ void cmCTestLaunch::LoadScrapeRules() this->LoadScrapeRules("WarningSuppress", this->RegexWarningSuppress); } -void -cmCTestLaunch -::LoadScrapeRules(const char* purpose, - std::vector<cmsys::RegularExpression>& regexps) +void cmCTestLaunch::LoadScrapeRules( + const char* purpose, std::vector<cmsys::RegularExpression>& regexps) { std::string fname = this->LogDir; fname += "Custom"; @@ -634,13 +552,11 @@ cmCTestLaunch cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary); std::string line; cmsys::RegularExpression rex; - while(cmSystemTools::GetLineFromStream(fin, line)) - { - if(rex.compile(line.c_str())) - { + while (cmSystemTools::GetLineFromStream(fin, line)) { + if (rex.compile(line.c_str())) { regexps.push_back(rex); - } } + } } bool cmCTestLaunch::ScrapeLog(std::string const& fname) @@ -651,54 +567,48 @@ bool cmCTestLaunch::ScrapeLog(std::string const& fname) // suppression expressions. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary); std::string line; - while(cmSystemTools::GetLineFromStream(fin, line)) - { - if(MatchesFilterPrefix(line)) - { + while (cmSystemTools::GetLineFromStream(fin, line)) { + if (MatchesFilterPrefix(line)) { continue; - } + } - if(this->Match(line, this->RegexWarning) && - !this->Match(line, this->RegexWarningSuppress)) - { + if (this->Match(line, this->RegexWarning) && + !this->Match(line, this->RegexWarningSuppress)) { return true; - } } + } return false; } bool cmCTestLaunch::Match(std::string const& line, std::vector<cmsys::RegularExpression>& regexps) { - for(std::vector<cmsys::RegularExpression>::iterator ri = regexps.begin(); - ri != regexps.end(); ++ri) - { - if(ri->find(line.c_str())) - { + for (std::vector<cmsys::RegularExpression>::iterator ri = regexps.begin(); + ri != regexps.end(); ++ri) { + if (ri->find(line.c_str())) { return true; - } } + } return false; } bool cmCTestLaunch::MatchesFilterPrefix(std::string const& line) const { - if(!this->OptionFilterPrefix.empty() && cmSystemTools::StringStartsWith( - line.c_str(), this->OptionFilterPrefix.c_str())) - { + if (!this->OptionFilterPrefix.empty() && + cmSystemTools::StringStartsWith(line.c_str(), + this->OptionFilterPrefix.c_str())) { return true; - } + } return false; } int cmCTestLaunch::Main(int argc, const char* const argv[]) { - if(argc == 2) - { + if (argc == 2) { std::cerr << "ctest --launch: this mode is for internal CTest use only" << std::endl; return 1; - } + } cmCTestLaunch self(argc, argv); return self.Run(); } @@ -717,10 +627,9 @@ void cmCTestLaunch::LoadConfig() cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); std::string fname = this->LogDir; fname += "CTestLaunchConfig.cmake"; - if(cmSystemTools::FileExists(fname.c_str()) && - mf->ReadListFile(fname.c_str())) - { + if (cmSystemTools::FileExists(fname.c_str()) && + mf->ReadListFile(fname.c_str())) { this->SourceDir = mf->GetSafeDefinition("CTEST_SOURCE_DIRECTORY"); cmSystemTools::ConvertToUnixSlashes(this->SourceDir); - } + } } |