Merge topic 'fix-process-error-handling'

203b20df cmcmd:  Improve error handling when executing a process.
b28b07db cmCTestCoverageHandle:  Improve error handling.
This commit is contained in:
Brad King 2015-08-10 09:13:22 -04:00 committed by CMake Topic Stage
commit 815a2c09d3
3 changed files with 42 additions and 12 deletions

View File

@ -1474,7 +1474,12 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
<< std::endl, this->Quiet); << std::endl, this->Quiet);
std::vector<std::string> files; std::vector<std::string> files;
this->FindLCovFiles(files); if (!this->FindLCovFiles(files))
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error while finding LCov files.\n");
return 0;
}
std::vector<std::string>::iterator it; std::vector<std::string>::iterator it;
if (files.empty()) if (files.empty())
@ -1745,18 +1750,28 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector<std::string>& files)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files) bool cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
{ {
cmsys::Glob gl; cmsys::Glob gl;
gl.RecurseOff(); // No need of recurse if -prof_dir${BUILD_DIR} flag is gl.RecurseOff(); // No need of recurse if -prof_dir${BUILD_DIR} flag is
// used while compiling. // used while compiling.
gl.RecurseThroughSymlinksOff(); gl.RecurseThroughSymlinksOff();
std::string prevBinaryDir; std::string prevBinaryDir;
cmSystemTools::ChangeDirectory( std::string buildDir = this->CTest->GetCTestConfiguration("BuildDirectory");
this->CTest->GetCTestConfiguration("BuildDirectory")); if (cmSystemTools::ChangeDirectory(buildDir))
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error changing directory to " << buildDir << std::endl);
return false;
}
// Run profmerge to merge all *.dyn files into dpi files // Run profmerge to merge all *.dyn files into dpi files
cmSystemTools::RunSingleCommand("profmerge"); if (!cmSystemTools::RunSingleCommand("profmerge"))
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error while running profmerge.\n");
return false;
}
prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory().c_str(); prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory().c_str();
@ -1766,10 +1781,16 @@ void cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
daGlob += "/*.dpi"; daGlob += "/*.dpi";
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
" looking for dpi files in: " << daGlob << std::endl, this->Quiet); " looking for dpi files in: " << daGlob << std::endl, this->Quiet);
gl.FindFiles(daGlob); if (!gl.FindFiles(daGlob))
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error while finding files matching " << daGlob << std::endl);
return false;
}
files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end()); files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Now searching in: " << daGlob << std::endl, this->Quiet); "Now searching in: " << daGlob << std::endl, this->Quiet);
return true;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -75,7 +75,7 @@ private:
//! Handle coverage using Intel's LCov //! Handle coverage using Intel's LCov
int HandleLCovCoverage(cmCTestCoverageHandlerContainer* cont); int HandleLCovCoverage(cmCTestCoverageHandlerContainer* cont);
void FindLCovFiles(std::vector<std::string>& files); bool FindLCovFiles(std::vector<std::string>& files);
//! Handle coverage using xdebug php coverage //! Handle coverage using xdebug php coverage
int HandlePHPCoverage(cmCTestCoverageHandlerContainer* cont); int HandlePHPCoverage(cmCTestCoverageHandlerContainer* cont);

View File

@ -1468,18 +1468,24 @@ bool cmcmd::RunCommand(const char* comment,
std::string output; std::string output;
int retCode =0; int retCode =0;
// use rc command to create .res file // use rc command to create .res file
cmSystemTools::RunSingleCommand(command, bool res = cmSystemTools::RunSingleCommand(command,
&output, &output, &output, &output,
&retCode, 0, cmSystemTools::OUTPUT_NONE); &retCode, 0,
cmSystemTools::OUTPUT_NONE);
// always print the output of the command, unless // always print the output of the command, unless
// it is the dumb rc command banner, but if the command // it is the dumb rc command banner, but if the command
// returned an error code then print the output anyway as // returned an error code then print the output anyway as
// the banner may be mixed with some other important information. // the banner may be mixed with some other important information.
if(output.find("Resource Compiler Version") == output.npos if(output.find("Resource Compiler Version") == output.npos
|| retCode !=0) || !res || retCode)
{ {
std::cout << output; std::cout << output;
} }
if (!res)
{
std::cout << comment << " failed to run." << std::endl;
return false;
}
// if retCodeOut is requested then always return true // if retCodeOut is requested then always return true
// and set the retCodeOut to retCode // and set the retCodeOut to retCode
if(retCodeOut) if(retCodeOut)
@ -1593,7 +1599,10 @@ int cmcmd::VisualStudioLinkIncremental(std::vector<std::string>& args,
mtCommand.push_back(tempManifest); mtCommand.push_back(tempManifest);
// now run mt.exe to create the final manifest file // now run mt.exe to create the final manifest file
int mtRet =0; int mtRet =0;
cmcmd::RunCommand("MT", mtCommand, verbose, &mtRet); if(!cmcmd::RunCommand("MT", mtCommand, verbose, &mtRet))
{
return -1;
}
// if mt returns 0, then the manifest was not changed and // if mt returns 0, then the manifest was not changed and
// we do not need to do another link step // we do not need to do another link step
if(mtRet == 0) if(mtRet == 0)